import type { FiatStepResponse, JsonValue, Quote } from '@fun-xyz/fiat-contract/types'; import type { ComputePageOptions, FiatPage } from '../../domains/fiat/computePage'; import type { TransitionDispatch } from '../../domains/fiat/selectTransitions'; import type { CollectedInputs } from '../../domains/fiat/submitBody'; /** * What the client is doing, which is not what the flow is in — the step * response says the latter. Deliberately flat: `POLLING` is not here because polling * runs *alongside* collecting rather than instead of it, and modelling it as a * phase would make "waiting for the user while polling" unrepresentable. */ export type FiatPhase = 'RENDERING' | 'COLLECTING' | 'SURFACE_RUNNING' | 'IN_FLIGHT' | 'RETRYABLE' | 'TERMINAL' | 'EXITED'; /** * Polling runs alongside whatever the screen is doing, so it is tracked here * rather than as a phase — see `FiatPhase` above. * * `active` is the step response's doing: it asked for a poll. `paused` is ours: a * submit is in flight and a poll landing now would answer with the state that * submit is about to replace. */ export interface PollRegion { active: boolean; paused: boolean; } export interface FiatFlowState { phase: FiatPhase; page: FiatPage; stepResponse?: FiatStepResponse; /** Latest priced terms, retained while a later payment state owns the UI. */ quote?: Quote; dispatch: TransitionDispatch; /** Values the user has entered on the current screen. */ collected: CollectedInputs; poll: PollRegion; error?: unknown; } export type FiatFlowEvent = { type: 'STEP_RESPONSE_RECEIVED'; stepResponse: FiatStepResponse; /** How this flow reads an order — see {@link ComputePageOptions}. */ pageOptions?: ComputePageOptions; } | { type: 'FIELD_CHANGED'; name: string; value: JsonValue; } | { type: 'SUBMIT_STARTED'; } | { type: 'SUBMIT_FAILED'; } | { type: 'SURFACE_SETTLED'; } | { type: 'POLL_GAVE_UP'; error?: unknown; } | { type: 'EXITED'; }; export declare const initialFiatFlowState: FiatFlowState; /** Polling only runs where all three agree, so callers ask this, not the fields. */ export declare function isPolling(state: FiatFlowState): boolean; /** * The meta-machine, as a reducer. * * Two rules do most of the work: * - Terminality comes from the table via `page.terminal`, never from * `transitions.length`. `KYC{ON_HOLD}` emits no transitions and is not over. * - Collected values survive a step response with the *same* identity and are * dropped otherwise, so an error re-entry is a banner on the screen the user * is already on rather than a form that blanks itself. */ export declare function fiatFlowReducer(state: FiatFlowState, event: FiatFlowEvent): FiatFlowState; //# sourceMappingURL=fiatFlowReducer.d.ts.map