From dec6cc54a855984391e2564857425c9e2e8d2ba8 Mon Sep 17 00:00:00 2001 From: dcts Date: Tue, 4 Jun 2024 02:20:16 +0200 Subject: [PATCH] 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) {