frontend-monorepo-267 Reduce total staked to 2 decimal precision (#282)

* frontend-monorepo-267 Reduce total staked to 2 decimal precision

* Tweak to formatNumber to allow fixed decimal specificity

* Setting default value for the 'defaultPrecision' argument in the function signature of 'addDecimal'
This commit is contained in:
Sam Keen 2022-04-25 15:28:31 +01:00 committed by GitHub
parent ce5d7bc15b
commit 3354fbb0c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -60,7 +60,7 @@ export const statsFields: { [key in keyof IStats]: IStatFields[] } = {
{
title: t('Total staked'),
formatter: (total: string) => {
return formatNumber(total, 18);
return formatNumber(total, 18, 2);
},
description: t('Sum of VEGA associated with a Vega key'),
},

View File

@ -2,11 +2,15 @@ import { BigNumber } from 'bignumber.js';
import memoize from 'lodash/memoize';
import { getUserLocale } from './utils';
export function addDecimal(value: string, decimals: number): string {
export function addDecimal(
value: string,
decimals: number,
decimalPrecision = decimals
): string {
if (!decimals) return value;
return new BigNumber(value || 0)
.dividedBy(Math.pow(10, decimals))
.toFixed(decimals);
.toFixed(decimalPrecision);
}
export function removeDecimal(value: string, decimals: number): string {
@ -16,9 +20,10 @@ 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) =>
(digits: number) =>
new Intl.NumberFormat(getUserLocale(), {
minimumFractionDigits,
minimumFractionDigits: digits,
maximumFractionDigits: digits,
})
);