Fixes and cleanup

This commit is contained in:
2018-04-15 21:33:37 +02:00
parent a04ab09ed6
commit 3839eb2be4
+17 -24
View File
@@ -86,31 +86,11 @@ export default Service.extend({
contributors: this.getContributors(), contributors: this.getContributors(),
proposals: this.getProposals(), proposals: this.getProposals(),
}).then(({ contributors, proposals }) => { }).then(({ contributors, proposals }) => {
this.set('contributors', contributors); this.get('contributors').pushObjects(contributors);
this.set('proposals', proposals); this.get('proposals').pushObjects(proposals);
}); });
}, },
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);
@@ -191,6 +171,18 @@ export default Service.extend({
}, },
// Contract events // Contract events
addContractEventHandlers() {
// Operator events
this.get('kredits').Operator
.on('ProposalCreated', this.handleProposalCreated.bind(this))
.on('ProposalVoted', this.handleProposalVoted.bind(this))
.on('ProposalExecuted', this.handleProposalExecuted.bind(this));
// Token events
this.get('kredits').Token
.on('Transfer', this.handleTransfer.bind(this));
},
handleProposalCreated(proposalId) { handleProposalCreated(proposalId) {
let proposal = this.findProposalById(proposalId); let proposal = this.findProposalById(proposalId);
@@ -201,12 +193,13 @@ export default Service.extend({
this.get('kredits').Operator.getById(proposalId) this.get('kredits').Operator.getById(proposalId)
.then((proposal) => { .then((proposal) => {
proposal = this.buildModel('proposal', proposal);
this.get('proposals').pushObject(proposal); this.get('proposals').pushObject(proposal);
}); });
}, },
// TODO: We may want to reload that proposal to show the voter as voted // TODO: We may want to reload that proposal to show the voter as voted
handleProposalVoted(proposalId, totalVotes) { handleProposalVoted(proposalId, voterId, totalVotes) {
let proposal = this.findProposalById(proposalId); let proposal = this.findProposalById(proposalId);
if (proposal) { if (proposal) {
@@ -226,7 +219,7 @@ export default Service.extend({
this.get('contributors') this.get('contributors')
.findBy('id', contributorId.toString()) .findBy('id', contributorId.toString())
.incrementProperty('balance', amount); .incrementProperty('balance', amount.toNumber());
}, },
handleTransfer(from, to, value) { handleTransfer(from, to, value) {