Skip to content

Commit

Permalink
Fix bug in calculcation of All Time Staking Rewards Earned
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Jul 21, 2023
1 parent fdf0499 commit e5b0583
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions apps/web/src/composables/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ export default function useContracts() {
const formattedTotalStakedUSD = formatNumber(totalStakedUSD)
const formattedTotalStakedETH = formatNumber(totalStakedETH)
return {
eth: formattedTotalStakedUSD + ' ETH',
usd: '$ ' + formattedTotalStakedETH
eth: formattedTotalStakedETH + ' ETH',
usd: '$ ' + formattedTotalStakedUSD
}
} catch (error) {
console.log('Error occurred while fetching stake:', error)
Expand Down Expand Up @@ -208,13 +208,15 @@ export default function useContracts() {
const userEventTotalsSum = userEventTotals.reduce((acc, curr) => {
const { StakeDeposited, WithdrawalInitiated } = curr
return {
StakeDeposited: acc.StakeDeposited && StakeDeposited ? acc.StakeDeposited + StakeDeposited : acc.StakeDeposited,
WithdrawalInitiated: acc.WithdrawalInitiated && WithdrawalInitiated ? acc.WithdrawalInitiated + WithdrawalInitiated : acc.WithdrawalInitiated
StakeDeposited: acc.StakeDeposited + (StakeDeposited || 0),
WithdrawalInitiated: acc.WithdrawalInitiated + (WithdrawalInitiated || 0),
}
}, { StakeDeposited: 0, WithdrawalInitiated: 0 })
}, { StakeDeposited: 0, WithdrawalInitiated: 0 } as { StakeDeposited: number; WithdrawalInitiated: number })


const stakedDepositedETH = userEventTotalsSum.StakeDeposited
const withdrawalInitiatedETH = userEventTotalsSum.WithdrawalInitiated

/* Get User's All Time Rewards by Subtracting (StakeDesposited + WithdrawalInitiated) from CurrentStake */
const currentUserStakeMinusEvents = currentUserStakeETH - (stakedDepositedETH as number) - (withdrawalInitiatedETH as number)
return {
Expand Down

0 comments on commit e5b0583

Please sign in to comment.