Only sync contributions if loaded from cache

This commit is contained in:
2020-05-29 20:55:19 +02:00
parent 63dd5430bc
commit c54d754c89
2 changed files with 11 additions and 5 deletions
+5 -3
View File
@@ -24,12 +24,14 @@ export default Route.extend({
this.kredits.addContractEventHandlers();
})
.then(() => {
if (this.kredits.contributorsNeedFetch) {
if (this.kredits.contributorsNeedSync) {
schedule('afterRender', this.kredits.syncContributors,
this.kredits.syncContributors.perform);
}
schedule('afterRender', this.kredits.syncContributions,
this.kredits.syncContributions.perform);
if (this.kredits.contributionsNeedSync) {
schedule('afterRender', this.kredits.syncContributions,
this.kredits.syncContributions.perform);
}
});
}
});
+6 -2
View File
@@ -22,7 +22,6 @@ import Contribution from 'kredits-web/models/contribution'
export default Service.extend({
browserCache: service(),
contributorsNeedFetch: false,
currentBlock: null,
currentUserAccounts: null, // default to not having an account. this is the wen web3 is loaded.
@@ -35,6 +34,10 @@ export default Service.extend({
currentUserIsCore: alias('currentUser.isCore'),
hasAccounts: notEmpty('currentUserAccounts'),
// When data was loaded from cache, we need to fetch updates from the network
contributorsNeedSync: false,
contributionsNeedSync: false,
contributionsUnconfirmed: computed('contributions.[]', 'currentBlock', function() {
return this.contributions.filter(contribution => {
return contribution.confirmedAt > this.currentBlock;
@@ -180,7 +183,7 @@ export default Service.extend({
const numCachedContributors = await this.browserCache.contributors.length();
if (numCachedContributors > 0) {
await this.loadContributorsFromCache();
this.set('contributorsNeedFetch', true);
this.set('contributorsNeedSync', true);
} else {
await this.fetchContributors();
}
@@ -188,6 +191,7 @@ export default Service.extend({
const numCachedContributions = await this.browserCache.contributions.length();
if (numCachedContributions > 0) {
await this.loadContributionsFromCache();
this.set('contributionsNeedSync', true);
} else {
await this.fetchContributions({ page: { size: 30 } });
}