1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

Don't call "toPrecisionWithoutTrailingZeros" if a destination value is not a number (#20525)

This commit is contained in:
Daniel 2023-08-21 18:06:12 +02:00 committed by GitHub
parent 702ee233e7
commit 8ca0b762ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -401,6 +401,12 @@ describe('Swaps Util', () => {
'39.6493201125', '39.6493201125',
); );
}); });
it('gets swaps value for display when the value contains three dots', () => {
expect(formatSwapsValueForDisplay('33680099000000000000...')).toBe(
'33680099000000000000...',
);
});
}); });
describe('getSwapsTokensReceivedFromTxMeta', () => { describe('getSwapsTokensReceivedFromTxMeta', () => {

View File

@ -545,8 +545,18 @@ export function quotesToRenderableData({
}); });
} }
export function formatSwapsValueForDisplay(destinationAmount: string): string { export function formatSwapsValueForDisplay(
let amountToDisplay = toPrecisionWithoutTrailingZeros(destinationAmount, 12); destinationAmount: string | BigNumber,
): string {
let amountToDisplay;
if (
typeof destinationAmount === 'string' &&
destinationAmount.includes('...')
) {
amountToDisplay = destinationAmount;
} else {
amountToDisplay = toPrecisionWithoutTrailingZeros(destinationAmount, 12);
}
if (amountToDisplay.match(/e[+-]/u)) { if (amountToDisplay.match(/e[+-]/u)) {
amountToDisplay = new BigNumber(amountToDisplay).toFixed(); amountToDisplay = new BigNumber(amountToDisplay).toFixed();
} }