Move event handler assignment into method
This commit is contained in:
@@ -19,6 +19,9 @@ export default Route.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
afterModel() {
|
afterModel() {
|
||||||
return this.get('kredits').loadContributorsAndProposals();
|
return this.get('kredits').loadContributorsAndProposals()
|
||||||
|
.then(() => {
|
||||||
|
this.get('kredits').addContractEventHandlers();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+20
-21
@@ -88,35 +88,34 @@ export default Service.extend({
|
|||||||
}).then(({ contributors, proposals }) => {
|
}).then(({ contributors, proposals }) => {
|
||||||
this.set('contributors', contributors);
|
this.set('contributors', contributors);
|
||||||
this.set('proposals', proposals);
|
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
|
// TODO: Only assign valid attributes
|
||||||
buildModel(name, attributes) {
|
buildModel(name, attributes) {
|
||||||
debug('[kredits] build', name, attributes);
|
debug('[kredits] build', name, attributes);
|
||||||
let model = getOwner(this).lookup(`model:${name}`);
|
let model = getOwner(this).lookup(`model:${name}`);
|
||||||
|
|
||||||
// coerce id to string
|
|
||||||
if (attributes.id) {
|
|
||||||
attributes.id = attributes.id.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
model.setProperties(attributes);
|
model.setProperties(attributes);
|
||||||
return model;
|
return model;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user