robosats/frontend/src/utils/prettyNumbers.ts
Reckless_Satoshi 965bbb0765
Enhance UI for Swaps (#346)
* Add better fiat/swap UI switches

* Add swap controls to booktable

* Enhance order details and take button for swaps

* Add swap specific order summary strings

* Add specific bond commitment descriptions for swap orders

* Fix cosmetics
2023-02-10 13:28:26 +00:00

31 lines
762 B
TypeScript

export const pn = (value?: number | null): string | undefined => {
if (value === null || value === undefined) {
return;
}
const parts = value.toString().split('.');
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
return parts.join('.');
};
export const amountToString: (
amount: string,
has_range: boolean,
min_amount: number,
max_amount: number,
precision?: number,
) => string = (amount, has_range, min_amount, max_amount, precision = 4) => {
if (has_range) {
return (
pn(parseFloat(Number(min_amount).toPrecision(precision))) +
'-' +
pn(parseFloat(Number(max_amount).toPrecision(precision)))
);
}
return pn(parseFloat(Number(amount).toPrecision(precision))) || '';
};
export default pn;