Skip to content

Commit

Permalink
Introduce useEnsExpiry & useEnsRecordsWrite
Browse files Browse the repository at this point in the history
  • Loading branch information
lucemans committed Sep 4, 2024
1 parent 44d6194 commit bec3047
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@
"ts-node": "^10.9.2",
"typescript": "5.3.2",
"viem": "2.9.2",
"tslib": "^2.7.0"
"tslib": "^2.7.0",
"wagmi": "^2"
},
"peerDependencies": {
"@tanstack/react-query": "^5.54",
"viem": "2.9.2",
"wagmi": "2"
"viem": "^2.9.2",
"wagmi": "^2"
},
"engines": {
"node": ">=18"
Expand Down
2 changes: 2 additions & 0 deletions packages/react/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export { useNamesForAddress } from './hooks/useNamesForAddress.js'
export { useEnsAvailable } from './hooks/useEnsAvailable.js'
export { useEnsResolverInterfaces } from './hooks/useEnsResolverInterfaces.js'
export { useDecodedName } from './hooks/useDecodedName.js'
export { useEnsRecordsWrite } from './hooks/useEnsRecordsWrite.js'
export { useEnsExpiry } from './hooks/useEnsExpiry.js'
38 changes: 38 additions & 0 deletions packages/react/src/hooks/useEnsExpiry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { useQuery, type UseQueryResult } from '@tanstack/react-query'
import {
getExpiry,
type GetExpiryParameters,
type GetExpiryReturnType,
} from '@ensdomains/ensjs/public'
import type { ParamWithClients } from '../client.js'
import { fallbackQueryClient } from '../query.js'

export type UseEnsExpiryParams = ParamWithClients<GetExpiryParameters>

export type UseEnsExpiryReturnType = GetExpiryReturnType

/**
* Returns expiry of a name
*
* Keep in mind that this function is limited to second-level .eth names (luc.eth, nick.eth, etc)
*
* @param params - {@link UseEnsExpiryParams}
* @returns - {@link UseEnsExpiryReturnType}
*/
export const useEnsExpiry = (
params: UseEnsExpiryParams,
): UseQueryResult<UseEnsExpiryReturnType> => {
const { client, queryClient = fallbackQueryClient } = params

return useQuery(
{
queryKey: ['ensjs', 'ens-expiry', params.name],
queryFn: async () => {
const result = await getExpiry(client, params)

return result
},
},
queryClient,
)
}
18 changes: 18 additions & 0 deletions packages/react/src/hooks/useEnsRecordsWrite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useAccount } from 'wagmi'
import type { ParamWithClients } from '../client.js'

export type UseEnsRecordsWriteParams = ParamWithClients<{}>

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const useEnsRecordsWrite = (
_params: UseEnsRecordsWriteParams,
config?: any,
) => {
const { address } = useAccount({ config })
// const client = useWalletClient()

console.log('Hello ', address)

return { data: undefined }
// return setRecords(client as any, params)
}
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bec3047

Please sign in to comment.