diff --git a/app/routes/application.js b/app/routes/application.js index f5ecd51..3aec684 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -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); + } }); } }); diff --git a/app/services/kredits.js b/app/services/kredits.js index c0b5117..559afd3 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -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 } }); }