From d3bbc2f18f2d87e5eefcb30a9de3b01feb1b8c8e Mon Sep 17 00:00:00 2001 From: Alan Soares Date: Wed, 18 Oct 2023 09:39:06 +1300 Subject: [PATCH 1/2] fix: parse bigInt balance as float --- src/hooks/useGetAssetBalance.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/hooks/useGetAssetBalance.ts b/src/hooks/useGetAssetBalance.ts index 3039ec518..3781b367b 100644 --- a/src/hooks/useGetAssetBalance.ts +++ b/src/hooks/useGetAssetBalance.ts @@ -67,6 +67,7 @@ export const useGetAssetBalance = () => { */ const { data: keplrBalance, isLoading: keplrBalanceIsLoading } = useGetKeplerBalance(); + useEffect( () => { if (srcChain.module !== "axelarnet" || !keplrConnected) { @@ -124,6 +125,13 @@ export const useGetAssetBalance = () => { }; }; +function parseBigIntWithDecimals(bigint: bigint, decimals: number): number { + const divisor = BigInt(10 ** decimals); + const wholePart = Number(bigint / divisor); + const remainder = Number(bigint % divisor) / Number(divisor); + return wholePart + remainder; +} + const useGetEvmBalance = () => { const { address } = useAccount(); const asset = useSwapStore((state) => state.asset); @@ -194,8 +202,10 @@ const useGetEvmBalance = () => { return setBalance(value); } - const num = - (erc20Balance ?? BigInt(0)) / BigInt(10 ** (asset?.decimals ?? 0)); + const num = parseBigIntWithDecimals( + BigInt(erc20Balance ?? 0), + asset?.decimals ?? 0 + ); setBalance( num.toLocaleString("en", { From 0cac58fb44bfc70e12c52545c8f2cea9fa4b40a6 Mon Sep 17 00:00:00 2001 From: Alan Soares Date: Wed, 18 Oct 2023 09:40:12 +1300 Subject: [PATCH 2/2] 0.5.9 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ac77318d7..d7445202e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "axelar-satellite", - "version": "0.5.8", + "version": "0.5.9", "private": true, "scripts": { "dev": "next dev",