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", 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", {