From bec3047638e555bb20956da15e2583ca0f76a079 Mon Sep 17 00:00:00 2001 From: Luc Date: Wed, 4 Sep 2024 23:34:24 +0000 Subject: [PATCH] Introduce useEnsExpiry & useEnsRecordsWrite --- packages/react/package.json | 7 ++-- packages/react/src/hooks.ts | 2 + packages/react/src/hooks/useEnsExpiry.ts | 38 +++++++++++++++++++ .../react/src/hooks/useEnsRecordsWrite.ts | 18 +++++++++ pnpm-lock.yaml | 6 +-- 5 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 packages/react/src/hooks/useEnsExpiry.ts create mode 100644 packages/react/src/hooks/useEnsRecordsWrite.ts diff --git a/packages/react/package.json b/packages/react/package.json index b60628a9..2dfec481 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -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" diff --git a/packages/react/src/hooks.ts b/packages/react/src/hooks.ts index a9751524..765ed1b2 100644 --- a/packages/react/src/hooks.ts +++ b/packages/react/src/hooks.ts @@ -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' diff --git a/packages/react/src/hooks/useEnsExpiry.ts b/packages/react/src/hooks/useEnsExpiry.ts new file mode 100644 index 00000000..64d479be --- /dev/null +++ b/packages/react/src/hooks/useEnsExpiry.ts @@ -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 + +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 => { + const { client, queryClient = fallbackQueryClient } = params + + return useQuery( + { + queryKey: ['ensjs', 'ens-expiry', params.name], + queryFn: async () => { + const result = await getExpiry(client, params) + + return result + }, + }, + queryClient, + ) +} diff --git a/packages/react/src/hooks/useEnsRecordsWrite.ts b/packages/react/src/hooks/useEnsRecordsWrite.ts new file mode 100644 index 00000000..900985c4 --- /dev/null +++ b/packages/react/src/hooks/useEnsRecordsWrite.ts @@ -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) +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1de04649..f3a58568 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -256,9 +256,6 @@ importers: '@tanstack/react-query': specifier: ^5.54 version: 5.54.1(react@18.3.1) - wagmi: - specifier: '2' - version: 2.12.8(@tanstack/query-core@5.54.1)(@tanstack/react-query@5.54.1(react@18.3.1))(bufferutil@4.0.8)(react-native@0.75.2(@babel/core@7.25.2)(@babel/preset-env@7.25.4(@babel/core@7.25.2))(bufferutil@4.0.8)(react@18.3.1)(typescript@5.3.2)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.19.2)(typescript@5.3.2)(utf-8-validate@5.0.10)(viem@2.9.2(bufferutil@4.0.8)(typescript@5.3.2)(utf-8-validate@5.0.10)) devDependencies: '@ensdomains/buffer': specifier: ^0.0.13 @@ -281,6 +278,9 @@ importers: viem: specifier: 2.9.2 version: 2.9.2(bufferutil@4.0.8)(typescript@5.3.2)(utf-8-validate@5.0.10) + wagmi: + specifier: ^2 + version: 2.12.8(@tanstack/query-core@5.54.1)(@tanstack/react-query@5.54.1(react@18.3.1))(bufferutil@4.0.8)(react-native@0.75.2(@babel/core@7.25.2)(@babel/preset-env@7.25.4(@babel/core@7.25.2))(bufferutil@4.0.8)(react@18.3.1)(typescript@5.3.2)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.19.2)(typescript@5.3.2)(utf-8-validate@5.0.10)(viem@2.9.2(bufferutil@4.0.8)(typescript@5.3.2)(utf-8-validate@5.0.10)) packages: