Skip to content

Commit

Permalink
calculateTokenProportions calculation fix (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikestarrdev committed Oct 5, 2023
1 parent d6bc307 commit a616302
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/features/staking/PieBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const PieBar = () => {
color: "text-gray-500",
bg: null,
var: unstaked,
text: "Not staked",
text: "not staked",
},
];

Expand All @@ -53,7 +53,7 @@ export const PieBar = () => {
<BsCircleFill className={`text-${stakable.color} `} size={14} />
</div>
<span className="font-medium font-mono">{stakable.var}</span>
<span className="text-gray-400 relative -top-0.5">
<span className="content-end text-gray-400 relative -top-0.5">
&nbsp; {stakable.text}
</span>
</div>
Expand Down
14 changes: 10 additions & 4 deletions src/features/staking/utils/calculateTokenProportions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const calculateTokenProportions = ({
staked: number;
unstaked: number;
}): PercentObject => {
const totalBalance = unstakable + staked + unstaked;
const totalBalance = staked + unstaked;

if (totalBalance === 0) {
return {
Expand All @@ -23,9 +23,15 @@ export const calculateTokenProportions = ({
};
}

const unstakablePercent = (unstakable / totalBalance) * 100;

const stakedTotalPercent = 100 - unstakablePercent;
const stakedPercent = (staked / stakedTotalPercent) * 100;
const unstakedPercent = (unstaked / stakedTotalPercent) * 100;

return {
unstakablePercent: (unstakable / totalBalance) * 100,
stakedPercent: (staked / totalBalance) * 100,
unstakedPercent: (unstaked / totalBalance) * 100,
unstakablePercent,
stakedPercent,
unstakedPercent,
};
};

0 comments on commit a616302

Please sign in to comment.