Move contract event handling into service #51

Merged
fsmanuel merged 4 commits from feature/contract-events into master 2018-04-15 19:58:24 +00:00
2 changed files with 24 additions and 22 deletions
Showing only changes of commit a04ab09ed6 - Show all commits
+4 -1
View File
@@ -19,6 +19,9 @@ export default Route.extend({
},
afterModel() {
return this.get('kredits').loadContributorsAndProposals();
return this.get('kredits').loadContributorsAndProposals()
.then(() => {
this.get('kredits').addContractEventHandlers();
});
}
});
+20 -21
View File
@@ -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;
},