Skip to content

Commit e6fe83f

Browse files
authored
Merge pull request #207 from lightninglabs/input-locale-fix
pool+orders: fix number input being truncated
2 parents a23a773 + 0163efe commit e6fe83f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

app/src/components/common/FormInputNumber.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { ReactNode, useCallback, useMemo } from 'react';
2+
import { formatSats } from 'util/formatters';
23
import FormInput from './FormInput';
34

45
interface Props {
@@ -27,7 +28,10 @@ const FormInputNumber: React.FC<Props> = ({
2728
[onChange],
2829
);
2930

30-
const valueText = useMemo(() => (!value ? '' : value.toLocaleString()), [value]);
31+
const valueText = useMemo(
32+
() => (!value ? '' : formatSats(value, { withSuffix: false })),
33+
[value],
34+
);
3135

3236
return (
3337
<FormInput

app/src/util/formatters.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ const defaultFormatSatsOptions = {
2222
* @param sats the numeric value in satoshis
2323
* @param options the format options
2424
*/
25-
export const formatSats = (sats: Big, options?: FormatSatsOptions) => {
25+
export const formatSats = (sats: Big | number, options?: FormatSatsOptions) => {
2626
const { unit, withSuffix, lang } = Object.assign({}, defaultFormatSatsOptions, options);
2727
const { suffix, denominator, decimals } = Units[unit];
2828
const formatter = Intl.NumberFormat(lang, {
2929
minimumFractionDigits: decimals,
3030
maximumFractionDigits: decimals,
3131
});
32-
let text = formatter.format(+sats.div(denominator));
32+
let text = formatter.format(+Big(sats).div(denominator));
3333
if (withSuffix) text = `${text} ${suffix}`;
3434
return text;
3535
};

0 commit comments

Comments
 (0)