From c04023948bcf8fda6e233889387afd3a5ddd315c Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Wed, 29 Dec 2021 09:30:29 +0800 Subject: [PATCH] Replace weekly watch search loop with new `last_claimed` --- ui/redux/selectors/rewards.js | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/ui/redux/selectors/rewards.js b/ui/redux/selectors/rewards.js index df492467e..c35a63786 100644 --- a/ui/redux/selectors/rewards.js +++ b/ui/redux/selectors/rewards.js @@ -71,23 +71,13 @@ export const selectHasClaimedInitialRewards = createSelector(selectClaimedReward return newUserClaimed && confirmEmailClaimed; }); -export const selectWeeklyWatchClaimedThisWeek = createSelector(selectClaimedRewardsById, (claimedRewardsById) => { - const claimedRewards = Object.values(claimedRewardsById); - - // The list could be huge, so: - // - don't use find() which will look from the top. - // - only search until LOOKUP_LIMIT from the back. - const LOOKUP_LIMIT = 15; - let i = claimedRewards.length; - const stopIndex = i > LOOKUP_LIMIT ? i - LOOKUP_LIMIT : 0; - - while (--i >= stopIndex) { - if (claimedRewards[i].reward_type === REWARDS.TYPE_WEEKLY_WATCH) { - const last = new Date(claimedRewards[i].updated_at || claimedRewards[i].created_at); - const diff = new Date() - last; - const diffDays = Math.ceil(diff / (1000 * 60 * 60 * 24)); - return diffDays < 6; - } +export const selectWeeklyWatchClaimedThisWeek = createSelector(selectUnclaimedRewards, (unclaimedRewards) => { + const weeklyWatch = unclaimedRewards.find((x) => x.reward_type === REWARDS.TYPE_WEEKLY_WATCH); + if (weeklyWatch && weeklyWatch.data && weeklyWatch.data.last_claimed) { + const last = new Date(weeklyWatch.data.last_claimed); + const diff = new Date() - last; + const diffDays = Math.ceil(diff / (1000 * 60 * 60 * 24)); + return diffDays < 6; } return false; });