UNPKG

@funkit/connect

Version:

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

69 lines (68 loc) 3.28 kB
import type { ErrorNotification } from '../../../components/FunNotification/FunNotification'; import type { useFunkitTranslation } from '../../../hooks/useFunkitTranslation'; import type { AmountInputError } from './state'; type TFunction = ReturnType<typeof useFunkitTranslation>['t']; export declare const ASSET_DECIMALS = 5; export declare const USD_DECIMALS = 2; export declare const USD_INITIAL_AMOUNT = 100; export declare function getDefaultAmountFromQuickOptions(quickOptions: number[] | undefined): number | undefined; export declare function getUsdMaxAmount(maxUsd: number): number | null; export declare function getUsdMinAmount(minUsd?: number): number; export interface InputAmountSuggestion { autoConfirm: boolean; buttonLabel: string; usdAmount: number; } /** * Get suggested amount from error * Allow recovery actions to user in the CTA Continue button */ export declare const getInputAmountSuggestion: (error: AmountInputError | null, t: TFunction) => InputAmountSuggestion | undefined; export declare const getInputErrorNotification: (error: AmountInputError | null, t: TFunction) => ErrorNotification | undefined; export type NumberSeparators = { decimalSeparator: string; groupSeparator: RegExp; }; export declare function getNumberSeparators(locale: Intl.LocalesArgument): NumberSeparators; export declare function parseNumberInputValue(inputValue: string, separators: NumberSeparators): { amount: number | undefined; amountString: string; amountStringNormalized: string; decimalPart: string | null; integerPart: string; }; export declare function getCurrencyFormattingOptions(fiatCurrency: string, locale: Intl.LocalesArgument): { currencySymbol: string; currencySymbolWithSpacing: string; decimals: number; }; export declare function formatAssetAmountWithLocale(value: number, options: { locale: Intl.LocalesArgument; }): string; export declare function formatCurrencyAmountWithLocale(value: number, options: { fiatCurrency: string; locale: Intl.LocalesArgument; }): string; /** * Canonical fiat display formatter for the InputAmount UI. * * Combines our decimal rules with the utility library's suffix abbreviations: * - Adds locale-aware currency symbol prefix (e.g. `$` for USD, `Kč ` for CZK) * - Min 2, max ASSET_DECIMALS decimal places — trailing zeros trimmed beyond minimum * - Thousands separators (e.g. `$1,234.00`) * - M / B / T suffix abbreviation for amounts ≥ 1,000,000 (e.g. `$1.23M`) * * State-stored fiatAmounts are already floor-rounded to ASSET_DECIMALS precision, * so this function does not apply additional rounding. * * Note: the suffix path (≥ 1M) always uses USD `$` — acceptable since only USD * is currently supported in this flow. */ export declare function formatFiatAmountAndStringify(value: number, options: { fiatCurrency: string; locale: Intl.LocalesArgument; }): string; export declare function replaceStringRange(original: string, replacement: string, start: number, end: number): string; export declare function reformatDecimalPart(decimalPart: string, decimals: number): string; export declare function reformatIntegerPart(integerPart: string, locale: Intl.LocalesArgument, preserveLeadingZeroes: boolean): string; export {};