Add kredits-formatter and additionally format balance #108
@ -1,5 +1,6 @@
|
|||||||
|
|||||||
const Record = require('./record');
|
const Record = require('./record');
|
||||||
const ContributorSerializer = require('../serializers/contributor');
|
const ContributorSerializer = require('../serializers/contributor');
|
||||||
|
const formatKredits = require('../utils/format-kredits');
|
||||||
![]() As this is not a class, but just one formatting function, I'd call the file As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
![]() I think the convention is a dash for filenames in JS. I think the convention is a dash for filenames in JS.
👍 `formatKredits()`
|
|||||||
|
|
||||||
class Contributor extends Record {
|
class Contributor extends Record {
|
||||||
get count () {
|
get count () {
|
||||||
@ -8,9 +9,10 @@ class Contributor extends Record {
|
|||||||
![]() As this is not a class, but just one formatting function, I'd call the file As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
![]() As this is not a class, but just one formatting function, I'd call the file As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
![]() I think the convention is a dash for filenames in JS. I think the convention is a dash for filenames in JS.
👍 `formatKredits()`
![]() I think the convention is a dash for filenames in JS. I think the convention is a dash for filenames in JS.
👍 `formatKredits()`
|
|||||||
|
|
||||||
getById(id) {
|
getById(id) {
|
||||||
return this.functions.getContributorById(id)
|
return this.functions.getContributorById(id)
|
||||||
.then((data) => {
|
.then(data => {
|
||||||
![]() As this is not a class, but just one formatting function, I'd call the file As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
![]() I think the convention is a dash for filenames in JS. I think the convention is a dash for filenames in JS.
👍 `formatKredits()`
![]() As this is not a class, but just one formatting function, I'd call the file As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
![]() I think the convention is a dash for filenames in JS. I think the convention is a dash for filenames in JS.
👍 `formatKredits()`
|
|||||||
|
data.balanceInt = formatKredits(data.balance);
|
||||||
![]() As this is not a class, but just one formatting function, I'd call the file As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
![]() I think the convention is a dash for filenames in JS. I think the convention is a dash for filenames in JS.
👍 `formatKredits()`
|
|||||||
return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize);
|
return this.ipfs.catAndMerge(data, ContributorSerializer.deserialize);
|
||||||
});
|
})
|
||||||
![]() As this is not a class, but just one formatting function, I'd call the file As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
![]() I think the convention is a dash for filenames in JS. I think the convention is a dash for filenames in JS.
👍 `formatKredits()`
![]() As this is not a class, but just one formatting function, I'd call the file As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
![]() I think the convention is a dash for filenames in JS. I think the convention is a dash for filenames in JS.
👍 `formatKredits()`
|
|||||||
}
|
}
|
||||||
|
|
||||||
filterByAccount(search) {
|
filterByAccount(search) {
|
||||||
|
|||||||
![]() As this is not a class, but just one formatting function, I'd call the file As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
![]() As this is not a class, but just one formatting function, I'd call the file As this is not a class, but just one formatting function, I'd call the file `format_kredits` and import it as `formatKredits()`.
![]() I think the convention is a dash for filenames in JS. I think the convention is a dash for filenames in JS.
👍 `formatKredits()`
![]() I think the convention is a dash for filenames in JS. I think the convention is a dash for filenames in JS.
👍 `formatKredits()`
|
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.account,
|
||||||
`${c.name}`,
|
`${c.name}`,
|
||||||
c.isCore,
|
c.isCore,
|
||||||
ethers.utils.formatEther(c.balance),
|
c.balanceInt.toString(),
|
||||||
c.totalKreditsEarned.toString(),
|
c.totalKreditsEarned.toString(),
|
||||||
c.contributionsCount.toString(),
|
c.contributionsCount.toString(),
|
||||||
c.ipfsHash
|
c.ipfsHash
|
||||||
|
As this is not a class, but just one formatting function, I'd call the file
format_kredits
and import it asformatKredits()
.As this is not a class, but just one formatting function, I'd call the file
format_kredits
and import it asformatKredits()
.I think the convention is a dash for filenames in JS.
👍
formatKredits()
I think the convention is a dash for filenames in JS.
👍
formatKredits()