Skip to content

Commit

Permalink
bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Dec 25, 2024
1 parent 20f1876 commit 917e4cd
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/client/src/getBalances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ export const getBalances = async function (
t.contract === calls[index].target
);
if (token) {
const balance = ethers.utils.defaultAbiCoder.decode(
["uint256"],
data
)[0];
const formattedBalance = formatUnits(balance, token.decimals);
const balance = BigInt(
ethers.utils.defaultAbiCoder.decode(["uint256"], data)[0]
);
const formattedBalance = (
balance / BigInt(10 ** token.decimals)
).toString();
balances.push({ ...token, balance: formattedBalance });
}
});
Expand Down Expand Up @@ -274,9 +275,10 @@ export const getBalances = async function (
const r = await response.json();
const { funded_txo_sum, spent_txo_sum } = r.chain_stats;
const balance = (
(funded_txo_sum - spent_txo_sum) /
100000000
(BigInt(funded_txo_sum) - BigInt(spent_txo_sum)) /
BigInt(100000000)
).toString();

balances.push({ ...token, balance });
})
);
Expand Down Expand Up @@ -358,11 +360,11 @@ export const getBalances = async function (
const r = await response.json();

if (r.result && r.result.value && r.result.value.length > 0) {
let totalBalance = 0;
let totalBalance = BigInt(0);
for (const acc of r.result.value) {
const amount = acc.account.data.parsed.info.tokenAmount.amount;
const decimals = acc.account.data.parsed.info.tokenAmount.decimals;
totalBalance += parseFloat(amount) / Math.pow(10, decimals);
totalBalance += BigInt(amount) / BigInt(10 ** decimals);
}
balances.push({ ...token, balance: totalBalance.toString() });
} else {
Expand Down

0 comments on commit 917e4cd

Please sign in to comment.