From c09e685bceaf7d13c94210f92183555337a15bdf Mon Sep 17 00:00:00 2001 From: Daniel <80175477+dan437@users.noreply.github.com> Date: Thu, 13 Oct 2022 21:46:23 +0200 Subject: [PATCH] Keep imported tokens in the Assets list (#16167) * Don't add a token if it's already added * Pass tokens directly * Add toLowerCase --- ui/ducks/swaps/swaps.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ui/ducks/swaps/swaps.js b/ui/ducks/swaps/swaps.js index 87303d980..9af2ee183 100644 --- a/ui/ducks/swaps/swaps.js +++ b/ui/ducks/swaps/swaps.js @@ -83,7 +83,7 @@ import { IN_PROGRESS_TRANSACTION_STATUSES, SMART_TRANSACTION_STATUSES, } from '../../../shared/constants/transaction'; -import { getGasFeeEstimates } from '../metamask/metamask'; +import { getGasFeeEstimates, getTokens } from '../metamask/metamask'; import { ORIGIN_METAMASK } from '../../../shared/constants/app'; import { calcGasTotal, @@ -606,6 +606,15 @@ export const fetchSwapsLivenessAndFeatureFlags = () => { }; }; +const isTokenAlreadyAdded = (tokenAddress, tokens) => { + if (!Array.isArray(tokens)) { + return false; + } + return tokens.find( + (token) => token.address.toLowerCase() === tokenAddress.toLowerCase(), + ); +}; + export const fetchQuotesAndSetQuoteState = ( history, inputValue, @@ -674,7 +683,8 @@ export const fetchQuotesAndSetQuoteState = ( if ( toTokenAddress && toTokenSymbol !== swapsDefaultToken.symbol && - contractExchangeRates[toTokenAddress] === undefined + contractExchangeRates[toTokenAddress] === undefined && + !isTokenAlreadyAdded(toTokenAddress, getTokens(state)) ) { destinationTokenAddedForSwap = true; await dispatch(