/** * Configuration options for formatting blockchain token amounts. */ export interface FormatAmountPropsType { /** * The raw integer amount (string) in the smallest token unit. * Must be a valid integer string (no decimals, may include leading "-"). * * @example * // For 1.5 EGLD (18 decimals): "1500000000000000000" * // For 1000 USDC (6 decimals): "1000000000" */ input: string; /** * Number of decimals defined by the token (e.g. 18 for EGLD, 6 for USDC). * This determines how many decimal places to shift when converting from * the smallest unit to the human-readable format. * * @default DECIMALS (typically 18) * @example * // EGLD: 18, USDC: 6 */ decimals?: number; /** * Maximum number of decimal digits to display in the formatted output. * This parameter works differently depending on `showLastNonZeroDecimal`: * - When `showLastNonZeroDecimal=false`: strictly limits decimal places * - When `showLastNonZeroDecimal=true`: ignored for truncation, but affects special cases * * @default DIGITS (typically 4) * @example * // For 1.23456789 EGLD (18 decimals): "1234567890000000000" * // digits=4 with showLastNonZeroDecimal=false: "1.2345" * // digits=4 with showLastNonZeroDecimal=true: "1.23456789" */ digits?: number; /** * If true, insert thousands separators (commas) into the integer part. * Only affects the integer portion, not the decimal places. * * @default false * @example * // For 1000.5 EGLD (18 decimals, showLastNonZeroDecimal: true): "1000500000000000000000" * // false: "1000" * // true: "1,000" */ addCommas?: boolean; /** * If true, amounts smaller than the smallest displayable unit will show * a less-than format instead of zero. * * @default false * @example * // For 0.000000000000000001 EGLD (18 decimals, showIsLessThanDecimalsLabel: true): "1" * // false: "0.0000" * // true: "<0.0001" */ showIsLessThanDecimalsLabel?: boolean; /** * Controls the primary decimal formatting behavior: * * - **`true`** (default): When decimals exist, always pad to at least `digits` decimal places. * If there are more significant decimal places than `digits`, show all of them. * * - **`false`**: When decimals exist, always pad to exactly `digits` decimal places. * Truncate if there are more decimal places than `digits`. * * @default true * @example * // For 1.123456789 EGLD (18 decimals, digits=4): "1123456789000000000" * // showLastNonZeroDecimal=true: "1.123456789" (more than 4 digits, show all) * // showLastNonZeroDecimal=false: "1.1234" (exactly 4 digits) * * // For 1.1 EGLD (18 decimals, digits=4): "1100000000000000000" * // showLastNonZeroDecimal=true: "1.1" (pad to 4 digits minimum) * // showLastNonZeroDecimal=false: "1.1000" (exactly 4 digits) * * // For 1 EGLD (18 decimals, digits=4): "1000000000000000000" * // showLastNonZeroDecimal=true: "1" (integer, no decimals to pad) * // showLastNonZeroDecimal=false: "1.0000" (integer, no decimals to pad) * * // For 1.0000005 EGLD (18 decimals, digits=4): "1000000500000000000" * // showLastNonZeroDecimal=true: "1.0000005" (more than 4 digits, show all) * // showLastNonZeroDecimal=false: "1.0000" (exactly 4 digits) */ showLastNonZeroDecimal?: boolean; } /** * Formats blockchain token amounts from their smallest unit representation * to human-readable decimal format with configurable precision and formatting options. * * This function handles the conversion from raw integer token amounts (as stored on blockchain) * to human-readable decimal format with proper formatting, precision control, and edge case handling. * * @param props - Configuration object with formatting options * @returns Formatted string representation of the amount * * @throws {Error} When input is not a valid integer string * * @example * // Basic usage - 1.5 EGLD * formatAmount({ input: "1500000000000000000" }) * // Returns: "1.5" * * @example * // With precision control * formatAmount({ * input: "1123456789000000000", * showLastNonZeroDecimal: false, * digits: 4 * }) * // Returns: "1.1234" * * @example * // With precision control * formatAmount({ * input: "1123456789000000000", * showLastNonZeroDecimal: true, * digits: 4 * }) * // Returns: "1.123456789" * * @example * // With thousands separators * formatAmount({ * input: "1000000000000000000000", * addCommas: true * }) * // Returns: "1,000" * * @example * // Custom token with 6 decimals (USDC) * formatAmount({ * input: "1500000", * decimals: 6 * }) * // Returns: "1.5" * * @example * // Very small amounts with less-than label * formatAmount({ * input: "1", * decimals: 18, * digits: 4, * showIsLessThanDecimalsLabel: true * }) * // Returns: "<0.0001" */ export declare function formatAmount({ addCommas, decimals, digits, input, showIsLessThanDecimalsLabel, showLastNonZeroDecimal }: FormatAmountPropsType): string;