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:
parent
1029c5bfa2
commit
04669bf9ad
@ -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'),
|
||||
},
|
||||
],
|
||||
|
@ -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));
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user