UNPKG

@cyberk/hyperion-sdk

Version:

Hyperion SDK from Cyberk

30 lines 1.05 kB
import { useQuery } from "@tanstack/react-query"; import { RPCs } from "../constants/RPCs"; import { useCosmWasmClient } from "./useCosmWasmClient"; import { getCw20TokenBalanceQueryOptions, } from "../query/getCw20TokenBalance"; export const useCw20TokenBalance = ({ tokenAddress, address, chainId, options: observerOptions, }) => { const rpc = RPCs[chainId]; if (!rpc) { throw new Error(`RPC not found for chainId: ${chainId}`); } const { data: cosmwasmClient } = useCosmWasmClient({ rpc, options: { enabled: !!rpc, }, }); const enabled = !!cosmwasmClient && !!tokenAddress && !!address; const { queryKey, ...options } = getCw20TokenBalanceQueryOptions({ client: cosmwasmClient, tokenAddress, address, }); return useQuery({ ...observerOptions, ...options, // @ts-expect-error queryKey, enabled: Boolean(enabled && (observerOptions?.enabled ?? true)), }); }; //# sourceMappingURL=useCw20TokenBalance.js.map