|
1 | 1 | /* eslint-disable no-tabs */
|
2 |
| -import { Meteor } from 'meteor/meteor'; |
3 |
| -import numbro from 'numbro'; |
4 |
| -import Big from 'big.js'; |
| 2 | +import { Meteor } from "meteor/meteor"; |
| 3 | +import numbro from "numbro"; |
| 4 | +import Big from "big.js"; |
5 | 5 |
|
6 |
| -Big.PE = 21 |
7 |
| -Big.NE = -21 |
8 |
| -Big.RM = Big.roundDown |
| 6 | +// disable scientific notation usage |
| 7 | +Big.NE = -1e6; |
| 8 | +Big.PE = +1e6; |
| 9 | + |
| 10 | +Big.RM = Big.roundDown; |
9 | 11 |
|
10 | 12 | const coinList = Meteor.settings.public.coins;
|
11 | 13 |
|
12 | 14 | export default class Coin {
|
13 |
| - static StakingCoin = coinList.find(coin => coin.denom === Meteor.settings.public.bondDenom); |
14 |
| - |
15 |
| - constructor(amount, denom = Meteor.settings.public.bondDenom) { |
16 |
| - const lowerDenom = denom.toLowerCase(); |
17 |
| - this._coin = coinList.find(coin => |
18 |
| - coin.denom.toLowerCase() === lowerDenom || coin.displayName.toLowerCase() === lowerDenom |
19 |
| - ); |
| 15 | + static StakingCoin = coinList.find( |
| 16 | + (coin) => coin.denom === Meteor.settings.public.bondDenom |
| 17 | + ); |
20 | 18 |
|
21 |
| - if (!this._coin) { |
22 |
| - this._coin = { |
23 |
| - "denom": denom, |
24 |
| - "displayName": denom, |
25 |
| - "fraction": 1, |
26 |
| - }; |
27 |
| - } |
| 19 | + constructor(amount, denom = Meteor.settings.public.bondDenom) { |
| 20 | + const lowerDenom = denom.toLowerCase(); |
| 21 | + this._coin = coinList.find( |
| 22 | + (coin) => |
| 23 | + coin.denom.toLowerCase() === lowerDenom || |
| 24 | + coin.displayName.toLowerCase() === lowerDenom |
| 25 | + ); |
28 | 26 |
|
29 |
| - // denom => afet |
30 |
| - // displayName => FET |
| 27 | + if (!this._coin) { |
| 28 | + this._coin = { |
| 29 | + denom: denom, |
| 30 | + displayName: denom, |
| 31 | + fraction: 1, |
| 32 | + }; |
| 33 | + } |
31 | 34 |
|
32 |
| - // divider used to convert between denom or displayName representation |
33 |
| - this._coin.fraction = Big(this._coin.fraction) |
34 |
| - // threshold used to switch display of a coin between its denom or displayName representations. |
35 |
| - this._fractionDisplayThreshold = this._coin.fraction.div(Big(1000000)); |
| 35 | + // denom => afet |
| 36 | + // displayName => FET |
36 | 37 |
|
37 |
| - if (!amount) { |
38 |
| - amount = 0; |
39 |
| - } |
| 38 | + // divider used to convert between denom or displayName representation |
| 39 | + this._coin.fraction = Big(this._coin.fraction); |
| 40 | + // threshold used to switch display of a coin between its denom or displayName representations. |
| 41 | + this._fractionDisplayThreshold = this._coin.fraction.div(Big(1000000)); |
40 | 42 |
|
41 |
| - if (lowerDenom === this._coin.denom.toLowerCase()) { |
42 |
| - this._amount = Big(amount); |
43 |
| - } else { |
44 |
| - this._amount = Big(amount).mul(this._coin.fraction); |
45 |
| - } |
| 43 | + if (!amount) { |
| 44 | + amount = 0; |
46 | 45 | }
|
47 | 46 |
|
48 |
| - get amount() { |
49 |
| - return this._amount |
| 47 | + if (lowerDenom === this._coin.denom.toLowerCase()) { |
| 48 | + this._amount = Big(amount); |
| 49 | + } else { |
| 50 | + this._amount = Big(amount).mul(this._coin.fraction); |
50 | 51 | }
|
| 52 | + } |
51 | 53 |
|
52 |
| - toString() { |
53 |
| - let amount = this._amount; |
54 |
| - let denom = this._coin.denom; |
55 |
| - // when amount is below this threshold, denom value will be used |
56 |
| - // when above, it will be converted to displayName. |
57 |
| - if (this._amount.gt(this._fractionDisplayThreshold)) { |
58 |
| - amount = amount.div(this._coin.fraction); |
59 |
| - denom = this._coin.displayName; |
60 |
| - } |
| 54 | + get amount() { |
| 55 | + return this._amount; |
| 56 | + } |
| 57 | + |
| 58 | + toString() { |
| 59 | + let amount = this._amount; |
| 60 | + let denom = this._coin.denom; |
| 61 | + // when amount is below this threshold, denom value will be used |
| 62 | + // when above, it will be converted to displayName. |
| 63 | + if (this._amount.gt(this._fractionDisplayThreshold)) { |
| 64 | + amount = amount.div(this._coin.fraction); |
| 65 | + denom = this._coin.displayName; |
| 66 | + } |
61 | 67 |
|
62 |
| - let format = '0,0.000000' |
63 |
| - // removes unecessary decimals |
64 |
| - if (amount.eq(amount.round(0, Big.roundDown))) { |
65 |
| - format = '0,0' |
66 |
| - } |
67 |
| - return `${numbro(amount.toString()).format(format)} ${denom}` |
| 68 | + let format = "0,0.000000"; |
| 69 | + // removes unecessary decimals |
| 70 | + if (amount.eq(amount.round(0, Big.roundDown))) { |
| 71 | + format = "0,0"; |
68 | 72 | }
|
| 73 | + return `${numbro(amount.toString()).format(format)} ${denom}`; |
| 74 | + } |
69 | 75 | }
|
0 commit comments