import { type OpenfortError } from '../../errors/base.js'; import { type FundingClient, type FundingSession, type FundingTarget, type PayLinkParams, type PaymentMethodInput, type SessionStatus } from './fundingClient.js'; /** * The resolved result of a funding session action. * * @example * ```ts * import type { FundingSessionResult } from '@openfort/react' * * function sessionId(result: FundingSessionResult) { * return 'error' in result ? undefined : result.session.id * } * ``` */ export type FundingSessionResult = { session: FundingSession; } | { error: OpenfortError; }; /** * The resolved result of a hosted funding-link action. * * @example * ```ts * import type { FundingPayLinkResult } from '@openfort/react' * * function payLinkUrl(result: FundingPayLinkResult) { * return 'error' in result ? undefined : result.url * } * ``` */ export type FundingPayLinkResult = { url: string; } | { error: OpenfortError; }; export type UseFunding = { session: FundingSession | null; status: SessionStatus | 'idle'; error: OpenfortError | null; /** True while a session is being created and its deposit address fetched. */ loading: boolean; /** True when a funding client is resolved (injected, or uiConfig.fundingBaseUrl set). */ isAvailable: boolean; /** Create a session, set a payment method, and poll until terminal. */ fund: (target: FundingTarget, paymentMethod: PaymentMethodInput) => Promise; /** Create a bare session for a target (no payment method, no polling). Used by * the Coinbase CEX rail, which only needs the session id + secret to mint a * pay-link; the destination is bound to the session so the client can't redirect funds. */ createSession: (target: FundingTarget) => Promise; /** Poll an already-created session (id + clientSecret) until it reaches a * terminal state, surfacing `status`/`session` updates as it goes. Used by the * CEX rail, which hands off to a hosted Coinbase flow and then watches the * bound session settle to drive the success/failed screen. */ track: (session: { id: string; clientSecret: string; }) => Promise; /** Resolve a hosted Coinbase pay URL for an existing session. Coinbase delivers * to the session's bound destination, so only the amount (and optional asset) is client-supplied. */ payLink: (params: PayLinkParams) => Promise; /** Reset to the idle state (e.g. when leaving the Deposit flow). */ reset: () => void; }; /** * Options for {@link useFunding}. * * @example * ```ts * import type { UseFundingOptions } from '@openfort/react' * * const options: UseFundingOptions = { * onError: (error) => console.error(error.shortMessage), * } * ``` */ export type UseFundingOptions = { /** Inject a funding client (tests, or a custom backend). Defaults to the * fetch adapter over `uiConfig.fundingBaseUrl`. */ client?: FundingClient; /** * Resolve the base URL from the configured Openfort API backend * instead of `uiConfig.fundingBaseUrl`. The CEX (Coinbase pay-link) rail is served * by the API, not the standalone funding service — `DepositCex` opts in. */ useBackendUrl?: boolean; /** Called when a funding action resolves with an error. Callback failures are isolated from the action result. */ onError?: (error: OpenfortError) => unknown; }; /** * React surface over the funding session API. * * A session is one deposit attempt against a destination. The hook creates a * session, sets one payment method (a source the user commits to sending from, * or a fiat onramp method), then polls until the session reaches a terminal * state. The response carries everything the UI (or an agent) needs: a receiver * address, a scannable URI, prefilled wallet deeplinks, and CEX guidance. * * The hook depends on a {@link FundingClient}, not on `fetch` directly, so a * custom backend or a test double can be injected through * {@link UseFundingOptions.client}. * * Every action resolves to a discriminated result, so operational failures do * not require a `try`/`catch`. * * @returns Session state plus `fund` (run the deposit flow) and `reset`. * * @example * ```tsx * import { useFunding } from '@openfort/react' * * function FundingButton() { * const { fund, error } = useFunding() * const run = async () => { * const result = await fund( * { chain: 'eip155:8453', currency: 'native', address: '0x1111111111111111111111111111111111111111' }, * { type: 'evm', source: { chain: 'eip155:1', currency: 'native', amount: '1000000000000000' } } * ) * if ('error' in result) return * console.log(result.session.id) * } * return * } * ``` */ /** * Resolve the funding client every funding hook shares, in order of preference: * 1. an explicitly injected client (tests / custom backends), * 2. the SDK's `openfort.funding` namespace once it covers the full session * surface (an older SDK without methods/quote would break the fiat hooks), * 3. the fetch adapter over `uiConfig.fundingBaseUrl` / the API backend. * The SDK namespace covers sessions; embedded auth and pay-links stay on the * fetch adapter until the SDK exposes them (CEX is deferred), so the two are * composed. */ export declare function useFundingClient(options?: UseFundingOptions): FundingClient | null; export declare function useFunding(options?: UseFundingOptions): UseFunding;