Skip to content

Commit 780e82e

Browse files
committed
fix: staking earnings formatting
1 parent 4c76e15 commit 780e82e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/features/rnbw-staking/stores/derived/useRnbwStakingEarnings.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { convertRawAmountToDecimalFormat, isZero } from '@/helpers/utilities';
22
import { createDerivedStore } from '@/state/internal/createDerivedStore';
33
import { shallowEqual } from '@/worklets/comparisons';
44
import { useStakingPositionStore } from '../rnbwStakingPositionStore';
5-
import { divWorklet, sumWorklet, toFixedWorklet, toPercentageWorklet } from '@/framework/core/safeMath';
5+
import { divWorklet, sumWorklet, toFixedWorklet, toPercentageWorklet, truncateToDecimals } from '@/framework/core/safeMath';
66
import { formatNumber } from '@/helpers/strings';
77

88
type StakingEarnings = {
@@ -41,10 +41,10 @@ export const useRnbwStakingEarnings = createDerivedStore<StakingEarnings>(
4141

4242
return {
4343
totalEarnings: formatNumber(totalEarnings, { decimals: 4 }),
44-
cashbackEarnings: formatNumber(cashbackEarnings),
45-
cashbackShare: totalIsZero ? '0%' : `${toPercentageWorklet(cashbackRatio, 0.001)}%`,
46-
exitRewardsEarnings: formatNumber(exitRewardsEarnings),
47-
exitRewardsShare: totalIsZero ? '0%' : `${toPercentageWorklet(exitRewardsRatio, 0.001)}%`,
44+
cashbackEarnings: isZero(cashbackEarnings) ? '0' : formatNumber(truncateToDecimals(cashbackEarnings, 2), { decimals: 2 }),
45+
cashbackShare: totalIsZero ? '0%' : `${toPercentageWorklet(cashbackRatio)}%`,
46+
exitRewardsEarnings: isZero(exitRewardsEarnings) ? '0' : formatNumber(truncateToDecimals(exitRewardsEarnings, 2), { decimals: 2 }),
47+
exitRewardsShare: totalIsZero ? '0%' : `${toPercentageWorklet(exitRewardsRatio)}%`,
4848
};
4949
},
5050
{ equalityFn: shallowEqual, fastMode: true }

0 commit comments

Comments
 (0)