Fix kredits balance handling #104

Merged
bumi merged 3 commits from feature/handle-kredits-balances into master 2019-04-19 13:44:36 +00:00
5 changed files with 34 additions and 3 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ export default Controller.extend({
contributors: alias('kredits.contributors'),
contributorsWithKredits: filter('contributors', function(contributor) {
return contributor.get('balance') !== 0;
return contributor.get('balanceRaw').gt(0);
}),
contributorsSorting: Object.freeze(['balance:desc']),
contributorsSorted: sort('contributorsWithKredits', 'contributorsSorting'),
+2 -1
View File
@@ -1,12 +1,13 @@
import { computed } from '@ember/object';
import EmberObject from '@ember/object';
import bignumber from 'kredits-web/utils/cps/bignumber';
fsmanuel commented 2019-04-19 10:10:19 +00:00 (Migrated from github.com)
Review

No longer needed, right?

No longer needed, right?
fsmanuel commented 2019-04-19 10:22:56 +00:00 (Migrated from github.com)
Review

Ah sorry, we still need it for the id?!

Ah sorry, we still need it for the id?!
import kreditsValue from 'kredits-web/utils/cps/kredits';
export default EmberObject.extend({
// Contract
id: bignumber('idRaw', 'toString'),
account: null,
balance: bignumber('balanceRaw', 'toNumber'),
balance: kreditsValue('balanceRaw'),
isCore: false,
ipfsHash: null,
+5 -1
View File
@@ -7,6 +7,8 @@ import { computed } from '@ember/object';
import { alias, notEmpty } from '@ember/object/computed';
import { isEmpty } from '@ember/utils';
import formatKredits from 'kredits-web/utils/format-kredits';
import config from 'kredits-web/config/environment';
import Contributor from 'kredits-web/models/contributor'
import Proposal from 'kredits-web/models/proposal'
@@ -109,7 +111,9 @@ export default Service.extend({
},
fsmanuel commented 2019-04-19 10:09:53 +00:00 (Migrated from github.com)
Review

No need for Promise.resolve: return formatKredits(total);

No need for `Promise.resolve`: `return formatKredits(total);`
totalSupply: computed(function() {
return this.kredits.Token.functions.totalSupply();
return this.kredits.Token.functions.totalSupply().then(total => {
return formatKredits(total);
})
}),
loadInitialData() {
+17
View File
@@ -0,0 +1,17 @@
import { computed } from '@ember/object';
bumi commented 2019-04-19 09:48:17 +00:00 (Migrated from github.com)
Review

how do I do that import here? somehow I did not get this working.

how do I do that import here? somehow I did not get this working.
fsmanuel commented 2019-04-19 10:08:31 +00:00 (Migrated from github.com)
Review

Without .js or a relative import: import formatKredits from '../format-kredits';

Without `.js` or a relative import: `import formatKredits from '../format-kredits';`
bumi commented 2019-04-19 13:43:40 +00:00 (Migrated from github.com)
Review

ahhh, probably the only option that I did not try...thx.

ahhh, probably the only option that I did not try...thx.
import ethers from 'npm:ethers';
import formatKredits from 'kredits-web/utils/format-kredits';
export default function(dependentKey, options = {}) {
return computed(dependentKey, {
get () {
const value = this.get(dependentKey);
return formatKredits(value, options);
},
set (key, value) {
const bnValue = ethers.utils.bigNumberify(value);
this.set(dependentKey, bnValue);
return formatKredits(bnValue, options);
}
});
}
+9
View File
@@ -0,0 +1,9 @@
import ethers from 'npm:ethers';
export default function(value, options = {}) {
let etherValue = ethers.utils.formatEther(value);
if (!options.decimals) {
etherValue = parseInt(etherValue).toString();
}
return etherValue;
}