diff --git a/src/routes/xtransfer.tsx b/src/routes/xtransfer.tsx index d7a7820..eef7949 100644 --- a/src/routes/xtransfer.tsx +++ b/src/routes/xtransfer.tsx @@ -186,14 +186,17 @@ const Transfer = () => { // Remove all non-numeric characters except for the decimal point const sanitizedInput = e.replace(/[^\d.]/g, ''); + // Remove leading zeroes after the tens digit + const inputWithoutLeadingZeroes = sanitizedInput.replace(/^0+([0-9]+)/, '$1'); + // Format the available balance with 12 decimals const formattedBalance = new BigNumber(availableBalance.toString()).dividedBy(new BigNumber(10).pow(12)); - if (sanitizedInput === '') { - setAmount('0'); - } else if (Number(sanitizedInput) >= 0 && Number(sanitizedInput) <= formattedBalance.toNumber()) { - setAmount(sanitizedInput); - } else if (Number(sanitizedInput) > formattedBalance.toNumber()) { + if (inputWithoutLeadingZeroes === '') { + setAmount(''); + } else if (Number(inputWithoutLeadingZeroes) >= 0 && Number(inputWithoutLeadingZeroes) <= formattedBalance.toNumber()) { + setAmount(inputWithoutLeadingZeroes); + } else if (Number(inputWithoutLeadingZeroes) > formattedBalance.toNumber()) { setAmount(formattedBalance.toString()); } }; @@ -469,10 +472,6 @@ const Transfer = () => { }; }, [api, apiBasilisk, selectedAccount, setupSubscriptions]); - useEffect(() => { - setAmount("0"); - }, [pair.from, pair.to]); - return (