Skip to content

Commit cc47c1d

Browse files
committed
fix big toString converting to scientific notation
1 parent 025d1e0 commit cc47c1d

File tree

3 files changed

+64
-51
lines changed

3 files changed

+64
-51
lines changed

both/utils/coins.js

+57-51
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,75 @@
11
/* 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";
55

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;
911

1012
const coinList = Meteor.settings.public.coins;
1113

1214
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+
);
2018

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+
);
2826

29-
// denom => afet
30-
// displayName => FET
27+
if (!this._coin) {
28+
this._coin = {
29+
denom: denom,
30+
displayName: denom,
31+
fraction: 1,
32+
};
33+
}
3134

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
3637

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));
4042

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;
4645
}
4746

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);
5051
}
52+
}
5153

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+
}
6167

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";
6872
}
73+
return `${numbro(amount.toString()).format(format)} ${denom}`;
74+
}
6975
}

imports/ui/ledger/LedgerActions.jsx

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import TimeStamp from '../components/TimeStamp.jsx';
1515
import { PropTypes } from 'prop-types';
1616
import Big from 'big.js'
1717

18+
// disable scientific notation usage
19+
Big.NE = -1e+6
20+
Big.PE = +1e+6
21+
1822
const maxHeightModifier = {
1923
setMaxHeight: {
2024
enabled: true,

imports/ui/validators/List.jsx

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import TimeStamp from '../components/TimeStamp.jsx';
88
import SentryBoundary from '../components/SentryBoundary.jsx';
99
import Big from 'big.js';
1010

11+
// disable scientific notation usage
12+
Big.NE = -1e+6
13+
Big.PE = +1e+6
1114

1215
const ValidatorRow = (props) => {
1316
let moniker = (props.validator.description && props.validator.description.moniker) ? props.validator.description.moniker : props.validator.address;

0 commit comments

Comments
 (0)