fix(trading): fix percentage formatter rounding in liquidity table (#5250)

This commit is contained in:
m.ray 2023-11-13 18:14:18 +02:00 committed by GitHub
parent f780013846
commit 22703d937e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,6 @@ import { useMemo } from 'react';
import {
addDecimalsFormatNumber,
addDecimalsFormatNumberQuantum,
formatNumberPercentage,
getDateTimeFormat,
} from '@vegaprotocol/utils';
import { t } from '@vegaprotocol/i18n';
@ -29,6 +28,12 @@ import { LiquidityProvisionStatus } from '@vegaprotocol/types';
import { LiquidityProvisionStatusMapping } from '@vegaprotocol/types';
import type { LiquidityProvisionData } from './liquidity-data-provider';
const formatNumberPercentage = (value: BigNumber, decimals?: number) => {
const decimalPlaces =
typeof decimals === 'undefined' ? value.dp() || 0 : decimals;
return `${value.toFixed(decimalPlaces, 1)}%`;
};
const percentageFormatter = ({ value }: ValueFormatterParams) => {
if (!value) return '-';
return formatNumberPercentage(new BigNumber(value).times(100), 2) || '-';
@ -126,11 +131,11 @@ export const LiquidityTable = ({
new BigNumber(data.sla.currentEpochFractionOfTimeOnBook).times(
100
),
2
4
),
formatNumberPercentage(
new BigNumber(data.commitmentMinTimeFraction).times(100),
2
4
),
]
);
@ -143,7 +148,7 @@ export const LiquidityTable = ({
new BigNumber(data.sla.currentEpochFractionOfTimeOnBook).times(
100
),
2
4
),
]
);