UNPKG

@macalinao/grill

Version:

Modern Solana development kit for React applications with automatic account batching, caching, and transaction notifications

43 lines 1.2 kB
import { TOKEN_PROGRAM_ADDRESS } from "@solana-program/token"; import { useTokenAccount } from "../accounts/token-account.js"; import { useAssociatedTokenPda } from "../pdas/associated-token.js"; /** * Hook that computes the Associated Token Account address and fetches its data * Combines useAssociatedTokenPda and useTokenAccount for convenience * * @example * ```typescript * const { * address, * tokenAccount, * isLoading * } = useAssociatedTokenAccount({ * mint: mintAddress, * owner: walletAddress, * }); * * if (tokenAccount) { * console.log("Balance:", tokenAccount.amount); * } * ``` */ export function useAssociatedTokenAccount(options) { const { mint, owner, tokenProgram = TOKEN_PROGRAM_ADDRESS } = options; // Compute the ATA address const ataAddress = useAssociatedTokenPda(mint && owner ? { mint, owner, tokenProgram, } : null); // Fetch the token account data const accountResult = useTokenAccount({ address: ataAddress, }); return { ...accountResult, address: ataAddress, }; } //# sourceMappingURL=use-associated-token-account.js.map