fix: dont assume that you always want 2 dps
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { FeesBreakdown } from './fees-breakdown';
|
||||
|
||||
describe('FeesBreakdown', () => {
|
||||
it('formats fee factors correctly', () => {
|
||||
const feeFactors = {
|
||||
makerFee: '0.00005',
|
||||
infrastructureFee: '0.001',
|
||||
liquidityFee: '0.5',
|
||||
};
|
||||
const fees = {
|
||||
makerFee: '100',
|
||||
infrastructureFee: '100',
|
||||
liquidityFee: '100',
|
||||
};
|
||||
const props = {
|
||||
totalFeeAmount: '100',
|
||||
fees,
|
||||
feeFactors,
|
||||
symbol: 'USD',
|
||||
decimals: 2,
|
||||
referralDiscountFactor: '0.01',
|
||||
volumeDiscountFactor: '0.01',
|
||||
};
|
||||
render(<FeesBreakdown {...props} />);
|
||||
expect(screen.getByText('Maker fee').nextElementSibling).toHaveTextContent(
|
||||
'0.005%'
|
||||
);
|
||||
expect(
|
||||
screen.getByText('Infrastructure fee').nextElementSibling
|
||||
).toHaveTextContent('0.1%');
|
||||
expect(
|
||||
screen.getByText('Liquidity fee').nextElementSibling
|
||||
).toHaveTextContent('50%');
|
||||
});
|
||||
});
|
||||
@@ -158,7 +158,7 @@ export const addDecimalsFixedFormatNumber = (
|
||||
|
||||
export const formatNumberPercentage = (value: BigNumber, decimals?: number) => {
|
||||
const decimalPlaces =
|
||||
typeof decimals === 'undefined' ? Math.max(value.dp() || 0, 2) : decimals;
|
||||
typeof decimals === 'undefined' ? value.dp() || 0 : decimals;
|
||||
return `${formatNumber(value, decimalPlaces)}%`;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user