import type { TFunction } from 'i18next'; import type { ErrorNotification } from '../../components/FunNotification/FunNotification'; import type { ConvertSourceErrorReason } from './errors'; import { type ConvertQuote } from './quote'; import type { ConvertRecipientSelection } from './recipient'; import type { ConvertSubmission } from './reducer'; import type { ConvertSourceWalletSelection } from './sourceWallet'; import type { ConvertSubmitPreparation } from './submit'; /** What stops the user from converting the amount on screen. */ export type ConvertScreenIssue = /** `isRetryable`: the host's resolver failed or timed out, so asking again may work. */ { type: 'sourceWalletUnavailable'; isRetryable: boolean; } | { type: 'recipientUnavailable'; isRetryable: boolean; } /** A later balance read left the picked source out; reading again may fix it. */ | { type: 'sourceBalanceUnavailable'; } /** `maxBaseUnits` is `null` while Max is unknown, and `0n` with nothing to spend. */ | { type: 'insufficientBalance'; maxBaseUnits: bigint | null; } | { type: 'belowMinimum'; } | { type: 'quoteFailed'; error: Error | null; } /** The pre-sign balance read failed; submitting again reads it again. */ | { type: 'balanceCheckFailed'; } /** The pre-sign check threw before reaching the wallet; submitting again reruns it. */ | { type: 'checkFailed'; } /** The wallet step failed before any funds moved. */ | { type: 'signingFailed'; reason: ConvertSourceErrorReason; } /** Relay's fill failed or was refunded. */ | { type: 'fillFailed'; } /** Funds may have moved but can't be tracked. Final. */ | { type: 'untrackable'; }; /** * Where a submission stands, named by what the money is doing: * - `converting`: the pre-sign check, signing and recording; nothing sent yet, * or sent and not yet recorded. * - `pending`: on-chain and recorded; Relay is filling it. * - `completed`: delivered; the modal closes. * - `untrackable` is final: funds may have moved, so Convert stays locked. * - `failed`: nothing is in flight; `issue` says whether anything moved. */ export type ConvertPhase = 'converting' | 'pending' | 'completed' | 'untrackable' | 'failed'; /** * What a blocked pre-sign check tells the user, if anything. `undefined` ends * the submission with nothing to show beyond the live checks. */ export declare function getConvertPreSignIssue(preparation: Extract): ConvertScreenIssue | undefined; /** Convert is locked from the submission until it settles, and for good once `untrackable`. */ export declare function isConvertSubmissionLocked(submission: ConvertSubmission | undefined): boolean; /** * What the banner and the main button each show. A locked submission hides the * rest, since the balance drops as the deposit lands. Otherwise: * - The button acts on a live problem (amount, then quote) before the submission, * so a failed quote still offers a retry and a lowered balance offers Max. * - The banner does the same, except a failed fill stays on top: money moved, * so the user has to learn about it before anything newer. */ export declare function getConvertScreenIssues({ submission, amountIssue, quoteIssue, }: { submission: ConvertSubmission | undefined; amountIssue: ConvertScreenIssue | undefined; quoteIssue: ConvertScreenIssue | undefined; }): { bannerIssue: ConvertScreenIssue | undefined; buttonIssue: ConvertScreenIssue | undefined; }; /** * Problems found before quoting; a quote is only requested without one. * - Above the balance follows checkout: never clamp, offer Max instead. * - Under $1 never quotes: Relay won't, and its error reads worse. */ export declare function getConvertAmountIssue({ sourceWallet, recipient, isSourceBalanceUnavailable, amountInBaseUnits, amountUsd, balanceBaseUnits, maxBaseUnits, }: { sourceWallet: ConvertSourceWalletSelection | undefined; recipient: ConvertRecipientSelection | undefined; /** Without a balance there's no price, so neither the $1 nor the balance check can run. */ isSourceBalanceUnavailable: boolean; amountInBaseUnits: bigint | undefined; /** `undefined` while the price is unknown. */ amountUsd: number | undefined; /** `undefined` while the balance is unknown. */ balanceBaseUnits: string | undefined; maxBaseUnits: bigint | null; }): ConvertScreenIssue | undefined; /** A failed quote, or one that doesn't say what the user receives. */ export declare function getConvertQuoteIssue({ quote, isError, error, }: { quote: ConvertQuote | undefined; isError: boolean; error: Error | null; }): ConvertScreenIssue | undefined; /** The bottom-bar notification, worded like checkout's and withdrawal's. */ export declare function getConvertNotification({ issue, sourceSymbol, destinationSymbol, t, }: { issue: ConvertScreenIssue | undefined; sourceSymbol: string | undefined; destinationSymbol: string | undefined; t: TFunction; }): ErrorNotification | undefined; /** Another press restarts the timer. */ export declare const CONVERT_RECEIVE_AMOUNT_HINT_MS = 3000; /** Shown briefly when the read-only To amount is pressed. */ export declare function getConvertReceiveAmountHint(t: TFunction): ErrorNotification; export type ConvertActionButton = /** From the submission until Relay settles. */ { action: 'converting'; } /** Shown briefly before the modal closes. */ | { action: 'converted'; } /** The first balance read is out, so there's no source yet. */ | { action: 'loadingBalance'; } /** A native EVM source's gas price is loading, so Max and the reserve are unknown. */ | { action: 'estimatingGas'; } | { action: 'max'; maxBaseUnits: bigint; } /** After a failed quote or host lookup; `isRetrying` while the retry runs. */ | { action: 'retry'; isRetrying: boolean; } /** `isRefreshing`: a new quote is replacing the shown one, so it can't be signed. */ | { action: 'convert'; isEnabled: boolean; isRefreshing: boolean; }; /** * Like checkout's "Deposit max balance": above the balance, the main button * fills in Max. After a failed quote or host lookup it retries, since neither * tries again on its own. Otherwise it converts, once a quote says what * arrives, and waits out a refresh like checkout's confirmation screen. A * submission in flight overrides all of it. */ export declare function getConvertActionButton({ submission, issue, quote, isAwaitingBalances, isQuoteFetching, isLookupFetching, isFeeReserveLoading, }: { submission: ConvertSubmission | undefined; issue: ConvertScreenIssue | undefined; quote: ConvertQuote | undefined; isAwaitingBalances?: boolean; isQuoteFetching: boolean; /** A source wallet, recipient or balance read is running. */ isLookupFetching: boolean; /** Like the quote, the pre-sign check waits on it. */ isFeeReserveLoading: boolean; }): ConvertActionButton; /** The To card's amounts; `undefined` until a quote says what arrives. */ export declare function getConvertReceiveAmounts(quote: ConvertQuote | undefined, decimals: number | undefined): { tokenAmount: number | undefined; usdAmount: number | undefined; }; /** Whole seconds until the quote refreshes, seeded like `LightningInvoice`. */ export declare function getConvertCountdownSeconds(refreshesAtMs: number, nowMs: number): number;