Add kredits-formatter and additionally format balance
This adds a `balanceInt` value to the contributor data that has the token balance formatted as full Kredits. (similar to Ether)
This commit is contained in:
parent
5820d71b2c
commit
3cb94fb660
@ -1,5 +1,6 @@
|
|||||||
const Record = require('./record');
|
const Record = require('./record');
|
||||||
const ContributorSerializer = require('../serializers/contributor');
|
const ContributorSerializer = require('../serializers/contributor');
|
||||||
|
const KreditsFormatter = require('../utils/kredits-formatter');
|
||||||
|
|
||||||
class Contributor extends Record {
|
class Contributor extends Record {
|
||||||
get count () {
|
get count () {
|
||||||
@ -8,9 +9,13 @@ class Contributor extends Record {
|
|||||||
|
|
||||||
getById(id) {
|
getById(id) {
|
||||||
return this.functions.getContributorById(id)
|
return this.functions.getContributorById(id)
|
||||||
.then((data) => {
|
.then(data => {
|
||||||
return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize);
|
return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize);
|
||||||
});
|
})
|
||||||
|
.then(data => {
|
||||||
|
data.balanceInt = KreditsFormatter(data.balance);
|
||||||
|
return Promise.resolve(data);
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
filterByAccount(search) {
|
filterByAccount(search) {
|
||||||
|
10
lib/utils/kredits-formatter.js
Normal file
10
lib/utils/kredits-formatter.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
const ethersUtils = require('ethers').utils;
|
||||||
|
|
||||||
|
module.exports = function (value, options = {}) {
|
||||||
|
let etherValue = ethersUtils.formatEther(value);
|
||||||
|
if (options.asFloat) {
|
||||||
|
return parseFloat(etherValue);
|
||||||
|
} else {
|
||||||
|
return parseInt(etherValue);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user