Skip to content

Commit

Permalink
fix: Optimize Fetch calls using extensions - MEED-7288
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker authored and AzmiTouil committed Jul 18, 2024
1 parent 9eee800 commit 780f334
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ import {getRewardReportPeriods} from './js/service';
export function init() {
extensionRegistry.registerExtension('engagementCenterAchievements', 'achievements-extensions', {
type: 'wallet',
rewardPeriods: [],
init(from, to) {
getRewardReportPeriods(from, to, 0, -1).then(period => {
this.rewardPeriods = period;
});
},
computedCanUpdateStatus: {},
canUpdateStatus(createdDate) {
return this.rewardPeriods.filter(rewardPeriod => this.isInPeriod(rewardPeriod, createdDate)).length === 0;
if (createdDate in this.computedCanUpdateStatus) {
return this.computedCanUpdateStatus[createdDate];
} else {
this.computedCanUpdateStatus[createdDate] = getRewardReportPeriods(from, to, 0, -1)
.then(period => {
this.computedCanUpdateStatus[createdDate] = period.filter(rewardPeriod => this.isInPeriod(rewardPeriod, createdDate)).length === 0;
return this.computedCanUpdateStatus[createdDate];
});
return this.computedCanUpdateStatus[createdDate];
}
},
isInPeriod(period, timestamp) {
return timestamp >= period?.startDateInSeconds && timestamp <= period?.endDateInSeconds;
Expand Down

0 comments on commit 780f334

Please sign in to comment.