Use getProposalById instead of buildModel

This commit is contained in:
2018-04-08 14:33:38 +02:00
parent 28f7466595
commit f54a36f240
2 changed files with 13 additions and 17 deletions
+9 -17
View File
@@ -29,9 +29,8 @@ export default Controller.extend({
.map((proposal) => { .map((proposal) => {
let contributor = this.get('contributors') let contributor = this.get('contributors')
.findBy('id', proposal.get('recipientId')); .findBy('id', proposal.get('recipientId'));
if (contributor) {
proposal.set('contributor', contributor); proposal.set('contributor', contributor);
}
return proposal; return proposal;
}); });
@@ -51,15 +50,7 @@ export default Controller.extend({
return; return;
} }
// TODO: we should remove votesNeeded proposal = this.get('kredits').getProposalById(proposalId);
proposal = this.get('kredits').buildModel('proposal', {
id: proposalId,
creatorAddress: creatorAddress,
recipientId: recipientId.toString(),
votesNeeded: 2,
amount: amount.toNumber(),
});
this.get('proposals').pushObject(proposal); this.get('proposals').pushObject(proposal);
}, },
@@ -88,13 +79,14 @@ export default Controller.extend({
.setProperties({ 'votesCount': totalVotes }); .setProperties({ 'votesCount': totalVotes });
}, },
_handleTransfer(data) { _handleTransfer(from, to, value) {
value = value.toNumber();
this.get('contributors') this.get('contributors')
.findBy('address', data.args.from) .findBy('address', from)
.incrementProperty('balance', - data.args.value.toNumber()); .decrementProperty('balance', value);
this.get('contributors') this.get('contributors')
.findBy('address', data.args.to) .findBy('address', to)
.incrementProperty('balance', data.args.value.toNumber()); .incrementProperty('balance', value);
}, },
+4
View File
@@ -123,6 +123,8 @@ export default Service.extend({
}, },
getContributorById(id) { getContributorById(id) {
id = ethers.utils.bigNumberify(id);
return this.get('contributorsContract') return this.get('contributorsContract')
.then((contract) => contract.getContributorById(id)) .then((contract) => contract.getContributorById(id))
.then(this.reassembleIpfsHash) .then(this.reassembleIpfsHash)
@@ -199,6 +201,8 @@ export default Service.extend({
}, },
getProposalById(id) { getProposalById(id) {
id = ethers.utils.bigNumberify(id);
return this.get('kreditsContract') return this.get('kreditsContract')
.then((contract) => contract.proposals(id)) .then((contract) => contract.proposals(id))
.then(this.reassembleIpfsHash) .then(this.reassembleIpfsHash)