Replace weekly watch search loop with new last_claimed
This commit is contained in:
parent
283ea69a6e
commit
c04023948b
1 changed files with 7 additions and 17 deletions
|
@ -71,23 +71,13 @@ export const selectHasClaimedInitialRewards = createSelector(selectClaimedReward
|
||||||
return newUserClaimed && confirmEmailClaimed;
|
return newUserClaimed && confirmEmailClaimed;
|
||||||
});
|
});
|
||||||
|
|
||||||
export const selectWeeklyWatchClaimedThisWeek = createSelector(selectClaimedRewardsById, (claimedRewardsById) => {
|
export const selectWeeklyWatchClaimedThisWeek = createSelector(selectUnclaimedRewards, (unclaimedRewards) => {
|
||||||
const claimedRewards = Object.values(claimedRewardsById);
|
const weeklyWatch = unclaimedRewards.find((x) => x.reward_type === REWARDS.TYPE_WEEKLY_WATCH);
|
||||||
|
if (weeklyWatch && weeklyWatch.data && weeklyWatch.data.last_claimed) {
|
||||||
// The list could be huge, so:
|
const last = new Date(weeklyWatch.data.last_claimed);
|
||||||
// - 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 diff = new Date() - last;
|
||||||
const diffDays = Math.ceil(diff / (1000 * 60 * 60 * 24));
|
const diffDays = Math.ceil(diff / (1000 * 60 * 60 * 24));
|
||||||
return diffDays < 6;
|
return diffDays < 6;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue