Handle bignumber conversions
The kredits module always returns raw data from the contract. For uint values these are bignumbers. To handle those in the ember app we need to convert them to string or to number.
This commit is contained in:
@@ -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'),
|
||||
@@ -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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
|
||||
@@ -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]();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user