From 11f19c8344e994409db09ee50cc3d97d6774dfbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A2u=20Cao?= Date: Fri, 11 Nov 2022 20:28:26 +0100 Subject: [PATCH] Refactor adding new contributions from events Fixes contributions not being added when not already in memory (from creation). Simplifies the entire function. --- app/services/kredits.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/services/kredits.js b/app/services/kredits.js index a069a7d..3a4366a 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -305,11 +305,11 @@ export default Service.extend({ }), addContribution (attributes) { - console.debug('[kredits] add contribution', attributes); + console.debug('[kredits] Adding contribution', attributes); - return this.kredits.Contribution.addContribution(attributes, { gasLimit: 300000 }) + return this.kredits.Contribution.add(attributes, { gasLimit: 300000 }) .then(data => { - console.debug('[kredits] add contribution response', data); + console.debug('[kredits] Contribution.add response', data); attributes.contributor = this.contributors.findBy('id', attributes.contributorId); const contribution = Contribution.create(attributes); contribution.set('pendingTx', data); @@ -667,12 +667,12 @@ export default Service.extend({ }); if (pendingContribution) { - const attributes = await this.kredits.Contribution.getById(id); - attributes.contributor = this.contributors.findBy('id', attributes.contributorId); - const newContribution = Contribution.create(attributes); - this.contributions.addObject(newContribution); this.contributions.removeObject(pendingContribution); } + + const data = await this.kredits.Contribution.getById(id); + const c = this.loadContributionFromData(data); + await this.browserCache.contributions.setItem(c.id.toString(), c.serialize()); }, handleContributionVetoed (contributionId) {