Skip to content

Commit

Permalink
added remaining public funcs + package.json updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Sep 24, 2024
1 parent 617170d commit 9a6c857
Show file tree
Hide file tree
Showing 19 changed files with 1,013 additions and 29 deletions.
6 changes: 5 additions & 1 deletion packages/ensjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@
"!src/**/*.test.ts",
"!src/test"
],
"repository": "[email protected]:ensdomains/ensjs.git",
"repository": {
"type": "git",
"url": "git+https://github.com/ensdomains/ensjs.git",
"directory": "packages/ensjs"
},
"author": "TateB <[email protected]>",
"license": "MIT",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ React hooks & utilities to interact with the Ethereum Name Service using ENSjs
After installing [wagmi](https://wagmi.sh), simply run

```sh
pnpm install @ensdomains/ensjs-react
pnpm install @ensdomains/ensjs-react @ensdomains/ensjs
```

## Hooks
Expand Down
19 changes: 16 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"import": "./dist/esm/index.js",
"default": "./dist/cjs/index.js"
},
"./query": {
"types": "./dist/types/query.d.ts",
"import": "./dist/esm/query.js",
"default": "./dist/cjs/query.js"
},
"./package.json": "./package.json"
},
"files": [
Expand All @@ -22,8 +27,15 @@
"!src/**/*.test.ts",
"!src/test"
],
"repository": "[email protected]:ensdomains/ensjs.git",
"author": "Lucemans <[email protected]>",
"repository": {
"type": "git",
"url": "git+https://github.com/ensdomains/ensjs.git",
"directory": "packages/react"
},
"contributors": [
"TateB <[email protected]>",
"Lucemans <[email protected]>"
],
"license": "MIT",
"scripts": {
"clean": "rm -rf ./dist",
Expand All @@ -49,7 +61,8 @@
"peerDependencies": {
"@tanstack/react-query": "^5.54",
"viem": "^2.9.2",
"wagmi": "^2"
"wagmi": "^2",
"@ensdomains/ensjs": "^4.0.1"
},
"engines": {
"node": ">=18"
Expand Down
11 changes: 0 additions & 11 deletions packages/react/src/client.ts

This file was deleted.

7 changes: 0 additions & 7 deletions packages/react/src/hooks.ts

This file was deleted.

57 changes: 57 additions & 0 deletions packages/react/src/hooks/useEnsAbi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useChainId, useConfig } from 'wagmi'
import { useQuery, type UseQueryReturnType } from 'wagmi/query'
import {
getEnsAbiQueryOptions,
type GetEnsAbiData,
type GetEnsAbiErrorType,
type GetEnsAbiOptions,
type GetEnsAbiQueryFnData,
type GetEnsAbiQueryKey,
} from '../query/getEnsAbi.js'
import type { ConfigWithEns } from '../types/config.js'
import type { ConfigParameter, QueryParameter } from '../types/properties.js'
import type { ResolvedRegister } from '../types/register.js'
import type { Compute } from '../types/utils.js'

export type UseEnsAbiParameters<
config extends ConfigWithEns = ConfigWithEns,
selectData = GetEnsAbiData,
> = Compute<
GetEnsAbiOptions<config> &
ConfigParameter<config> &
QueryParameter<
GetEnsAbiQueryFnData,
GetEnsAbiErrorType,
selectData,
GetEnsAbiQueryKey<config>
>
>

export type UseEnsAbiReturnType<selectData = GetEnsAbiData> =
UseQueryReturnType<selectData, GetEnsAbiErrorType>

/**
* Returns the ABI for a name
*
* @param parameters - {@link UseEnsAbiParameters}
* @returns - {@link UseEnsAbiReturnType}
*/
export const useEnsAbi = <
config extends ConfigWithEns = ResolvedRegister['config'],
selectData = GetEnsAbiData,
>(
parameters: UseEnsAbiParameters<config, selectData> = {},
): UseEnsAbiReturnType<selectData> => {
const { name, query = {} } = parameters

const config = useConfig<ConfigWithEns>()
const chainId = useChainId({ config })

const options = getEnsAbiQueryOptions(config, {
...parameters,
chainId: parameters.chainId ?? chainId,
})
const enabled = Boolean(name && (query.enabled ?? true))

return useQuery({ ...query, ...options, enabled })
}
57 changes: 57 additions & 0 deletions packages/react/src/hooks/useEnsAddress.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useChainId, useConfig } from 'wagmi'
import { useQuery, type UseQueryReturnType } from 'wagmi/query'
import {
getEnsAddressQueryOptions,
type GetEnsAddressData,
type GetEnsAddressErrorType,
type GetEnsAddressOptions,
type GetEnsAddressQueryFnData,
type GetEnsAddressQueryKey,
} from '../query/getEnsAddress.js'
import type { ConfigWithEns } from '../types/config.js'
import type { ConfigParameter, QueryParameter } from '../types/properties.js'
import type { ResolvedRegister } from '../types/register.js'
import type { Compute } from '../types/utils.js'

export type UseEnsAddressParameters<
config extends ConfigWithEns = ConfigWithEns,
selectData = GetEnsAddressData,
> = Compute<
GetEnsAddressOptions<config> &
ConfigParameter<config> &
QueryParameter<
GetEnsAddressQueryFnData,
GetEnsAddressErrorType,
selectData,
GetEnsAddressQueryKey<config>
>
>

export type UseEnsAddressReturnType<selectData = GetEnsAddressData> =
UseQueryReturnType<selectData, GetEnsAddressErrorType>

/**
* Returns the address for a name
*
* @param parameters - {@link UseEnsAddressParameters}
* @returns - {@link UseEnsAddressReturnType}
*/
export const useEnsAddress = <
config extends ConfigWithEns = ResolvedRegister['config'],
selectData = GetEnsAddressData,
>(
parameters: UseEnsAddressParameters<config, selectData> = {},
): UseEnsAddressReturnType<selectData> => {
const { name, query = {} } = parameters

const config = useConfig<ConfigWithEns>()
const chainId = useChainId({ config })

const options = getEnsAddressQueryOptions(config, {
...parameters,
chainId: parameters.chainId ?? chainId,
})
const enabled = Boolean(name && (query.enabled ?? true))

return useQuery({ ...query, ...options, enabled })
}
57 changes: 57 additions & 0 deletions packages/react/src/hooks/useEnsContentHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useChainId, useConfig } from 'wagmi'
import { useQuery, type UseQueryReturnType } from 'wagmi/query'
import {
getEnsContentHashQueryOptions,
type GetEnsContentHashData,
type GetEnsContentHashErrorType,
type GetEnsContentHashOptions,
type GetEnsContentHashQueryFnData,
type GetEnsContentHashQueryKey,
} from '../query/getEnsContentHash.js'
import type { ConfigWithEns } from '../types/config.js'
import type { ConfigParameter, QueryParameter } from '../types/properties.js'
import type { ResolvedRegister } from '../types/register.js'
import type { Compute } from '../types/utils.js'

export type UseEnsContentHashParameters<
config extends ConfigWithEns = ConfigWithEns,
selectData = GetEnsContentHashData,
> = Compute<
GetEnsContentHashOptions<config> &
ConfigParameter<config> &
QueryParameter<
GetEnsContentHashQueryFnData,
GetEnsContentHashErrorType,
selectData,
GetEnsContentHashQueryKey<config>
>
>

export type UseEnsContentHashReturnType<selectData = GetEnsContentHashData> =
UseQueryReturnType<selectData, GetEnsContentHashErrorType>

/**
* Returns the content hash for a name
*
* @param parameters - {@link UseEnsContentHashParameters}
* @returns - {@link UseEnsContentHashReturnType}
*/
export const useEnsContentHash = <
config extends ConfigWithEns = ResolvedRegister['config'],
selectData = GetEnsContentHashData,
>(
parameters: UseEnsContentHashParameters<config, selectData> = {},
): UseEnsContentHashReturnType<selectData> => {
const { name, query = {} } = parameters

const config = useConfig<ConfigWithEns>()
const chainId = useChainId({ config })

const options = getEnsContentHashQueryOptions(config, {
...parameters,
chainId: parameters.chainId ?? chainId,
})
const enabled = Boolean(name && (query.enabled ?? true))

return useQuery({ ...query, ...options, enabled })
}
57 changes: 57 additions & 0 deletions packages/react/src/hooks/useEnsOwner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useChainId, useConfig } from 'wagmi'
import { useQuery, type UseQueryReturnType } from 'wagmi/query'
import {
getEnsOwnerQueryOptions,
type GetEnsOwnerData,
type GetEnsOwnerErrorType,
type GetEnsOwnerOptions,
type GetEnsOwnerQueryFnData,
type GetEnsOwnerQueryKey,
} from '../query/getEnsOwner.js'
import type { ConfigWithEns } from '../types/config.js'
import type { ConfigParameter, QueryParameter } from '../types/properties.js'
import type { ResolvedRegister } from '../types/register.js'
import type { Compute } from '../types/utils.js'

export type UseEnsOwnerParameters<
config extends ConfigWithEns = ConfigWithEns,
selectData = GetEnsOwnerData,
> = Compute<
GetEnsOwnerOptions<config> &
ConfigParameter<config> &
QueryParameter<
GetEnsOwnerQueryFnData,
GetEnsOwnerErrorType,
selectData,
GetEnsOwnerQueryKey<config>
>
>

export type UseEnsOwnerReturnType<selectData = GetEnsOwnerData> =
UseQueryReturnType<selectData, GetEnsOwnerErrorType>

/**
* Returns the owner of a name
*
* @param parameters - {@link UseEnsOwnerParameters}
* @returns - {@link UseEnsOwnerReturnType}
*/
export const useEnsOwner = <
config extends ConfigWithEns = ResolvedRegister['config'],
selectData = GetEnsOwnerData,
>(
parameters: UseEnsOwnerParameters<config, selectData> = {},
): UseEnsOwnerReturnType<selectData> => {
const { name, query = {} } = parameters

const config = useConfig<ConfigWithEns>()
const chainId = useChainId({ config })

const options = getEnsOwnerQueryOptions(config, {
...parameters,
chainId: parameters.chainId ?? chainId,
})
const enabled = Boolean(name && (query.enabled ?? true))

return useQuery({ ...query, ...options, enabled })
}
57 changes: 57 additions & 0 deletions packages/react/src/hooks/useEnsPrice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useChainId, useConfig } from 'wagmi'
import { useQuery, type UseQueryReturnType } from 'wagmi/query'
import {
getEnsPriceQueryOptions,
type GetEnsPriceData,
type GetEnsPriceErrorType,
type GetEnsPriceOptions,
type GetEnsPriceQueryFnData,
type GetEnsPriceQueryKey,
} from '../query/getEnsPrice.js'
import type { ConfigWithEns } from '../types/config.js'
import type { ConfigParameter, QueryParameter } from '../types/properties.js'
import type { ResolvedRegister } from '../types/register.js'
import type { Compute } from '../types/utils.js'

export type UseEnsPriceParameters<
config extends ConfigWithEns = ConfigWithEns,
selectData = GetEnsPriceData,
> = Compute<
GetEnsPriceOptions<config> &
ConfigParameter<config> &
QueryParameter<
GetEnsPriceQueryFnData,
GetEnsPriceErrorType,
selectData,
GetEnsPriceQueryKey<config>
>
>

export type UseEnsPriceReturnType<selectData = GetEnsPriceData> =
UseQueryReturnType<selectData, GetEnsPriceErrorType>

/**
* Returns the price for registering or renewing a name
*
* @param parameters - {@link UseEnsPriceParameters}
* @returns - {@link UseEnsPriceReturnType}
*/
export const useEnsPrice = <
config extends ConfigWithEns = ResolvedRegister['config'],
selectData = GetEnsPriceData,
>(
parameters: UseEnsPriceParameters<config, selectData> = {},
): UseEnsPriceReturnType<selectData> => {
const { nameOrNames, duration, query = {} } = parameters

const config = useConfig<ConfigWithEns>()
const chainId = useChainId({ config })

const options = getEnsPriceQueryOptions(config, {
...parameters,
chainId: parameters.chainId ?? chainId,
})
const enabled = Boolean(nameOrNames && duration && (query.enabled ?? true))

return useQuery({ ...query, ...options, enabled })
}
Loading

0 comments on commit 9a6c857

Please sign in to comment.