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