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:
@@ -305,11 +305,11 @@ export default Service.extend({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
addContribution (attributes) {
|
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 => {
|
.then(data => {
|
||||||
console.debug('[kredits] add contribution response', data);
|
console.debug('[kredits] Contribution.add response', data);
|
||||||
attributes.contributor = this.contributors.findBy('id', attributes.contributorId);
|
attributes.contributor = this.contributors.findBy('id', attributes.contributorId);
|
||||||
const contribution = Contribution.create(attributes);
|
const contribution = Contribution.create(attributes);
|
||||||
contribution.set('pendingTx', data);
|
contribution.set('pendingTx', data);
|
||||||
@@ -667,12 +667,12 @@ export default Service.extend({
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (pendingContribution) {
|
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);
|
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) {
|
handleContributionVetoed (contributionId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user