Only sync contributions if loaded from cache
This commit is contained in:
@@ -24,12 +24,14 @@ export default Route.extend({
|
|||||||
this.kredits.addContractEventHandlers();
|
this.kredits.addContractEventHandlers();
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (this.kredits.contributorsNeedFetch) {
|
if (this.kredits.contributorsNeedSync) {
|
||||||
schedule('afterRender', this.kredits.syncContributors,
|
schedule('afterRender', this.kredits.syncContributors,
|
||||||
this.kredits.syncContributors.perform);
|
this.kredits.syncContributors.perform);
|
||||||
}
|
}
|
||||||
schedule('afterRender', this.kredits.syncContributions,
|
if (this.kredits.contributionsNeedSync) {
|
||||||
this.kredits.syncContributions.perform);
|
schedule('afterRender', this.kredits.syncContributions,
|
||||||
|
this.kredits.syncContributions.perform);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import Contribution from 'kredits-web/models/contribution'
|
|||||||
export default Service.extend({
|
export default Service.extend({
|
||||||
|
|
||||||
browserCache: service(),
|
browserCache: service(),
|
||||||
contributorsNeedFetch: false,
|
|
||||||
|
|
||||||
currentBlock: null,
|
currentBlock: null,
|
||||||
currentUserAccounts: null, // default to not having an account. this is the wen web3 is loaded.
|
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'),
|
currentUserIsCore: alias('currentUser.isCore'),
|
||||||
hasAccounts: notEmpty('currentUserAccounts'),
|
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() {
|
contributionsUnconfirmed: computed('contributions.[]', 'currentBlock', function() {
|
||||||
return this.contributions.filter(contribution => {
|
return this.contributions.filter(contribution => {
|
||||||
return contribution.confirmedAt > this.currentBlock;
|
return contribution.confirmedAt > this.currentBlock;
|
||||||
@@ -180,7 +183,7 @@ export default Service.extend({
|
|||||||
const numCachedContributors = await this.browserCache.contributors.length();
|
const numCachedContributors = await this.browserCache.contributors.length();
|
||||||
if (numCachedContributors > 0) {
|
if (numCachedContributors > 0) {
|
||||||
await this.loadContributorsFromCache();
|
await this.loadContributorsFromCache();
|
||||||
this.set('contributorsNeedFetch', true);
|
this.set('contributorsNeedSync', true);
|
||||||
} else {
|
} else {
|
||||||
await this.fetchContributors();
|
await this.fetchContributors();
|
||||||
}
|
}
|
||||||
@@ -188,6 +191,7 @@ export default Service.extend({
|
|||||||
const numCachedContributions = await this.browserCache.contributions.length();
|
const numCachedContributions = await this.browserCache.contributions.length();
|
||||||
if (numCachedContributions > 0) {
|
if (numCachedContributions > 0) {
|
||||||
await this.loadContributionsFromCache();
|
await this.loadContributionsFromCache();
|
||||||
|
this.set('contributionsNeedSync', true);
|
||||||
} else {
|
} else {
|
||||||
await this.fetchContributions({ page: { size: 30 } });
|
await this.fetchContributions({ page: { size: 30 } });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user