From 801dc713c82c648236df536b3ec8b6612327c3a5 Mon Sep 17 00:00:00 2001 From: dcts Date: Tue, 4 Jun 2024 02:06:20 +0200 Subject: [PATCH 1/2] exit function if addresses are not found to prevent too many error toasts --- src/app/rewards/page.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/rewards/page.tsx b/src/app/rewards/page.tsx index 1e7cbec1..792fa7a8 100644 --- a/src/app/rewards/page.tsx +++ b/src/app/rewards/page.tsx @@ -102,7 +102,10 @@ function RewardsCard() { useEffect(() => { async function loadRewards() { - await dispatch(fetchAddresses()); + const fetchAddressesResult = await dispatch(fetchAddresses()); + if (!fetchAddressesResult.payload) { + return; // quit if address could not be loaded + } let fetchReceiptsAction = await dispatch(fetchReciepts(pairsList)); // console.log("fetchReceiptsAction: ", fetchReceiptsAction); await dispatch(fetchAccountRewards()); From dec6cc54a855984391e2564857425c9e2e8d2ba8 Mon Sep 17 00:00:00 2001 From: dcts Date: Tue, 4 Jun 2024 02:20:16 +0200 Subject: [PATCH 2/2] exit if loading of addresses or receipt failed + add comment --- src/app/rewards/page.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/app/rewards/page.tsx b/src/app/rewards/page.tsx index 792fa7a8..37bd37cd 100644 --- a/src/app/rewards/page.tsx +++ b/src/app/rewards/page.tsx @@ -101,16 +101,23 @@ function RewardsCard() { const userHasRewards = getUserHasRewards(rewardData); useEffect(() => { + // Performs 4 sequential actions: + // 1. fetchAddresses : fetches relevant rewards component addresses + // 2. fetchAccountRewards: fetches rewards for a specific account + // 3. fetchReciepts : fetches NFT reciepts + // 4. fetchOrderRewards : fetches rewards based on the NFT reciepts async function loadRewards() { const fetchAddressesResult = await dispatch(fetchAddresses()); if (!fetchAddressesResult.payload) { - return; // quit if address could not be loaded + return; // stop loading rewards if addresses could not be loaded } - let fetchReceiptsAction = await dispatch(fetchReciepts(pairsList)); - // console.log("fetchReceiptsAction: ", fetchReceiptsAction); await dispatch(fetchAccountRewards()); + let fetchReceiptsResult = await dispatch(fetchReciepts(pairsList)); + if (!fetchReceiptsResult.payload) { + return; // stop loading order rewards if reciepts are not loaded successfully + } await dispatch( - fetchOrderRewards(fetchReceiptsAction.payload as string[]) + fetchOrderRewards(fetchReceiptsResult.payload as string[]) ); } if (isConnected) {