Files
kredits-web/app/utils/cps/kredits.js
T
bumi 2aae2a8f90 Fix kredits balance handling
Kredits are stored on the Token contract as uint256 / bignumbers with 18
decimal points. Just like Ether and required by the ERC20 standard.
So we need to work with bignumbers and format a bignumber value here.
2019-04-19 11:37:18 +02:00

26 lines
715 B
JavaScript

import { computed } from '@ember/object';
import ethers from 'npm:ethers';
//import formatKredits from 'kredits-web/utils/format-kredits.js';
function formatKredits(value, options) {
let etherValue = ethers.utils.formatEther(value);
if (!options.decimals) {
etherValue = parseInt(etherValue).toString();
}
return etherValue;
}
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);
}
});
}