From f17b7b80552a45f01065b6be94b2394abd01820b Mon Sep 17 00:00:00 2001 From: Yaki Date: Tue, 9 Jan 2024 15:58:45 -0800 Subject: [PATCH 1/4] Fix useEffect causing infinite rerenders --- src/components/ProjectCard.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/ProjectCard.tsx b/src/components/ProjectCard.tsx index 37449d0..6cd711d 100644 --- a/src/components/ProjectCard.tsx +++ b/src/components/ProjectCard.tsx @@ -122,7 +122,8 @@ const ProjectCard = (props: ProjectCardProps) => { useEffect(() => { calcMinSupportMet(); - }, [calcMinSupportMet]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); useEffect(() => { if (totalStaked !== undefined) { From 64cb3f657928d461f37a743a9397f1c9c2ae8f7b Mon Sep 17 00:00:00 2001 From: Yaki Date: Tue, 9 Jan 2024 16:22:55 -0800 Subject: [PATCH 2/4] add missing await keywords --- src/routes/xtransfer.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routes/xtransfer.tsx b/src/routes/xtransfer.tsx index 54d23cd..d7a7820 100644 --- a/src/routes/xtransfer.tsx +++ b/src/routes/xtransfer.tsx @@ -281,7 +281,7 @@ const Transfer = () => { // Multiply the amount by 10^12 and convert to a string const amountToSend = amountBigNumber.multipliedBy(new BigNumber(10).pow(12)).toString(); - api.tx.xTokens + await api.tx.xTokens .transfer( 0, amountToSend, @@ -367,11 +367,11 @@ const Transfer = () => { const apiBasilisk = await ApiPromise.create({ provider: wsProviderBasilisk, }); - + console.log('amountBigNumber', amountBigNumber.toString()); // Multiply the amount by 10^12 and convert to a string const amountToSend = amountBigNumber.multipliedBy(new BigNumber(10).pow(12)).toString(); - apiBasilisk.tx.xTokens + await apiBasilisk.tx.xTokens .transfer( 6, amountToSend, From 77a69ce99ff9c9bf4530929ff815da1545a692c5 Mon Sep 17 00:00:00 2001 From: Yaki Date: Tue, 9 Jan 2024 16:38:58 -0800 Subject: [PATCH 3/4] Refactor input handling in Transfer component --- src/routes/xtransfer.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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 (
From d2a1c7bb2284b80f5a1bec4071f242b2dbd8f44d Mon Sep 17 00:00:00 2001 From: Yaki Date: Tue, 9 Jan 2024 16:45:14 -0800 Subject: [PATCH 4/4] chore: set max width on metric dashboard --- src/components/MetricDashboard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MetricDashboard.tsx b/src/components/MetricDashboard.tsx index ee33d97..ec57edf 100644 --- a/src/components/MetricDashboard.tsx +++ b/src/components/MetricDashboard.tsx @@ -60,7 +60,7 @@ const MetricDashboard = (props: MetricDashboardProps) => { return (
+ className="min-h-40 max-w-[1068px] relative overflow-x-auto rounded-xl shadow flex lg:flex-wrap flex-grow flex-row gap-4 justify-between backdrop-blur-sm bg-black bg-opacity-40 tinker-scrollbar scrollbar scrollbar-thumb-amber-300 scrollbar-thin overflow-x-auto p-4 mb-4"> {totalUnclaimed !== undefined && {totalUnclaimed ? `${ formatBalanceToTwoDecimals(totalUnclaimed) } TNKR` : "0 TNKR"}