-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce useEnsResolverInterfaces, abstract fallbackQuery, and Param…
…WithClients
- Loading branch information
Showing
6 changed files
with
74 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { ClientWithEns } from '@ensdomains/ensjs/contracts' | ||
import type { QueryClient } from '@tanstack/react-query' | ||
|
||
export type ParamWithClients<T> = T & { | ||
client: ClientWithEns | ||
queryClient?: QueryClient | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { useNamesForAddress } from './hooks/useNamesForAddress.js' | ||
export { useEnsAvailable } from './hooks/useEnsAvailable.js' | ||
export { useEnsResolverInterfaces } from './hooks/useEnsResolverInterfaces.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useQuery, type UseQueryResult } from '@tanstack/react-query' | ||
import type { Address, Hex } from 'viem' | ||
import { getSupportedInterfaces } from '@ensdomains/ensjs/public' | ||
import type { ParamWithClients } from '../client.js' | ||
import { fallbackQueryClient } from '../query.js' | ||
|
||
export type UseEnsResolverInterfacesParams< | ||
Interfaces extends readonly Hex[] = [Hex, Hex], | ||
> = ParamWithClients<{ | ||
resolver: Address | ||
interfaces?: Interfaces | ||
}> | ||
|
||
export type UseEnsResolverInterfacesReturnType< | ||
Interfaces extends readonly Hex[], | ||
> = { | ||
[K in keyof Interfaces]: boolean | ||
} | ||
|
||
/** | ||
* Returns a wether or not the interfaces are supported by the resolver | ||
* You can find a list of interfaces at https://docs.ens.domains/resolvers/interfaces | ||
* | ||
* @param data - {@link UseEnsResolverInterfacesParams} | ||
* @returns - {@link boolean[]} | ||
*/ | ||
export const useEnsResolverInterfaces = <Interfaces extends readonly Hex[]>( | ||
data: UseEnsResolverInterfacesParams<Interfaces>, | ||
): UseQueryResult<UseEnsResolverInterfacesReturnType<Interfaces>> => { | ||
const { | ||
resolver, | ||
// default ['addr(node, coinType)', 'wildcard'] | ||
interfaces = ['0xf1cb7e06', '0x9061b923'], | ||
client, | ||
queryClient = fallbackQueryClient, | ||
} = data | ||
|
||
return useQuery( | ||
{ | ||
queryKey: ['ensjs', 'resolver-interfaces', resolver], | ||
queryFn: async () => { | ||
const result = await getSupportedInterfaces(client, { | ||
address: resolver, | ||
interfaces, | ||
}) | ||
|
||
return result | ||
}, | ||
}, | ||
queryClient, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { QueryClient } from '@tanstack/react-query' | ||
|
||
// TODO: figure out why not taking from provider | ||
export const fallbackQueryClient = new QueryClient() |