// packages/dapp-kit/src/hooks/swap/useCreateLimitOrder.ts import { useSodaxContext } from '../shared/useSodaxContext.js'; import type { LimitOrderActionParams, SpokeChainKey, SwapResponse } from '@sodax/sdk'; import type { MutationHookParams } from '../shared/types.js'; import { useSafeMutation, type SafeUseMutationResult } from '../shared/useSafeMutation.js'; import { unwrapResult } from '../shared/unwrapResult.js'; /** * Mutation variables for {@link useCreateLimitOrder}. Generic over `K extends SpokeChainKey` * (defaults to the full union). Sophisticated callers can lock K at the call site to narrow the * `walletProvider` and `params.srcChainKey` types. */ export type UseCreateLimitOrderVars = Omit< LimitOrderActionParams, 'raw' >; /** * React hook for creating a limit-order intent (no deadline). * * Throws on SDK failure so React Query's native error model engages (`isError`, `error`, * `onError`, `retry`). Returns the unwrapped `SwapResponse` on success. */ export function useCreateLimitOrder({ mutationOptions, }: MutationHookParams> = {}): SafeUseMutationResult< SwapResponse, Error, UseCreateLimitOrderVars > { const { sodax } = useSodaxContext(); return useSafeMutation>({ mutationKey: ['swap', 'limitOrder', 'create'], ...mutationOptions, mutationFn: async vars => unwrapResult(await sodax.swaps.createLimitOrder({ ...vars, raw: false })), }); }