import type { AutoSwapPreferences } from '@sodax/sdk'; import { useQuery, type UseQueryResult } from '@tanstack/react-query'; import { useSodaxContext } from '../shared/useSodaxContext.js'; import type { ReadHookParams } from '../shared/types.js'; export type UseGetAutoSwapPreferencesParams = ReadHookParams< AutoSwapPreferences, { queryAddress: string | undefined; } >; /** * React hook to fetch the auto-swap preferences (output token, destination chain, destination * address) for a given EVM address. Disabled when `queryAddress` is missing. Throws on `!ok`. */ export function useGetAutoSwapPreferences({ params, queryOptions, }: UseGetAutoSwapPreferencesParams = {}): UseQueryResult { const { sodax } = useSodaxContext(); const queryAddress = params?.queryAddress; return useQuery({ queryKey: ['partner', 'feeClaim', 'autoSwapPreferences', queryAddress], queryFn: async () => { if (!queryAddress) { throw new Error('queryAddress is required'); } const result = await sodax.partners.feeClaim.getAutoSwapPreferences(queryAddress); if (!result.ok) throw result.error; return result.value; }, enabled: !!queryAddress, ...queryOptions, }); }