-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(hooks): add hooks for loading user assets
- Loading branch information
1 parent
358e06e
commit 357fd87
Showing
3 changed files
with
77 additions
and
0 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,45 @@ | ||
import { ANTRegistry, ANT_REGISTRY_ID, AOProcess, AoClient } from '@ar.io/sdk'; | ||
import { useGlobalState, useWalletState } from '@src/state'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
export function buildANTRegistryQuery( | ||
{ address }: { address?: string }, | ||
{ aoClient }: { aoClient: AoClient }, | ||
): Parameters< | ||
typeof useQuery<{ | ||
Owned: string[]; | ||
Controlled: string[]; | ||
}> | ||
>[0] { | ||
return { | ||
enabled: !!address, | ||
queryKey: ['ant-registry', address, aoClient], | ||
queryFn: async () => { | ||
if (!address) throw new Error('User address required to query for ACL'); | ||
const antRegistry = ANTRegistry.init({ | ||
process: new AOProcess({ | ||
processId: ANT_REGISTRY_ID, | ||
ao: aoClient, | ||
}), | ||
}); | ||
const acl = await antRegistry.accessControlList({ | ||
address, | ||
}); | ||
|
||
return acl; | ||
}, | ||
staleTime: 1000 * 60 * 5, | ||
}; | ||
} | ||
|
||
export function useANTRegistry({ address }: { address?: string } = {}) { | ||
const [{ aoClient }] = useGlobalState(); | ||
const [{ walletAddress }] = useWalletState(); | ||
|
||
return useQuery( | ||
buildANTRegistryQuery( | ||
{ address: address ?? walletAddress?.toString() }, | ||
{ aoClient }, | ||
), | ||
); | ||
} |
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,11 @@ | ||
import { useGlobalState } from '@src/state'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import arweaveGraphql from 'arweave-graphql'; | ||
|
||
export function useAOProcessMetaData({ processIds }: { processIds: string[] }) { | ||
const [{ gateway }] = useGlobalState(); | ||
|
||
const arGql = arweaveGraphql(`${gateway}/graphql`); | ||
|
||
return useQuery | ||
} |
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,21 @@ | ||
import { useGlobalState, useWalletState } from '@src/state'; | ||
|
||
import { useANTRegistry } from './useANTRegistry'; | ||
import { useArNSRegistryDomains } from './useArNSRegistryDomains'; | ||
|
||
/** | ||
* This is a composite tanstack query hook that combines | ||
* | ||
*/ | ||
|
||
export function useArNSAssets({ address }: { address?: string }) { | ||
const [{ arioContract, aoNetwork, gateway }] = useGlobalState(); | ||
const [{ walletAddress }] = useWalletState(); | ||
|
||
const { data: arnsRecords } = useArNSRegistryDomains(); | ||
const { data: userAcl } = useANTRegistry(); | ||
|
||
const res = useQuery({ | ||
queryKey: ['arns-assets', arioContract, aoNetwork], | ||
}); | ||
} |