1+ import { useQuery } from "@tanstack/react-query" ;
12import { useMemo } from "react" ;
3+ import type { ThirdwebClient } from "../../../../../client/client.js" ;
4+ import { getToken } from "../../../../../pay/convert/get-token.js" ;
25import type { Wallet } from "../../../../../wallets/interfaces/wallet.js" ;
36import { useActiveAccount } from "../../../../core/hooks/wallets/useActiveAccount.js" ;
47import { useActiveWallet } from "../../../../core/hooks/wallets/useActiveWallet.js" ;
58import { useActiveWalletChain } from "../../../../core/hooks/wallets/useActiveWalletChain.js" ;
6- import type { ActiveWalletInfo } from "./types.js" ;
9+ import type { ActiveWalletInfo , TokenSelection } from "./types.js" ;
710
811export function useActiveWalletInfo (
912 activeWalletOverride ?: Wallet ,
@@ -25,3 +28,26 @@ export function useActiveWalletInfo(
2528 : undefined ;
2629 } , [ activeAccount , activeWallet , activeChain , activeWalletOverride ] ) ;
2730}
31+
32+ export function useTokenPrice ( options : {
33+ token : TokenSelection | undefined ;
34+ client : ThirdwebClient ;
35+ } ) {
36+ return useQuery ( {
37+ queryKey : [ "token-price" , options . token ] ,
38+ enabled : ! ! options . token ,
39+ queryFn : ( ) => {
40+ if ( ! options . token ) {
41+ throw new Error ( "Token is required" ) ;
42+ }
43+ return getToken (
44+ options . client ,
45+ options . token . tokenAddress ,
46+ options . token . chainId ,
47+ ) ;
48+ } ,
49+ refetchOnMount : false ,
50+ retry : false ,
51+ refetchOnWindowFocus : false ,
52+ } ) ;
53+ }
0 commit comments