@openocean.finance/widget
Version:
Openocean Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.
24 lines • 852 B
JavaScript
import { useQuery } from '@tanstack/react-query';
import { OpenOceanService } from '../services/OpenOceanService.js';
export const useTokenPrice = (chainId, token) => {
const { data: price, isLoading } = useQuery({
queryKey: ['token-price', chainId, token?.address],
queryFn: async () => {
if (!chainId || !token?.address) {
return undefined;
}
const prices = await OpenOceanService.getTokensPrice(chainId.toString(), [
token.address,
]);
return prices[token.address.toLowerCase()] || 0;
},
enabled: !!chainId && !!token?.address,
refetchInterval: 60000, // Update price every minute
staleTime: 60000,
});
return {
price,
isLoading,
};
};
//# sourceMappingURL=useTokenPrice.js.map