From 8aa941e704bc2379ac60d3a1d4d979fad553fc26 Mon Sep 17 00:00:00 2001 From: bumi Date: Sun, 15 Apr 2018 19:02:35 +0200 Subject: [PATCH 1/2] Rename recipientId to contributorId in proposals --- app/components/add-proposal/component.js | 4 ++-- app/components/add-proposal/template.hbs | 4 ++-- app/controllers/index.js | 10 +++++----- app/controllers/proposals/new.js | 2 +- app/lib/kredits/contracts/operator.js | 2 +- app/models/proposal.js | 2 +- app/utils/cps/bignumber.js | 2 ++ 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/components/add-proposal/component.js b/app/components/add-proposal/component.js index aba9926..e7acf1a 100644 --- a/app/components/add-proposal/component.js +++ b/app/components/add-proposal/component.js @@ -8,7 +8,7 @@ export default Component.extend({ // Default attributes used by reset attributes: { - recipientId: null, + contributorId: null, kind: 'community', amount: null, description: null, @@ -22,7 +22,7 @@ export default Component.extend({ contributors: [], - isValidRecipient: isPresent('recipientId'), + isValidRecipient: isPresent('contributorId'), isValidAmount: computed('amount', function() { return parseInt(this.get('amount'), 10) > 0; }), diff --git a/app/components/add-proposal/template.hbs b/app/components/add-proposal/template.hbs index c7bb975..4f3cb9f 100644 --- a/app/components/add-proposal/template.hbs +++ b/app/components/add-proposal/template.hbs @@ -1,9 +1,9 @@

- {{#each contributors as |contributor|}} - + {{/each}}

diff --git a/app/controllers/index.js b/app/controllers/index.js index a82343a..1233651 100644 --- a/app/controllers/index.js +++ b/app/controllers/index.js @@ -26,7 +26,7 @@ export default Controller.extend({ return this.get('model.proposals') .map((proposal) => { let contributor = this.get('contributors') - .findBy('id', proposal.get('recipientId')); + .findBy('id', proposal.get('contributorId')); proposal.set('contributor', contributor); @@ -51,9 +51,9 @@ export default Controller.extend({ this.get('proposals').pushObject(proposal); }, - _handleProposalExecuted(proposalId, recipientId, amount) { + _handleProposalExecuted(proposalId, contributorId, amount) { let proposal = this.get('proposals') - .findBy('id', proposalId.toString()); + .findBy('id', proposalId); if (proposal.get('isExecuted')) { Ember.Logger.debug('[index] proposal already executed, not adding from event'); @@ -65,13 +65,13 @@ export default Controller.extend({ }); this.get('contributors') - .findBy('id', recipientId.toString()) + .findBy('id', contributorId) .incrementProperty('balance', amount); }, _handleProposalVoted(proposalId, voter, totalVotes) { this.get('proposals') - .findBy('id', proposalId.toString()) + .findBy('id', proposalId) .setProperties({ 'votesCount': totalVotes }); }, diff --git a/app/controllers/proposals/new.js b/app/controllers/proposals/new.js index dbea973..2b2f869 100644 --- a/app/controllers/proposals/new.js +++ b/app/controllers/proposals/new.js @@ -11,7 +11,7 @@ export default Controller.extend({ actions: { save(proposal) { // contributorIpfsHash is needed for the proposal ipfs data. I'm not happy to do this here but I think to load all the contributors in addProposal again is a bit too much. I hope we can refactor it later. - let contributor = this.get('contributors').findBy('id', proposal.recipientId); + let contributor = this.get('contributors').findBy('id', proposal.contributorId); proposal.contributorIpfsHash = contributor.get('ipfsHash'); return this.get('kredits').addProposal(proposal) diff --git a/app/lib/kredits/contracts/operator.js b/app/lib/kredits/contracts/operator.js index cd37573..accf785 100644 --- a/app/lib/kredits/contracts/operator.js +++ b/app/lib/kredits/contracts/operator.js @@ -39,7 +39,7 @@ export default class Operator extends Base { .add(json) .then((ipfsHashAttr) => { let proposal = [ - proposalAttr.recipientId, + proposalAttr.contributorId, proposalAttr.amount, ipfsHashAttr.ipfsHash, ipfsHashAttr.hashFunction, diff --git a/app/models/proposal.js b/app/models/proposal.js index b193414..4022ec4 100644 --- a/app/models/proposal.js +++ b/app/models/proposal.js @@ -6,7 +6,7 @@ export default EmberObject.extend({ // Contract id: bignumber('idRaw', 'toString'), creatorAccount: null, - recipientId: bignumber('recipientIdRaw', 'toString'), + contributorId: bignumber('contributorIdRaw', 'toString'), amount: bignumber('amountRaw', 'toNumber'), votesCount: bignumber('votesCountRaw', 'toNumber'), votesNeeded: bignumber('votesNeededRaw', 'toNumber'), diff --git a/app/utils/cps/bignumber.js b/app/utils/cps/bignumber.js index 701eed1..f86cab2 100644 --- a/app/utils/cps/bignumber.js +++ b/app/utils/cps/bignumber.js @@ -1,4 +1,5 @@ import computed from 'ember-computed'; +import ethers from 'npm:ethers'; export default function(dependentKey, converterMethod) { return computed(dependentKey, { @@ -6,6 +7,7 @@ export default function(dependentKey, converterMethod) { return this.get(dependentKey)[converterMethod](); }, set (key, value) { + value = ethers.utils.bigNumberify(value); this.set(dependentKey, value); return value[converterMethod](); } From 62e195d186880743b883768dc52092c2d333658d Mon Sep 17 00:00:00 2001 From: bumi Date: Sun, 15 Apr 2018 19:56:03 +0200 Subject: [PATCH 2/2] remove fake bignumber from tests We make everything bignumber-y now so that is no longer needed --- tests/unit/controllers/index-test.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/unit/controllers/index-test.js b/tests/unit/controllers/index-test.js index 0bce69e..76f11f1 100644 --- a/tests/unit/controllers/index-test.js +++ b/tests/unit/controllers/index-test.js @@ -23,9 +23,6 @@ let addFixtures = function(controller) { { github_username: "trinity", github_uid: "123", balance: 5000 }, { github_username: "mouse", github_uid: "696", balance: 0 } ].forEach(fixture => { - // we expect a bignumer but I don't want to add the bignumber dependency here... so this is some hack to return an object that looks good enough for the test - let fakeBignumber = function(balance) { return { toNumber: function() { return balance; } }; }; - fixture.balance = fakeBignumber(fixture.balance); controller.get('model.contributors').push(Contributor.create(fixture)); }); };