diff --git a/packages/react/src/hooks/useDecodedName.ts b/packages/react/src/hooks/useDecodedName.ts index 96a169fd..824e4f53 100644 --- a/packages/react/src/hooks/useDecodedName.ts +++ b/packages/react/src/hooks/useDecodedName.ts @@ -1,42 +1,34 @@ import { useQuery, type UseQueryResult } from '@tanstack/react-query' import { getDecodedName, + type GetDecodedNameParameters, type GetDecodedNameReturnType, } from '@ensdomains/ensjs/subgraph' import type { ParamWithClients } from '../client.js' import { fallbackQueryClient } from '../query.js' -export type UseDecodedNameParams = ParamWithClients<{ - name: string - allowIncomplete?: boolean -}> +export type UseDecodedNameParams = ParamWithClients + +export type UseDecodedNameReturnType = GetDecodedNameReturnType /** * Decode names returned using the subgraph * * Performs network request only if the name needs to be decoded, otherwise transparent * - * @param data - {@link UseDecodedNameParams} + * @param params - {@link UseDecodedNameParams} * @returns - {@link GetDecodedNameReturnType} */ export const useDecodedName = ( - data: UseDecodedNameParams, -): UseQueryResult => { - const { - name, - allowIncomplete, - client, - queryClient = fallbackQueryClient, - } = data + params: UseDecodedNameParams, +): UseQueryResult => { + const { client, queryClient = fallbackQueryClient } = params return useQuery( { - queryKey: ['ensjs', 'decoded-subgraph-name', name], + queryKey: ['ensjs', 'decoded-subgraph-name', params.name], queryFn: async () => { - const result = await getDecodedName(client, { - name, - allowIncomplete, - }) + const result = await getDecodedName(client, params) return result }, diff --git a/packages/react/src/hooks/useEnsAvailable.ts b/packages/react/src/hooks/useEnsAvailable.ts index fbb830b9..d37f9aff 100644 --- a/packages/react/src/hooks/useEnsAvailable.ts +++ b/packages/react/src/hooks/useEnsAvailable.ts @@ -1,32 +1,34 @@ import { useQuery, type UseQueryResult } from '@tanstack/react-query' -import { getAvailable } from '@ensdomains/ensjs/public' +import { + getAvailable, + type GetAvailableParameters, + type GetAvailableReturnType, +} from '@ensdomains/ensjs/public' import type { ParamWithClients } from '../client.js' import { fallbackQueryClient } from '../query.js' -export type UseEnsAvailableParams = ParamWithClients<{ - name: string -}> +export type UseEnsAvailableParams = ParamWithClients + +export type UseEnsAvailableReturnType = GetAvailableReturnType /** * Returns a list of names for an address * * Keep in mind that this function is limited to .eth names * - * @param data - {@link UseEnsAvailableParams} - * @returns - {@link boolean} + * @param params - {@link UseEnsAvailableParams} + * @returns - {@link UseEnsAvailableReturnType} */ export const useEnsAvailable = ( - data: UseEnsAvailableParams, -): UseQueryResult => { - const { name, client, queryClient = fallbackQueryClient } = data + params: UseEnsAvailableParams, +): UseQueryResult => { + const { client, queryClient = fallbackQueryClient } = params return useQuery( { - queryKey: ['ensjs', 'eth-name-available', name], + queryKey: ['ensjs', 'eth-name-available', params.name], queryFn: async () => { - const result = await getAvailable(client, { - name, - }) + const result = await getAvailable(client, params) return result }, diff --git a/packages/react/src/hooks/useEnsResolverInterfaces.ts b/packages/react/src/hooks/useEnsResolverInterfaces.ts index 802792ae..0e5c0484 100644 --- a/packages/react/src/hooks/useEnsResolverInterfaces.ts +++ b/packages/react/src/hooks/useEnsResolverInterfaces.ts @@ -1,22 +1,20 @@ import { useQuery, type UseQueryResult } from '@tanstack/react-query' import type { Address, Hex } from 'viem' -import { getSupportedInterfaces } from '@ensdomains/ensjs/public' +import { + getSupportedInterfaces, + type GetSupportedInterfacesParameters, + type GetSupportedInterfacesReturnType, +} from '@ensdomains/ensjs/public' import type { ParamWithClients } from '../client.js' import { fallbackQueryClient } from '../query.js' -import { resolverInterfaces } from '../interfaces.js' export type UseEnsResolverInterfacesParams< Interfaces extends readonly Hex[] = [Hex, Hex], -> = ParamWithClients<{ - resolver: Address - interfaces?: Interfaces -}> +> = ParamWithClients> export type UseEnsResolverInterfacesReturnType< Interfaces extends readonly Hex[], -> = { - [K in keyof Interfaces]: boolean -} +> = GetSupportedInterfacesReturnType /** * Returns a wether or not the interfaces are supported by the resolver @@ -24,30 +22,19 @@ export type UseEnsResolverInterfacesReturnType< * * You can use the {@link resolverInterfaces} shorthand, or manually specify a Hex value * - * @param data - {@link UseEnsResolverInterfacesParams} + * @param params - {@link UseEnsResolverInterfacesParams} * @returns - {@link boolean[]} */ export const useEnsResolverInterfaces = ( - data: UseEnsResolverInterfacesParams, + params: UseEnsResolverInterfacesParams, ): UseQueryResult> => { - const { - resolver, - interfaces = [ - resolverInterfaces.addrMulticoin, - resolverInterfaces.wildcard, - ], - client, - queryClient = fallbackQueryClient, - } = data + const { client, queryClient = fallbackQueryClient } = params return useQuery( { - queryKey: ['ensjs', 'resolver-interfaces', resolver], + queryKey: ['ensjs', 'resolver-interfaces', params.address], queryFn: async () => { - const result = await getSupportedInterfaces(client, { - address: resolver, - interfaces, - }) + const result = await getSupportedInterfaces(client, params) return result }, diff --git a/packages/react/src/hooks/useNamesForAddress.ts b/packages/react/src/hooks/useNamesForAddress.ts index 6919817c..f0637940 100644 --- a/packages/react/src/hooks/useNamesForAddress.ts +++ b/packages/react/src/hooks/useNamesForAddress.ts @@ -7,23 +7,25 @@ import { import { fallbackQueryClient } from '../query.js' import type { ParamWithClients } from '../client.js' -export type UseNamesParams = ParamWithClients<{ +export type UseNamesForAddressParams = ParamWithClients<{ address: Address }> +export type UseNamesForAddressReturnType = GetNamesForAddressReturnType + /** * Returns a list of names for an address * * Keep in mind that this list will be loaded from the subgraph, and only include watchable names. * Read more about enumeration and watchability here: https://docs.ens.domains/web/enumerate * - * @param data - {@link UseNamesParams} - * @returns - {@link GetNamesForAddressReturnType} + * @param params - {@link UseNamesForAddressParams} + * @returns - {@link UseNamesForAddressReturnType} */ export const useNamesForAddress = ( - data: UseNamesParams, -): UseQueryResult => { - const { address, client, queryClient = fallbackQueryClient } = data + params: UseNamesForAddressParams, +): UseQueryResult => { + const { address, client, queryClient = fallbackQueryClient } = params return useQuery( {