ghost-portal/packages/test-support/src/utils/balance.ts
Jaco 4929b1c6fd
Update headers for 2023 (#8665)
* Update headers for 2023

* Adjust env-config
2023-01-01 10:32:05 +02:00

28 lines
1.1 KiB
TypeScript

// Copyright 2017-2023 @polkadot/test-supports authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { Balance } from '@polkadot/types/interfaces';
import { BN, formatBalance } from '@polkadot/util';
import { balanceOf } from '../creation/balance';
/**
* Creates a balance instance for testing purposes which most often do not need to specifiy/use decimal part.
* @param amountInt Integer part of the balance number
* @param decimalsString Decimals part of the balance number. Note! This is a string sequence just after '.' separator
* that is the point that separates integers from decimals. E.g. (100, 4567) => 100.45670000...00
*/
export function balance (amountInt: number, decimalsString?: string): Balance {
const decimalsPadded = (decimalsString || '').padEnd(12, '0');
return balanceOf(amountInt.toString() + decimalsPadded);
}
export function showBalance (amount: number): string {
return format(balance(amount));
}
export function format (amount: Balance | BN): string {
return formatBalance(amount, { decimals: 12, forceUnit: '-', withUnit: true });
}