{"version":3,"file":"DtUfwk8V.js","sources":["../../../../../../src/lib/utils/tokenFormatters.ts"],"sourcesContent":["/**\n * Formats a USD value with appropriate decimal places and suffixes\n * @param value The USD value to format\n * @returns Formatted USD string\n */\nexport function formatUsdValue(value: number | string, showLessThanCent: boolean = false): string {\n if (!value) return \"$0.00\";\n const valueNumber = typeof value === 'string' ? Number(value.replace(/,/g, '')) : value;\n\n // For extremely small values (< 0.00001), show scientific notation\n if (valueNumber < 0.01 && valueNumber > 0 && !showLessThanCent) {\n return `< $0.01`;\n }\n \n // For very small values (< 0.01), show up to 6 decimals\n if (valueNumber < 0.01 && valueNumber > 0) {\n return `$${valueNumber.toFixed(6).replace(/\\.?0+$/, '')}`;\n }\n\n // For small values (0.01 to 1), show up to 4 decimals\n if (valueNumber < 1 && valueNumber >= 0.01) {\n return `$${valueNumber.toFixed(4).replace(/\\.?0+$/, '')}`;\n }\n\n if (valueNumber >= 1_000_000_000) {\n return `$${(valueNumber / 1000000000).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}B`;\n }\n if (valueNumber >= 1000000) {\n return `$${(valueNumber / 1000000).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}M`;\n }\n if (valueNumber >= 1000) {\n return `$${(valueNumber / 1000).toLocaleString(undefined, { minimumFractionDigits: 0, maximumFractionDigits: 2 })}K`;\n }\n \n // For normal values (>= 1), show 2 decimals\n return `$${valueNumber.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;\n}\n\n/**\n * Calculates and formats the USD value of a token amount\n * @param rawBalance The raw balance as a string (big integer format)\n * @param price The token price in USD\n * @param decimals The number of decimals for the token\n * @returns Formatted USD value string\n */\nexport function formatTokenValue(rawBalance: string, price: number | undefined, decimals: number = 8): string {\n if (!rawBalance || !price) return \"$0.00\";\n const actualBalance = Number(rawBalance) / Math.pow(10, decimals);\n const value = actualBalance * (price ?? 0);\n return formatUsdValue(value);\n}\n\n/**\n * Converts a human-readable amount to raw token amount (considering decimals)\n * @param amount The amount in human-readable format\n * @param decimals The number of decimals for the token\n * @returns Raw amount as a string (big integer format)\n */\nexport function toRawAmount(amount: string | number, decimals: number = 8): string {\n if (!amount) return \"0\";\n const value = typeof amount === 'string' ? parseFloat(amount) : amount;\n return (value * Math.pow(10, decimals)).toFixed(0);\n}\n\n/**\n * Converts a raw token amount to human-readable format\n * @param rawAmount The raw amount as a string (big integer format)\n * @param decimals The number of decimals for the token\n * @returns Human-readable amount as a number\n */\nexport function fromRawAmount(rawAmount: string, decimals: number = 8): number {\n if (!rawAmount) return 0;\n return Number(rawAmount) / Math.pow(10, decimals);\n}\n\nexport function formatTokenBalance(amount: string | bigint, decimals: number): string {\n if (!amount) return '0';\n \n const value = typeof amount === 'string' ? BigInt(amount) : amount;\n const divisor = BigInt(10 ** decimals);\n const integerPart = value / divisor;\n const fractionalPart = value % divisor;\n \n let result = integerPart.toString();\n \n if (fractionalPart > 0) {\n let fraction = fractionalPart.toString().padStart(decimals, '0');\n // Remove trailing zeros\n fraction = fraction.replace(/0+$/, '');\n if (fraction.length > 0) {\n result += '.' + fraction;\n }\n }\n \n return result;\n}"],"names":["formatUsdValue","value","showLessThanCent","valueNumber","Number","replace","toFixed","toLocaleString","minimumFractionDigits","maximumFractionDigits","formatTokenBalance","amount","decimals","BigInt","divisor","fractionalPart","result","toString","fraction","padStart","length"],"mappings":"AAKgB,SAAAA,EAAeC,EAAwBC,GAA4B,GAC3E,IAACD,EAAc,MAAA,QACb,MAAAE,EAA+B,iBAAVF,EAAqBG,OAAOH,EAAMI,QAAQ,KAAM,KAAOJ,EAGlF,OAAIE,EAAc,KAAQA,EAAc,IAAMD,EACnC,UAIPC,EAAc,KAAQA,EAAc,EAC7B,IAAIA,EAAYG,QAAQ,GAAGD,QAAQ,SAAU,MAIpDF,EAAc,GAAKA,GAAe,IAC3B,IAAIA,EAAYG,QAAQ,GAAGD,QAAQ,SAAU,MAGpDF,GAAe,IACR,KAAKA,EAAc,KAAYI,oBAAe,EAAW,CAAEC,sBAAuB,EAAGC,sBAAuB,OAEnHN,GAAe,IACR,KAAKA,EAAc,KAASI,oBAAe,EAAW,CAAEC,sBAAuB,EAAGC,sBAAuB,OAEhHN,GAAe,IACR,KAAKA,EAAc,KAAMI,oBAAe,EAAW,CAAEC,sBAAuB,EAAGC,sBAAuB,OAI1G,IAAIN,EAAYI,oBAAe,EAAW,CAAEC,sBAAuB,EAAGC,sBAAuB,KACxG,CAuCgB,SAAAC,EAAmBC,EAAyBC,GACpD,IAACD,EAAe,MAAA,IAEpB,MAAMV,EAA0B,iBAAXU,EAAsBE,OAAOF,GAAUA,EACtDG,EAAUD,OAAO,IAAMD,GAEvBG,EAAiBd,EAAQa,EAE3B,IAAAE,GAHgBf,EAAQa,GAGHG,WAEzB,GAAIF,EAAiB,EAAG,CACpB,IAAIG,EAAWH,EAAeE,WAAWE,SAASP,EAAU,KAEjDM,EAAAA,EAASb,QAAQ,MAAO,IAC/Ba,EAASE,OAAS,IAClBJ,GAAU,IAAME,EACpB,CAGG,OAAAF,CACX"}