Skip to content

Commit

Permalink
fix(hooks): add hooks for loading user assets
Browse files Browse the repository at this point in the history
  • Loading branch information
atticusofsparta committed Jan 30, 2025
1 parent 358e06e commit 357fd87
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/hooks/useANTRegistry.tsx
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 },
),
);
}
11 changes: 11 additions & 0 deletions src/hooks/useAOProcessMetaData.tsx
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[] }) {

Check failure on line 5 in src/hooks/useAOProcessMetaData.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

'processIds' is defined but never used
const [{ gateway }] = useGlobalState();

const arGql = arweaveGraphql(`${gateway}/graphql`);

Check failure on line 8 in src/hooks/useAOProcessMetaData.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

'arGql' is assigned a value but never used

return useQuery

Check failure on line 10 in src/hooks/useAOProcessMetaData.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

Insert `;`
}
21 changes: 21 additions & 0 deletions src/hooks/useArNSAssets.tsx
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 }) {

Check failure on line 11 in src/hooks/useArNSAssets.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

'address' is defined but never used
const [{ arioContract, aoNetwork, gateway }] = useGlobalState();

Check failure on line 12 in src/hooks/useArNSAssets.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

'gateway' is assigned a value but never used
const [{ walletAddress }] = useWalletState();

Check failure on line 13 in src/hooks/useArNSAssets.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

'walletAddress' is assigned a value but never used

const { data: arnsRecords } = useArNSRegistryDomains();

Check failure on line 15 in src/hooks/useArNSAssets.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

'arnsRecords' is assigned a value but never used
const { data: userAcl } = useANTRegistry();

Check failure on line 16 in src/hooks/useArNSAssets.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

'userAcl' is assigned a value but never used

const res = useQuery({

Check failure on line 18 in src/hooks/useArNSAssets.tsx

View workflow job for this annotation

GitHub Actions / lint_test_build

'res' is assigned a value but never used
queryKey: ['arns-assets', arioContract, aoNetwork],
});
}

0 comments on commit 357fd87

Please sign in to comment.