UNPKG

@funkit/connect

Version:

Funkit Connect SDK elevates DeFi apps via web2 sign-ins and one-click checkouts.

67 lines (66 loc) 3.28 kB
import type { PerpsTransferDirection, PerpsTransferStatus } from './PolymarketPerpsTransferScreen'; /** * pUSD has 6 on-chain decimals, so balances carry up to 6 decimal places. We * render only the decimals actually present, up to 6: capping at 2 rounded * `196.867461` *up* to `196.87`, so Max filled a value above the real balance * and tripped the insufficient-balance guard. At 6 decimals the value is * reproduced exactly. There is no minimum, so trailing zeros are trimmed — * a `1.1` balance fills as `1.1`, not `1.100000` (or `1.10`). * * Not `formatCurrencyAndStringify` — that helper produces a 2-decimal `$` * display string, while this fills the editable input with an exact, * re-parsable pUSD amount. */ export declare function formatAmountValue(value: number): string; export interface PerpsTransferFormProps { predictionsBalanceUsd: number; perpsBalanceUsd: number; /** Minimum pUSD to transfer *into* predictions (USD). */ predictionsMinTransferUsd?: number; /** Minimum pUSD to transfer *into* perps (USD). */ perpsMinTransferUsd?: number; initialDirection?: PerpsTransferDirection; /** Initial amount input string (pUSD). */ initialAmountUsd?: string; status?: PerpsTransferStatus; onTransfer: (params: { /** Exact string the user entered (validated numeric, ≤6 decimals). */ amountUsd: string; direction: PerpsTransferDirection; }) => void; } export interface PerpsTransferAccount { /** Localized account name ("Predictions" / "Perps"). */ label: string; balanceUsd: number; } /** Plain form state consumed by `PerpsTransferRows` and `PerpsTransferBottomBar`. */ export interface PerpsTransferForm { /** Raw amount input string (may contain separators). */ amount: string; /** Validated setter — ignores input that isn't numeric with ≤6 decimals. */ setAmount: (next: string) => void; /** Fills the amount with the source balance at full 6-decimal precision. */ fillMaxAmount: () => void; swapDirection: () => void; /** The editable "From" account. */ source: PerpsTransferAccount; /** The read-only "To" account mirroring the source. */ destination: PerpsTransferAccount; /** Validation/error notice line; `null` when nothing should be shown. */ noticeText: string | null; /** Status for the action button (`error` is remapped to a retry-able idle). */ buttonStatus: PerpsTransferStatus; isTransferDisabled: boolean; /** Reports the entered amount + direction via the host's `onTransfer`. */ requestTransfer: () => void; } /** * Owns the Perps ⇄ Predictions transfer form state — amount, direction, and * the derived validation/notice/button values — so both the standalone * {@link PolymarketPerpsTransferScreen} (Dialog) and the in-modal * `PerpsTransferStep` (renders rows inline + portals the bottom bar) share * identical behavior. Returns plain values; `PerpsTransferRows` and * `PerpsTransferBottomBar` render them. */ export declare function usePerpsTransferForm({ predictionsBalanceUsd, perpsBalanceUsd, predictionsMinTransferUsd, perpsMinTransferUsd, initialDirection, initialAmountUsd, status, onTransfer, }: PerpsTransferFormProps): PerpsTransferForm;