diff --git a/app/services/kredits.js b/app/services/kredits.js index 58049ed..4610dc3 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -225,7 +225,6 @@ export default Service.extend({ console.debug('[kredits] add contribution response', data); attributes.contributor = this.contributors.findBy('id', attributes.contributorId); const contribution = Contribution.create(attributes); - // TODO receive from wrapper contribution.set('confirmedAtBlock', data.blockNumber + 40320); this.contributions.pushObject(contribution); return contribution; @@ -315,6 +314,7 @@ export default Service.extend({ .on('ContributorAdded', this.handleContributorChange.bind(this)) this.kredits.Contribution + .on('ContributionAdded', this.handleContributionAdded.bind(this)) .on('ContributionVetoed', this.handleContributionVetoed.bind(this)) this.kredits.Proposal @@ -342,6 +342,24 @@ export default Service.extend({ this.contributors.pushObject(newContributor); }, + async handleContributionAdded (id, contributorId, amount) { + console.debug('[kredits] ContributionAdded event received', { id, contributorId, amount }); + + const pendingContribution = this.contributions.find(c => { + return (c.id === null) && + (c.contributorId.toString() === contributorId.toString()) && + (c.amount.toString() === amount.toString()); + }); + + if (pendingContribution) { + const attributes = await this.kredits.Contribution.getById(id); + attributes.contributor = this.contributors.findBy('id', attributes.contributorId.toString()); + const newContribution = Contribution.create(attributes); + this.contributions.addObject(newContribution); + this.contributions.removeObject(pendingContribution); + } + }, + handleContributionVetoed (contributionId) { console.debug('[kredits] ContributionVetoed event received for ', contributionId); const contribution = this.contributions.findBy('id', contributionId);