From ea09241628c93c9c572c4ca9b06fdb8249834220 Mon Sep 17 00:00:00 2001 From: Petromir Petrov Date: Fri, 14 Feb 2025 15:49:06 +0200 Subject: [PATCH] fix: swap fromtoken amount without zero (.1) error --- src/controllers/swapAndBridge/swapAndBridge.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/controllers/swapAndBridge/swapAndBridge.ts b/src/controllers/swapAndBridge/swapAndBridge.ts index cb404de8d..807d5d15c 100644 --- a/src/controllers/swapAndBridge/swapAndBridge.ts +++ b/src/controllers/swapAndBridge/swapAndBridge.ts @@ -486,6 +486,7 @@ export class SwapAndBridgeController extends EventEmitter { } = props if (fromAmount !== undefined) { + const fromAmountFormatted = fromAmount.indexOf('.') === 0 ? `0${fromAmount}` : fromAmount this.fromAmount = fromAmount ;(() => { if (fromAmount === '') { @@ -512,7 +513,7 @@ export class SwapAndBridgeController extends EventEmitter { const { tokenPriceBigInt, tokenPriceDecimals } = convertTokenPriceToBigInt(tokenPrice) // Convert the numbers to big int - const amountInFiatBigInt = parseUnits(fromAmount, amountInFiatDecimals) + const amountInFiatBigInt = parseUnits(fromAmountFormatted, amountInFiatDecimals) this.fromAmount = formatUnits( (amountInFiatBigInt * CONVERSION_PRECISION_POW) / tokenPriceBigInt, @@ -528,7 +529,7 @@ export class SwapAndBridgeController extends EventEmitter { if (!this.fromSelectedToken) return const sanitizedFieldValue = getSanitizedAmount( - fromAmount, + fromAmountFormatted, this.fromSelectedToken.decimals ) // Convert the field value to big int