Merge pull request #108 from 67P/feature/kredits-formatter
Add kredits-formatter and additionally format balance
This commit is contained in:
commit
f59c37827a
@ -1,5 +1,6 @@
|
||||
const Record = require('./record');
|
||||
const ContributorSerializer = require('../serializers/contributor');
|
||||
const formatKredits = require('../utils/format-kredits');
|
||||
|
||||
class Contributor extends Record {
|
||||
get count () {
|
||||
@ -8,9 +9,10 @@ class Contributor extends Record {
|
||||
|
||||
getById(id) {
|
||||
return this.functions.getContributorById(id)
|
||||
.then((data) => {
|
||||
.then(data => {
|
||||
data.balanceInt = formatKredits(data.balance);
|
||||
return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize);
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
filterByAccount(search) {
|
||||
|
10
lib/utils/format-kredits.js
Normal file
10
lib/utils/format-kredits.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);
|
||||
}
|
||||
}
|
@ -28,7 +28,7 @@ module.exports = async function(callback) {
|
||||
c.account,
|
||||
`${c.name}`,
|
||||
c.isCore,
|
||||
ethers.utils.formatEther(c.balance),
|
||||
c.balanceInt.toString(),
|
||||
c.totalKreditsEarned.toString(),
|
||||
c.contributionsCount.toString(),
|
||||
c.ipfsHash
|
||||
|
Loading…
x
Reference in New Issue
Block a user