ghost-portal/packages/page-staking/src/Query/util.ts
Tarik Gul 384049fb6b
2025 (#11172)
* 2025

* update ci scripts to add access to scripts
2025-01-03 03:59:53 +02:00

21 lines
526 B
TypeScript

// Copyright 2017-2025 @polkadot/app-staking authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { BN } from '@polkadot/util';
import { BN_THOUSAND, BN_ZERO, isBn, isFunction } from '@polkadot/util';
interface ToBN {
toBn: () => BN;
}
export function balanceToNumber (amount: BN | ToBN = BN_ZERO, divisor: BN): number {
const value = isBn(amount)
? amount
: isFunction(amount.toBn)
? amount.toBn()
: BN_ZERO;
return value.mul(BN_THOUSAND).div(divisor).toNumber() / 1000;
}