Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/cashMethods.js
import { currency } from '@components/Common/Ticker'; | import { currency } from '@components/Common/Ticker'; | ||||
import BigNumber from 'bignumber.js'; | import BigNumber from 'bignumber.js'; | ||||
export const fromSmallestDenomination = ( | export const fromSmallestDenomination = ( | ||||
amount, | amount, | ||||
cashDecimals = currency.cashDecimals, | cashDecimals = currency.cashDecimals, | ||||
) => { | ) => { | ||||
const amountBig = new BigNumber(amount); | const amountBig = new BigNumber(amount); | ||||
const multiplier = new BigNumber(10 ** (-1 * cashDecimals)); | const multiplier = new BigNumber(10 ** (-1 * cashDecimals)); | ||||
const amountInBaseUnits = amountBig.times(multiplier); | const amountInBaseUnits = amountBig.times(multiplier); | ||||
return amountInBaseUnits.toNumber(); | return amountInBaseUnits.toNumber(); | ||||
}; | }; | ||||
export const formatBalance = x => { | |||||
return x.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ','); | |||||
}; |