Fix/213 total staked not showing (#242)

* total staked should show

* format number correctly with the correct number of decimal places
This commit is contained in:
Dexter Edwards 2022-04-12 19:18:58 +01:00 committed by GitHub
parent 1029c5bfa2
commit 04669bf9ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import { t } from '@vegaprotocol/react-helpers';
import { formatNumber, t } from '@vegaprotocol/react-helpers';
import type { Stats as IStats, StatFields as IStatFields } from './types';
// Stats fields config. Keys will correspond to graphql queries when used, and values
@ -59,9 +59,9 @@ export const statsFields: { [key in keyof IStats]: IStatFields[] } = {
stakedTotal: [
{
title: t('Total staked'),
formatter: (total: string) =>
total.length > 18 &&
parseInt(total.substring(0, total.length - 18)).toLocaleString('en-US'),
formatter: (total: string) => {
return formatNumber(total, 18);
},
description: t('Sum of VEGA associated with a Vega key'),
},
],

View File

@ -17,11 +17,17 @@ export function removeDecimal(value: string, decimals: number): string {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
export const getNumberFormat = memoize(
(minimumFractionDigits: number) =>
new Intl.NumberFormat(getUserLocale(), { minimumFractionDigits })
new Intl.NumberFormat(getUserLocale(), {
minimumFractionDigits,
})
);
export const formatNumber = (rawValue: string, decimalPlaces: number) => {
export const formatNumber = (
rawValue: string,
decimalPlaces: number,
formatDecimals: number = decimalPlaces
) => {
const x = addDecimal(rawValue, decimalPlaces);
return getNumberFormat(decimalPlaces).format(Number(x));
return getNumberFormat(formatDecimals).format(Number(x));
};