Skip to content

Commit

Permalink
fix calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhochu committed Dec 27, 2023
1 parent 0c42bf5 commit d479b58
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions redux/selectors/getTotalAccountBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export const getTotalAccountBalance = (source: "borrowed" | "supplied") =>

const sumTokenAmounts = (account, assets, source) => {
const { collateral, borrows, collaterals, supplies } = account.portfolio || {};
let tokens = source === "supplied" ? [...supplies, ...collaterals] : borrows;
tokens = _.uniqBy(tokens, "token_id");
const tokens = source === "supplied" ? [...supplies, ...collaterals] : borrows;

const tokenAmounts = tokens.map((d) => {
const { token_id } = d || {};
const { price, metadata, config } = assets.data[token_id];
Expand All @@ -61,12 +61,14 @@ const sumTokenAmounts = (account, assets, source) => {
Number(shrinkToken(d?.balance || 0, metadata.decimals + config.extra_decimals)) *
(price?.usd || 0);

const totalCollateral =
Number(
shrinkToken(collateral[token_id]?.balance || 0, metadata.decimals + config.extra_decimals),
) * (price?.usd || 0);
// console.log(`>> source:${source} tokenId:${token_id} total:${total} totalCollateral:${totalCollateral} metadata:${metadata}`)
return source === "supplied" ? total + totalCollateral : total;
// const totalCollateral =
// Number(
// shrinkToken(collateral[token_id]?.balance || 0, metadata.decimals + config.extra_decimals),
// ) * (price?.usd || 0);
// if (source === "supplied") {
// console.log(`>> source:${source} tokenId:${token_id} total:${total} totalCollateral:${totalCollateral} metadata:${metadata.decimals} price:${price?.usd}`)
// }
return source === "supplied" ? total : total;
});

return tokenAmounts;
Expand Down

0 comments on commit d479b58

Please sign in to comment.