Refactor adding new contributions from events

Fixes contributions not being added when not already in memory (from
creation). Simplifies the entire function.
This commit is contained in:
Râu Cao
2022-11-11 20:28:26 +01:00
parent 0f8d7d84ca
commit 11f19c8344
+7 -7
View File
@@ -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) {