+1
-1
@@ -35,7 +35,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.12",
|
||||
"@polkadot/dev": "^0.68.29",
|
||||
"@polkadot/dev": "^0.68.36",
|
||||
"@types/jest": "^29.4.0"
|
||||
},
|
||||
"resolutions": {
|
||||
|
||||
@@ -4,13 +4,18 @@
|
||||
import { BN } from '../bn';
|
||||
import { formatBalance } from '.';
|
||||
|
||||
const FMT_DEFAULTS = {
|
||||
decimals: 0,
|
||||
unit: 'Unit'
|
||||
};
|
||||
|
||||
describe('formatBalance', (): void => {
|
||||
const TESTVAL = new BN('123456789000');
|
||||
|
||||
// We mess around with the global setDefaults inside some tests,
|
||||
// ensure we restore it to the defaults straight after each run
|
||||
afterEach((): void => {
|
||||
formatBalance.setDefaults({ decimals: 0, unit: 'Unit' });
|
||||
formatBalance.setDefaults(FMT_DEFAULTS);
|
||||
});
|
||||
|
||||
it('returns options for dropdown', (): void => {
|
||||
@@ -216,7 +221,7 @@ describe('formatBalance', (): void => {
|
||||
).toEqual('12,345.6789 Unit');
|
||||
});
|
||||
|
||||
it('formats 123,456,789,000 (decimals=15, forceUnit=µ)', (): void => {
|
||||
it('formats 123,456,789,000 (decimals=15, forceUnit=micro)', (): void => {
|
||||
expect(
|
||||
formatBalance(TESTVAL, { decimals: 15, forceUnit: 'µ' })
|
||||
).toEqual('123.4567 µUnit');
|
||||
@@ -265,10 +270,9 @@ describe('formatBalance', (): void => {
|
||||
|
||||
describe('defaults', (): void => {
|
||||
it('returns defaults', (): void => {
|
||||
expect(formatBalance.getDefaults()).toEqual({
|
||||
decimals: 0,
|
||||
unit: 'Unit'
|
||||
});
|
||||
expect(
|
||||
formatBalance.getDefaults()
|
||||
).toEqual(FMT_DEFAULTS);
|
||||
});
|
||||
|
||||
it('formats 123,456,789,000 (defaultDecimals=12)', (): void => {
|
||||
|
||||
@@ -71,7 +71,7 @@ let defaultDecimals = DEFAULT_DECIMALS;
|
||||
let defaultUnit = DEFAULT_UNIT;
|
||||
|
||||
// Formats a string/number with <prefix>.<postfix><type> notation
|
||||
function _formatBalance <ExtToBn extends ToBn> (input?: number | string | BN | bigint | ExtToBn, { decimals = defaultDecimals, forceUnit, withAll = false, withSi = true, withSiFull = false, withUnit = true, withZero = true, locale = 'en' }: Options = {}): string {
|
||||
function _formatBalance <ExtToBn extends ToBn> (input?: number | string | BN | bigint | ExtToBn, { decimals = defaultDecimals, forceUnit, locale = 'en', withAll = false, withSi = true, withSiFull = false, withUnit = true, withZero = true }: Options = {}): string {
|
||||
// we only work with string inputs here - convert anything
|
||||
// into the string-only value
|
||||
let text = bnToBn(input).toString();
|
||||
|
||||
Reference in New Issue
Block a user