Refactor contract interaction in its own module #42

Merged
bumi merged 11 commits from kredits-module into master 2018-04-10 13:46:58 +00:00
4 changed files with 24 additions and 9 deletions
Showing only changes of commit 32846194b6 - Show all commits
+2 -2
View File
@@ -17,7 +17,7 @@ export default Controller.extend({
contributors: alias('model.contributors'),
contributorsWithKredits: filter('contributors', function(contributor) {
return contributor.get('balance').toString() !== "0";
return contributor.get('balance') !== 0;
}),
contributorsSorting: ['balance:desc'],
contributorsSorted: sort('contributorsWithKredits', 'contributorsSorting'),
1
@@ -68,7 +68,7 @@ export default Controller.extend({
this.get('contributors')
.findBy('id', recipientId.toString())
.incrementProperty('balance', amount.toNumber());
.incrementProperty('balance', amount);
},
_handleProposalVoted(proposalId, voter, totalVotes) {
+3 -2
View File
@@ -1,12 +1,13 @@
import computed from 'ember-computed';
import EmberObject from 'ember-object';
import bignumber from 'kredits-web/utils/cps/bignumber';
export default EmberObject.extend({
// Contract
id: null,
id: bignumber('idRaw', 'toString'),
// TODO: Should we rename it to account like in the contract?
address: null,
balance: 0,
balance: bignumber('balanceRaw', 'toNumber'),
isCore: false,
ipfsHash: null,
+6 -5
View File
@@ -1,14 +1,15 @@
import EmberObject from 'ember-object';
import { alias } from 'ember-computed';
import bignumber from 'kredits-web/utils/cps/bignumber';
export default EmberObject.extend({
// Contract
id: null,
id: bignumber('idRaw', 'toString'),
creatorAddress: null,
recipientId: null,
amount: null,
votesCount: null,
votesNeeded: null,
recipientId: bignumber('recipientIdRaw', 'toString'),
amount: bignumber('amountRaw', 'toNumber'),
votesCount: bignumber('votesCountRaw', 'toNumber'),
votesNeeded: bignumber('votesNeededRaw', 'toNumber'),
executed: null,
ipfsHash: null,
+13
View File
@@ -0,0 +1,13 @@
import computed from 'ember-computed';
export default function(dependentKey, converterMethod) {
return computed(dependentKey, {
get () {
return this.get(dependentKey)[converterMethod]();
},
set (key, value) {
this.set(dependentKey, value);
return value[converterMethod]();
}
});
}