From a04ab09ed611b4ea259c5117b0f368d1e7624f6f Mon Sep 17 00:00:00 2001 From: Manuel Wiedenmann Date: Sun, 15 Apr 2018 20:49:17 +0200 Subject: [PATCH] Move event handler assignment into method --- app/routes/application.js | 5 ++++- app/services/kredits.js | 41 +++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app/routes/application.js b/app/routes/application.js index 8a6a815..f136ff8 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -19,6 +19,9 @@ export default Route.extend({ }, afterModel() { - return this.get('kredits').loadContributorsAndProposals(); + return this.get('kredits').loadContributorsAndProposals() + .then(() => { + this.get('kredits').addContractEventHandlers(); + }); } }); diff --git a/app/services/kredits.js b/app/services/kredits.js index 5100470..470c1ff 100644 --- a/app/services/kredits.js +++ b/app/services/kredits.js @@ -88,35 +88,34 @@ export default Service.extend({ }).then(({ contributors, proposals }) => { this.set('contributors', contributors); this.set('proposals', proposals); - }).then(() => { - this.get('kredits').Operator - .on('ProposalCreated', (proposalId) => { - this.handleProposalCreated(proposalId); - }) - .on('ProposalVoted', (proposalId, voter, totalVotes) => { - this.handleProposalVoted(proposalId, totalVotes); - }) - .on('ProposalExecuted', (proposalId, contributorId, amount) => { - this.handleProposalExecuted(proposalId, contributorId, amount); - }); - - this.get('kredits').Token - .on('Transfer', (from, to, value) => { - this.handleTransfer(from, to, value); - }); }); }, + addContractEventHandlers() { + // Operator events + this.get('kredits').Operator + .on('ProposalCreated', (proposalId) => { + this.handleProposalCreated(proposalId); + }) + .on('ProposalVoted', (proposalId, voter, totalVotes) => { + this.handleProposalVoted(proposalId, totalVotes); + }) + .on('ProposalExecuted', (proposalId, contributorId, amount) => { + this.handleProposalExecuted(proposalId, contributorId, amount); + }); + + // Token events + this.get('kredits').Token + .on('Transfer', (from, to, value) => { + this.handleTransfer(from, to, value); + }); + }, + // TODO: Only assign valid attributes buildModel(name, attributes) { debug('[kredits] build', name, attributes); let model = getOwner(this).lookup(`model:${name}`); - // coerce id to string - if (attributes.id) { - attributes.id = attributes.id.toString(); - } - model.setProperties(attributes); return model; },