From b4ab75b92531b6b401a53f0b22d00ba5bbfea944 Mon Sep 17 00:00:00 2001 From: cryptotavares Date: Fri, 14 Nov 2025 16:55:44 +0000 Subject: [PATCH] fix: remove hex amount leading zeros --- src/components/transactions/swapComparison.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/components/transactions/swapComparison.js b/src/components/transactions/swapComparison.js index 9f8d09e7..74b5000e 100644 --- a/src/components/transactions/swapComparison.js +++ b/src/components/transactions/swapComparison.js @@ -43,6 +43,15 @@ const V4_BASE_ACTIONS_ABI_DEFINITION = { }; // Helper functions for input validation and parsing +function stripLeadingZeros(hexString) { + // Handle 0x0 or 0x00...0 -> return 0x0 + if (hexString === '0x' || /^0x0+$/u.test(hexString)) { + return '0x0'; + } + // Remove leading zeros: 0x0110d... -> 0x110d... + return hexString.replace(/^0x0+/u, '0x'); +} + function isValidAddress(address) { return ethers.utils.isAddress(address); } @@ -58,8 +67,10 @@ function parseEthAmount(input) { if (isNaN(parsed) || parsed < 0) { return null; } - // Convert ETH to wei and then to hex - return ethers.utils.parseEther(value.toString()).toHexString(); + // Convert ETH to wei and then to hex, stripping leading zeros + return stripLeadingZeros( + ethers.utils.parseEther(value.toString()).toHexString(), + ); } catch { return null; } @@ -104,7 +115,9 @@ function getConfigValues() { const ethAmountHex = parseEthAmount(ethAmountInput) || - ethers.utils.parseEther(DEFAULT_ETH_AMOUNT).toHexString(); + stripLeadingZeros( + ethers.utils.parseEther(DEFAULT_ETH_AMOUNT).toHexString(), + ); const feeBips = parseFeePercentage(feePercentageInput) || DEFAULT_FEE_PERCENTAGE * 100;