import { useQuery, type UseQueryResult } from '@tanstack/react-query'; import { useSodaxContext } from '../shared/useSodaxContext.js'; import type { ReadHookParams } from '../shared/types.js'; export type UseConvertedAssetsParams = ReadHookParams< bigint, { amount: bigint | undefined; } >; /** * React hook to convert an xSODA share amount to its underlying SODA value via the vault's * exchange rate. Hub-only read. Throws on `!ok`. */ export function useConvertedAssets({ params, queryOptions, }: UseConvertedAssetsParams = {}): UseQueryResult { const { sodax } = useSodaxContext(); const amount = params?.amount; return useQuery({ queryKey: ['staking', 'convertedAssets', amount?.toString()], queryFn: async () => { if (amount === undefined) { throw new Error('amount is required'); } const result = await sodax.staking.getConvertedAssets(amount); if (!result.ok) throw result.error; return result.value; }, enabled: amount !== undefined, refetchInterval: 10_000, ...queryOptions, }); }