diff --git a/app/components/UI/Swaps/QuotesView.js b/app/components/UI/Swaps/QuotesView.js index 238bbd5f6e3..ce56a8fba5f 100644 --- a/app/components/UI/Swaps/QuotesView.js +++ b/app/components/UI/Swaps/QuotesView.js @@ -586,9 +586,6 @@ function SwapsQuotesView({ const ethAmountBN = isSwapsNativeAsset(sourceToken) ? sourceBN : new BigNumber(0); - - // accounts[selectedAddress].balance might be undefined - // BigNumber(undefined) returns "NaN", which causes missingEthBalance to be "NaN" downstream const ethBalanceBN = new BigNumber(accounts[selectedAddress].balance); const gasBN = toWei(selectedQuoteValue?.maxEthFee || '0'); const hasEnoughEthBalance = ethBalanceBN.gte(ethAmountBN.plus(gasBN)); @@ -1677,12 +1674,6 @@ function SwapsQuotesView({ hasEnoughTokenBalance && hasEnoughEthBalance; - const shouldShowNeedMoreAlert = - (!isSwapsNativeAsset(sourceToken) && !hasEnoughTokenBalance) || - (isSwapsNativeAsset(sourceToken) && - !hasEnoughEthBalance && - missingEthBalance?.isNaN() === false); - return ( - {shouldShowNeedMoreAlert && ( + {(!hasEnoughTokenBalance || !hasEnoughEthBalance) && ( {`${strings('swaps.you_need')} `} diff --git a/app/util/number/index.js b/app/util/number/index.js index c4408d160a2..d24915a5f70 100644 --- a/app/util/number/index.js +++ b/app/util/number/index.js @@ -312,22 +312,17 @@ export function fiatNumberToTokenMinimalUnit( export function renderFromWei(value, decimalsToShow = 5) { let renderWei = '0'; // avoid undefined - // This function can throw an error if value is "NaN", so wrap in try/catch - try { - if (value) { - const wei = fromWei(value); - const weiNumber = parseFloat(wei); - if (weiNumber < 0.00001 && weiNumber > 0) { - renderWei = '< 0.00001'; - } else { - const base = Math.pow(10, decimalsToShow); - renderWei = (Math.round(weiNumber * base) / base).toString(); - } + if (value) { + const wei = fromWei(value); + const weiNumber = parseFloat(wei); + if (weiNumber < 0.00001 && weiNumber > 0) { + renderWei = '< 0.00001'; + } else { + const base = Math.pow(10, decimalsToShow); + renderWei = (Math.round(weiNumber * base) / base).toString(); } - return renderWei; - } catch (e) { - return renderWei; } + return renderWei; } /** diff --git a/app/util/number/index.test.ts b/app/util/number/index.test.ts index 8f6777529e9..4f85fe775aa 100644 --- a/app/util/number/index.test.ts +++ b/app/util/number/index.test.ts @@ -403,10 +403,6 @@ describe('Number utils :: renderFromWei', () => { expect(renderFromWei('133700000000000000')).toEqual('0.1337'); expect(renderFromWei('1337')).toEqual('< 0.00001'); expect(renderFromWei('0')).toEqual('0'); - - // https://github.com/MetaMask/metamask-mobile/issues/9672 - // fromWei will throw error if "NaN" is passed - expect(renderFromWei('NaN')).toEqual('0'); }); it('renderFromWei using BN number', () => {