From aa51f5939b6ef0c7b0416f288be824d0023f16a6 Mon Sep 17 00:00:00 2001 From: Steven Yi Date: Mon, 11 Nov 2024 14:16:57 -0500 Subject: [PATCH] fix: protect for distributions without walletAddress found leading to undefined results --- src/hooks/useRewardsEarned.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hooks/useRewardsEarned.ts b/src/hooks/useRewardsEarned.ts index 83ecdb6..addf2da 100644 --- a/src/hooks/useRewardsEarned.ts +++ b/src/hooks/useRewardsEarned.ts @@ -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)