From 8ca0b762ad71912778ae9dfd21bd71fd0f6b013a Mon Sep 17 00:00:00 2001 From: Daniel <80175477+dan437@users.noreply.github.com> Date: Mon, 21 Aug 2023 18:06:12 +0200 Subject: [PATCH] Don't call "toPrecisionWithoutTrailingZeros" if a destination value is not a number (#20525) --- ui/pages/swaps/swaps.util.test.js | 6 ++++++ ui/pages/swaps/swaps.util.ts | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ui/pages/swaps/swaps.util.test.js b/ui/pages/swaps/swaps.util.test.js index 05f06f7d1..642879484 100644 --- a/ui/pages/swaps/swaps.util.test.js +++ b/ui/pages/swaps/swaps.util.test.js @@ -401,6 +401,12 @@ describe('Swaps Util', () => { '39.6493201125', ); }); + + it('gets swaps value for display when the value contains three dots', () => { + expect(formatSwapsValueForDisplay('33680099000000000000...')).toBe( + '33680099000000000000...', + ); + }); }); describe('getSwapsTokensReceivedFromTxMeta', () => { diff --git a/ui/pages/swaps/swaps.util.ts b/ui/pages/swaps/swaps.util.ts index 566faa93f..7782f0df8 100644 --- a/ui/pages/swaps/swaps.util.ts +++ b/ui/pages/swaps/swaps.util.ts @@ -545,8 +545,18 @@ export function quotesToRenderableData({ }); } -export function formatSwapsValueForDisplay(destinationAmount: string): string { - let amountToDisplay = toPrecisionWithoutTrailingZeros(destinationAmount, 12); +export function formatSwapsValueForDisplay( + destinationAmount: string | BigNumber, +): string { + let amountToDisplay; + if ( + typeof destinationAmount === 'string' && + destinationAmount.includes('...') + ) { + amountToDisplay = destinationAmount; + } else { + amountToDisplay = toPrecisionWithoutTrailingZeros(destinationAmount, 12); + } if (amountToDisplay.match(/e[+-]/u)) { amountToDisplay = new BigNumber(amountToDisplay).toFixed(); }