From bf600c32c87216496ed8b8ab3f73f28058354c96 Mon Sep 17 00:00:00 2001 From: AzizbekFayziyev Date: Mon, 7 Jul 2025 16:35:31 +0500 Subject: [PATCH] fix: sientific notation --- shared/utils.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/shared/utils.ts b/shared/utils.ts index d6f74c6..33f925d 100644 --- a/shared/utils.ts +++ b/shared/utils.ts @@ -4,7 +4,20 @@ export function validateTokensInput(input: string | number, decimal_point = 12) let inputVal = input; if (typeof inputVal === 'number') { + // scientific notation check + if (inputVal.toString().toLowerCase().includes('e')) { + return { + valid: false, + error: 'Scientific notation is not allowed', + }; + } + inputVal = inputVal.toString(); + } else if (/^[+-]?\d+(\.\d+)?[eE][+-]?\d+$/.test(inputVal)) { + return { + valid: false, + error: 'Scientific notation is not allowed', + }; } if (inputVal === '') { @@ -28,9 +41,7 @@ export function validateTokensInput(input: string | number, decimal_point = 12) const dotInput = inputVal.replace(/,/g, ''); const decimalDevider = new Decimal(10).pow(decimal_point); - const maxAllowedNumber = MAX_NUMBER.div(decimalDevider); - const minAllowedNumber = new Decimal(1).div(decimalDevider); const rounded = (() => { @@ -69,7 +80,15 @@ export function validateTokensInput(input: string | number, decimal_point = 12) }; } - const dotInputDecimal = new Decimal(rounded); + let dotInputDecimal: Decimal; + try { + dotInputDecimal = new Decimal(rounded); + } catch (e) { + return { + valid: false, + error: 'Invalid number format', + }; + } if (dotInputDecimal.gt(maxAllowedNumber)) { return { @@ -88,4 +107,4 @@ export function validateTokensInput(input: string | number, decimal_point = 12) return { valid: true, }; -} +} \ No newline at end of file