From 22e7ae86712c17d1f1a8004566d6f762883ea9c9 Mon Sep 17 00:00:00 2001 From: Dima Date: Thu, 26 Dec 2024 11:44:11 +0300 Subject: [PATCH] fix(sphere): estimation apr (#1351) --- src/components/index.js | 1 - .../HeroDetails/components/Details/Details.tsx | 2 +- .../HeroDetails/utils/reduceDetails.ts | 16 +++++++++------- .../Heroes/utils/reduceValidatorData.ts | 16 +++++++++------- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/components/index.js b/src/components/index.js index 1dd21805d..b34425740 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -63,7 +63,6 @@ export { StartStageSearchActionBar, ActionBarSend, RewardsDelegators, - ReDelegate, TransactionError, TextTable, Vitalik, diff --git a/src/pages/Sphere/pages/containers/HeroDetails/components/Details/Details.tsx b/src/pages/Sphere/pages/containers/HeroDetails/components/Details/Details.tsx index 4b7c70616..b31e8da6e 100644 --- a/src/pages/Sphere/pages/containers/HeroDetails/components/Details/Details.tsx +++ b/src/pages/Sphere/pages/containers/HeroDetails/components/Details/Details.tsx @@ -33,7 +33,7 @@ function Col({ } type Options = { - apr?: number; + apr?: string; power?: number; delegateAddress?: string; selfStake?: number; diff --git a/src/pages/Sphere/pages/containers/HeroDetails/utils/reduceDetails.ts b/src/pages/Sphere/pages/containers/HeroDetails/utils/reduceDetails.ts index 2eecbbe5a..e39053b04 100644 --- a/src/pages/Sphere/pages/containers/HeroDetails/utils/reduceDetails.ts +++ b/src/pages/Sphere/pages/containers/HeroDetails/utils/reduceDetails.ts @@ -32,17 +32,19 @@ function reduceDetails( ? big(100).minus(self).dp(3, BigNumber.ROUND_FLOOR).toNumber() : undefined; - const totalVotingPower = big(bondedTokens).multipliedBy( - big(1).minus(validatorInfo.commission.commissionRates.rate) - ); + const stakingProvisionsByItem = stakingProvisions + ? big(stakingProvisions).multipliedBy( + big(1).minus(validatorInfo.commission.commissionRates.rate) + ) + : undefined; const estimatedApr = - bondedTokens && stakingProvisions - ? big(stakingProvisions) - .dividedBy(totalVotingPower) + bondedTokens && stakingProvisionsByItem + ? big(stakingProvisionsByItem) + .dividedBy(bondedTokens) .multipliedBy(100) .dp(2, BigNumber.ROUND_FLOOR) - .toNumber() + .toFixed(2) : undefined; return { diff --git a/src/pages/Sphere/pages/containers/Heroes/utils/reduceValidatorData.ts b/src/pages/Sphere/pages/containers/Heroes/utils/reduceValidatorData.ts index 0d154f50a..c1da1d0f9 100644 --- a/src/pages/Sphere/pages/containers/Heroes/utils/reduceValidatorData.ts +++ b/src/pages/Sphere/pages/containers/Heroes/utils/reduceValidatorData.ts @@ -72,13 +72,15 @@ function reduceValidatorData(data: Validator[], options: Options) { .dp(2, BigNumber.ROUND_FLOOR) .toFixed(2); - const totalVotingPower = new BigNumber(bondedTokens).multipliedBy( - new BigNumber(1).minus(commission.commissionRates.rate) - ); - - const estimatedApr = stakingProvisions - ? new BigNumber(stakingProvisions) - .dividedBy(totalVotingPower) + const stakingProvisionsByItem = stakingProvisions + ? new BigNumber(stakingProvisions).multipliedBy( + new BigNumber(1).minus(commission.commissionRates.rate) + ) + : undefined; + + const estimatedApr = stakingProvisionsByItem + ? new BigNumber(stakingProvisionsByItem) + .dividedBy(bondedTokens) .toNumber() : 0;