WIP reimbursement sync
This commit is contained in:
+14
-9
@@ -1,13 +1,18 @@
|
|||||||
import Route from '@ember/routing/route';
|
import Route from '@ember/routing/route';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
|
import { isEmpty, isPresent } from '@ember/utils';
|
||||||
|
import { schedule } from '@ember/runloop';
|
||||||
|
|
||||||
export default class BudgetRoute extends Route {
|
export default class BudgetRoute extends Route {
|
||||||
|
|
||||||
@service browserCache;
|
@service browserCache;
|
||||||
@service kredits;
|
@service kredits;
|
||||||
|
|
||||||
async model () {
|
async model () {
|
||||||
if (this.kredits.reimbursements.length > 0) return;
|
if (isPresent(this.kredits.reimbursements) &&
|
||||||
|
isEmpty(this.kredits.reimbursementsPending)) {
|
||||||
|
// reimbursements loaded before, no need to sync or load
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const numCachedReimbursements = await this.browserCache.reimbursements.length();
|
const numCachedReimbursements = await this.browserCache.reimbursements.length();
|
||||||
if (numCachedReimbursements > 0) {
|
if (numCachedReimbursements > 0) {
|
||||||
@@ -18,11 +23,11 @@ export default class BudgetRoute extends Route {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// afterModel() {
|
afterModel() {
|
||||||
// if (this.kredits.reimbursementsNeedSync) {
|
// TODO implement syncReimbursements
|
||||||
// schedule('afterRender', this.kredits.syncReimbursements,
|
// if (this.kredits.reimbursementsNeedSync) {
|
||||||
// this.kredits.syncReimbursements.perform);
|
// schedule('afterRender', this.kredits.syncReimbursements,
|
||||||
// }
|
// this.kredits.syncReimbursements.perform);
|
||||||
// }
|
// }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -214,6 +214,10 @@ export default Service.extend({
|
|||||||
.filter(r => r.confirmedAt <= this.currentBlock);
|
.filter(r => r.confirmedAt <= this.currentBlock);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
reimbursementsPending: computed('reimbursements.[]', 'pendingTx', function() {
|
||||||
|
return this.reimbursements.filter(r => !r.id);
|
||||||
|
}),
|
||||||
|
|
||||||
async loadInitialData () {
|
async loadInitialData () {
|
||||||
const numCachedContributors = await this.browserCache.contributors.length();
|
const numCachedContributors = await this.browserCache.contributors.length();
|
||||||
if (numCachedContributors > 0) {
|
if (numCachedContributors > 0) {
|
||||||
@@ -676,9 +680,8 @@ export default Service.extend({
|
|||||||
async handleReimbursementAdded (id, addedByAccount, amount) {
|
async handleReimbursementAdded (id, addedByAccount, amount) {
|
||||||
console.debug('[kredits] ReimbursementAdded event received', { id, addedByAccount, amount });
|
console.debug('[kredits] ReimbursementAdded event received', { id, addedByAccount, amount });
|
||||||
|
|
||||||
const pendingReimbursement = this.reimbursements.find(r => {
|
const pendingReimbursement = this.reimbursementsPending.find(r => {
|
||||||
return (r.id === null) &&
|
return (this.currentUserAccounts.includes(addedByAccount)) &&
|
||||||
(this.currentUserAccounts.includes(addedByAccount)) &&
|
|
||||||
(r.amount.toString() === amount.toString());
|
(r.amount.toString() === amount.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user