Skip to content

Commit

Permalink
fix: cancel toFixed when format balances (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-ziv authored May 3, 2022
1 parent 87cc450 commit 2906e3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/__tests__/utils/wallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import utils from '../../utils';
const {formatBalance, shortenAddress, shortenBalance} = utils.wallet;

describe('formatBalance', () => {
it('should format balance to 5 digits precision', () => {
expect(formatBalance(1.222243232)).toEqual(1.22224);
expect(formatBalance(3000.232143123212)).toEqual(3000.23214);
expect(formatBalance(10.000000001)).toEqual(10);
it('should format balance as string', () => {
expect(formatBalance(1.222243232)).toEqual('1.222243232');
expect(formatBalance(3000.232143123212)).toEqual('3000.232143123212');
expect(formatBalance(10.000000001)).toEqual('10.000000001');
});

it('should handle exponential balances', () => {
Expand Down
6 changes: 1 addition & 5 deletions src/utils/wallet.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
export const formatBalance = balance => {
if (typeof balance === 'number') {
balance = fromExponential(balance);
return typeof balance === 'string' ? balance : parseFloat(balance.toFixed(5));
}
return 'N/A';
return typeof balance === 'number' ? String(fromExponential(balance)) : 'N/A';
};

export const shortenBalance = balance => {
Expand Down

0 comments on commit 2906e3e

Please sign in to comment.