Skip to content

Commit

Permalink
refined slider value to keep min 2 decimal and max 4 demical digits
Browse files Browse the repository at this point in the history
  • Loading branch information
noumantahir committed Mar 14, 2023
1 parent 2eab416 commit ba8f24e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/utils/vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ export const getEstimatedAmount = (account, globalProps: GlobalProps, sliderValu
const hbdMedian = base / quote;
const voteEffectiveShares = calculateVoteRshares(totalVests, _votingPower, weight);
const voteValue = (voteEffectiveShares / fundRecentClaims) * fundRewardBalance * hbdMedian;
const estimatedAmount = weight < 0 ? Math.min(voteValue * -1, 0) : Math.max(voteValue, 0);
const estimatedAmount = (weight < 0 ? Math.min(voteValue * -1, 0) : Math.max(voteValue, 0)) * 200;

if (isNaN(estimatedAmount)) {
return '0.00';
}
else if (estimatedAmount >= 1) {
return estimatedAmount.toFixed(2)
} else {
const _fixed = parseFloat(estimatedAmount.toFixed(4));
const _precision = _fixed < 0.001 ? 1 : 2
return _fixed.toPrecision(_precision);
}

return Number.isNaN(estimatedAmount) ? '0.00000' : estimatedAmount.toFixed(5);
};

/*
Expand Down

0 comments on commit ba8f24e

Please sign in to comment.