Use language stored in localStorage for formatting numbers.

This commit is contained in:
Franco Montenegro 2022-04-28 09:05:05 -03:00 committed by jessopb
parent 5319232918
commit efa682ef02
3 changed files with 8 additions and 6 deletions

View file

@ -9,7 +9,7 @@ import HelpLink from 'component/common/help-link';
import Card from 'component/common/card';
import LbcSymbol from 'component/common/lbc-symbol';
import I18nMessage from 'component/i18nMessage';
import { formatNumberWithCommas } from 'util/number';
import { formatCredits } from 'util/format-credits';
type Props = {
balance: number,
@ -64,7 +64,7 @@ const WalletBalance = (props: Props) => {
return (
<Card
title={<LbcSymbol postfix={formatNumberWithCommas(totalBalance)} isTitle />}
title={<LbcSymbol postfix={formatCredits(totalBalance, 8)} isTitle />}
subtitle={
totalLocked > 0 ? (
<I18nMessage tokens={{ lbc: <LbcSymbol /> }}>

View file

@ -1,11 +1,12 @@
export function formatCredits(amount, precision, shortFormat = false) {
const language = localStorage.getItem('language') || undefined;
const actualAmount = Number(amount);
const safePrecision = Math.min(20, Math.max(1, precision));
const safePrecision = Math.min(20, Math.max(1, precision || 0));
if (Number.isNaN(actualAmount) || actualAmount === 0) return '0';
if (shortFormat) {
const formatter = new Intl.NumberFormat(undefined, {
const formatter = new Intl.NumberFormat(language, {
minimumFractionDigits: safePrecision,
maximumFractionDigits: safePrecision,
roundingIncrement: 5,
@ -16,7 +17,7 @@ export function formatCredits(amount, precision, shortFormat = false) {
return formatter.format(actualAmount);
}
const formatter = new Intl.NumberFormat(undefined, {
const formatter = new Intl.NumberFormat(language, {
minimumFractionDigits: safePrecision,
maximumFractionDigits: safePrecision,
roundingIncrement: 5,

View file

@ -1,8 +1,9 @@
// @flow
export function formatNumber(num: number, numberOfDigits?: number, short: boolean = false): string {
const language = localStorage.getItem('language') || undefined;
const safePrecision = Math.min(20, numberOfDigits || 0);
const formatter = new Intl.NumberFormat(undefined, {
const formatter = new Intl.NumberFormat(language, {
maximumFractionDigits: safePrecision,
notation: short ? 'compact' : 'standard',
compactDisplay: 'short',