MCPcopy
hub / github.com/BlueWallet/BlueWallet / formatBalance

Function formatBalance

loc/index.ts:377–390  ·  view source on GitHub ↗
(balance: number, toUnit: string, withFormatting = false)

Source from the content-addressed store, hash-verified

375 * @returns {string}
376 */
377export function formatBalance(balance: number, toUnit: string, withFormatting = false): string {
378 if (toUnit === undefined) {
379 return balance + ' ' + loc.units[BitcoinUnit.BTC];
380 }
381 if (toUnit === BitcoinUnit.BTC) {
382 const value = new BigNumber(balance).dividedBy(100000000).toFixed(8);
383 return removeTrailingZeros(value) + ' ' + loc.units[BitcoinUnit.BTC];
384 } else if (toUnit === BitcoinUnit.SATS) {
385 return (withFormatting ? new Intl.NumberFormat().format(balance).toString() : String(balance)) + ' ' + loc.units[BitcoinUnit.SATS];
386 } else {
387 console.debug('[UnitSwitch/Fiat] formatBalance to fiat', { balance, unit: toUnit, withFormatting });
388 return satoshiToLocalCurrency(balance);
389 }
390}
391
392/**
393 *

Callers 15

WalletListItemFunction · 0.90
AddressItemFunction · 0.90
SelectFeeScreenFunction · 0.90
ReceiveDetailsFunction · 0.90
renderGotPayloadFunction · 0.90
createInvoiceFunction · 0.90
ConfirmFunction · 0.90
formatFeeFunction · 0.90
CoinControlOutputSheetFunction · 0.90
OutputListFunction · 0.90

Calls 3

satoshiToLocalCurrencyFunction · 0.90
removeTrailingZerosFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected