@edgex-web/components
Version:
EdgeX Universal UI Components Library - Reusable React components for deposit, withdraw and other common UI patterns
66 lines • 2.73 kB
TypeScript
export declare const calculateBalance: (balance: string, amount: string, decimals: number) => string;
export declare const calculateEquity: (equity: number, depositAmount: string, rate: string) => string;
export declare const isGreaterThan: (a: string | number, b: string | number) => boolean;
export declare const isLessThan: (a: string | number, b: string | number) => boolean;
/**
* 格式化金额显示
* 规则:
* - 最长显示6位小数
* - 如果末尾为0,则最多显示2位小数
* - 保持至少2位小数(当整数部分为0时)
*
* @param value - 要格式化的数值(字符串或数字)
* @returns 格式化后的字符串
*
* @example
* formatAmount('0.000287645') // '0.000287'
* formatAmount('0.00') // '0.00'
* formatAmount('0.002800') // '0.0028'
* formatAmount('15.21532') // '15.21532'
* formatAmount('0.1520') // '0.152'
* formatAmount('0.1') // '0.10'
* formatAmount('0.11') // '0.11'
* formatAmount('0.111') // '0.111'
*/
export declare const formatAmount: (value: string | number) => string;
/**
* 验证和格式化输入金额
* @param input - 用户输入的字符串
* @param maxBalance - 最大可用余额
* @returns { isValid: boolean, formattedValue: string, errorType?: string }
*/
export declare const validateAndFormatInput: (input: string, maxBalance?: string) => {
isValid: boolean;
formattedValue: string;
errorType?: "invalid_char" | "exceed_decimals" | "exceed_balance" | "auto_adjusted_to_max";
};
/**
* 格式化输入显示(用于实时显示)
* 与 formatAmount 不同,这个函数用于输入过程中的实时格式化
* 不强制添加小数位,保持用户输入的原始意图
*/
export declare const formatInputDisplay: (value: string) => string;
export declare const mockUseTranslation: () => (key: string, params?: any) => string;
export declare const mockUseToast: () => {
show: (_message: string, _options?: any) => void;
};
export declare const CHAIN_IDS: {
readonly ETHEREUM: 1;
readonly BSC: 56;
readonly POLYGON: 137;
readonly ARBITRUM: 42161;
readonly ARBITRUM_SEPOLIA: 421614;
readonly OPTIMISM: 10;
readonly AVALANCHE: 43114;
readonly SEPOLIA: 11155111;
};
export declare const CHAINS_WITHOUT_LARGE_DEPOSIT_WARNING: readonly [1, 11155111, 42161, 421614];
export declare const shouldShowLargeDepositWarning: (chain: {
chainId?: string | number;
}) => boolean;
/**
* 检查是否应该显示 LayerZero 提示
* 条件:Arbitrum 链 + USDT + 金额 >= 200,000
*/
export declare const shouldShowLayerZeroTip: (chainId: number | string | undefined, tokenSymbol: string | undefined, depositAmount: string | undefined) => boolean;
//# sourceMappingURL=utils.d.ts.map