import { type AmountUnit } from '../../components/TokenSwapWidget/AmountUnitToggle/useAmountUnitToggle'; import type { ConvertQuote } from './quote'; import { type ConvertScreenIssue } from './screen'; import type { ConvertSubmittedTransaction } from './settlement'; import type { ConvertSourceWalletSelection } from './sourceWallet'; import type { ConvertSubmitPreparation } from './submit'; import type { ConvertResolvedAsset } from './types'; /** What the user is editing. Keys are {@link convertAssetKey}s. */ export interface ConvertDraft { sourceKey: string | undefined; destinationKey: string | undefined; /** The field text as typed; stale while a preset is on, which derives its own. */ inputValue: string; unit: AmountUnit; /** A percentage preset's exact amount (Max included); typing clears it. */ presetBaseUnits: bigint | undefined; } /** What the user converted, frozen when they did; a locked screen reads only this. */ export interface ConvertSnapshot { sourceAsset: ConvertResolvedAsset; destinationAsset: ConvertResolvedAsset; amountBaseUnits: bigint; quote: ConvertQuote; sourceWallet: Extract; recipientAddress: string; /** The price the amount was shown at, so its USD value can't move mid-conversion. */ unitPriceUsd: number | undefined; } export type ConvertSubmission = { snapshot: ConvertSnapshot; } & ({ phase: 'converting' | 'completed' | 'untrackable'; } /** Polling follows `transaction` until Relay fills or fails it. */ | { phase: 'pending'; transaction: ConvertSubmittedTransaction; } | { phase: 'failed'; issue: ConvertScreenIssue; }); export interface ConvertState { draft: ConvertDraft; submission: ConvertSubmission | undefined; /** Counts deposits sent, so a quote whose Relay request went out is never signed again. */ sentCount: number; } export type ConvertEvent = { type: 'AMOUNT_EDITED'; inputValue: string; } | { type: 'PRESET_SET'; presetBaseUnits: bigint; } /** Converts the field at the live price; ignored without one. */ | { type: 'UNIT_TOGGLED'; unitPriceUsd: number | undefined; } | { type: 'SOURCE_PICKED'; sourceKey: string; } /** Balances loaded with no source picked: opens on the most valuable token. */ | { type: 'SOURCE_PRESELECTED'; sourceKey: string; } | { type: 'DESTINATION_PICKED'; destinationKey: string; } | { type: 'DIRECTION_SWAPPED'; } | { type: 'CONVERT_STARTED'; snapshot: ConvertSnapshot; } | { type: 'CHECK_FAILED'; preparation: Extract; } /** The pre-sign check threw; nothing reached the wallet. */ | { type: 'CHECK_FAILED'; error: unknown; } /** The wallet step failed with nothing sent. */ | { type: 'SIGNING_FAILED'; error: unknown; } | { type: 'DEPOSIT_RECORDED'; transaction: ConvertSubmittedTransaction; } | { type: 'UNTRACKABLE'; } | { type: 'COMPLETED'; } | { type: 'FILL_FAILED'; } | { type: 'RETRIED'; } /** The success label has shown long enough; the screen opens for another conversion. */ | { type: 'SUCCESS_SHOWN'; }; export declare const INITIAL_CONVERT_STATE: ConvertState; /** * Convert's draft and submission. Pure: the provider runs the wallet steps * and polling, and dispatches what they report. * - An edit, preset, pick or retry ends a `failed` submission; a locked one ignores them. * - `CONVERT_STARTED` freezes the snapshot; nothing live reaches it after. * - `untrackable` is final; `completed` ends with `SUCCESS_SHOWN`, which keeps * the tokens and drops the amount, since it was converted. */ export declare function convertReducer(state: ConvertState, event: ConvertEvent): ConvertState;