Skip to content

Commit

Permalink
Implement useAccountDetails hook
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy committed Dec 31, 2023
1 parent ed8ba37 commit 0fb3a91
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/features/account/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lockedGoldABI } from '@celo/abis';
import { accountsABI, lockedGoldABI } from '@celo/abis';
import type { FetchBalanceResult } from '@wagmi/core';
import { useToastError } from 'src/components/notifications/useToastError';
import { ZERO_ADDRESS } from 'src/config/consts';
Expand Down Expand Up @@ -40,3 +40,31 @@ export function useLockedBalance(address?: Address) {

return { lockedBalance, isError, isLoading };
}

// Note, this retrieves the address's info from the Accounts contract
// It has nothing to do with wallets or backend services
export function useAccountDetails(address?: Address) {
const {
data: isRegistered,
isError,
isLoading,
error,
} = useContractRead({
address: Addresses.Accounts,
abi: accountsABI,
functionName: 'isAccount',
args: [address || ZERO_ADDRESS],
enabled: !!address,
});

// Note, more reads can be added here if more info is needed, such
// as name, metadataUrl, walletAddress, voteSignerToAccount, etc.

useToastError(error, 'Error fetching account registration status');

return {
account: { isRegistered },
isError,
isLoading,
};
}

0 comments on commit 0fb3a91

Please sign in to comment.