Skip to content

Commit

Permalink
fix: protect for distributions without walletAddress found leading to…
Browse files Browse the repository at this point in the history
… undefined results
  • Loading branch information
kunstmusik committed Nov 11, 2024
1 parent 2da372e commit aa51f59
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/hooks/useRewardsEarned.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ const useRewardsEarned = (walletAddress?: string) => {
const previousEpochDistributed =
previousEpoch.distributions.rewards.distributed;
const previousEpochRewards = previousEpochDistributed
? previousEpochDistributed[walletAddress]
? previousEpochDistributed[walletAddress] || 0
: 0;

const totalForPastAvailableEpochs = epochs.reduce((acc, epoch) => {
const distributed = epoch.distributions.rewards.distributed;
return acc + (distributed ? distributed[walletAddress] : 0);
return acc + (distributed ? distributed[walletAddress] || 0 : 0);
}, 0);

setRewardsEarned({
previousEpoch: new mIOToken(previousEpochRewards).toIO().valueOf(),
totalForPastAvailableEpochs: new mIOToken(totalForPastAvailableEpochs)
Expand Down

0 comments on commit aa51f59

Please sign in to comment.