Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab-components/src/utils/cashtab-helpers.ts
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | |||||
const formatAmount = (amount?: number, decimals?: number): string => { | const formatAmount = (amount?: number, decimals?: number): string => { | ||||
if (!decimals) { | if (!decimals) { | ||||
return '-.--------'; | return '-.--------'; | ||||
} | } | ||||
if (!amount) { | if (!amount) { | ||||
return `-.`.padEnd(decimals + 2, '-'); | return `-.`.padEnd(decimals + 2, '-'); | ||||
} | } | ||||
const baseAmount = new BigNumber(amount); | const baseAmount = new BigNumber(amount); | ||||
const adjustDecimals = baseAmount | const adjustDecimals = baseAmount.shiftedBy(-1 * decimals).toFixed(2); | ||||
.shiftedBy(-1 * decimals) | const formatForLargeNum = parseFloat(adjustDecimals).toLocaleString( | ||||
.toFixed(decimals); | undefined, | ||||
const removeTrailing = +adjustDecimals + ''; | { | ||||
minimumFractionDigits: 2, | |||||
maximumFractionDigits: 2, | |||||
}, | |||||
); | |||||
const removeTrailing = `${formatForLargeNum} `; | |||||
return removeTrailing; | return removeTrailing; | ||||
}; | }; | ||||
const priceToSatoshis = (BCHRate: number, price: number): number => { | const priceToSatoshis = (BCHRate: number, price: number): number => { | ||||
const singleDollarValue = new BigNumber(BCHRate); | const singleDollarValue = new BigNumber(BCHRate); | ||||
const satoshisPerBCH = new BigNumber(100000000); | const satoshisPerBCH = new BigNumber(100000000); | ||||
const singleDollarSatoshis = satoshisPerBCH.div(singleDollarValue); | const singleDollarSatoshis = satoshisPerBCH.div(singleDollarValue); | ||||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |