1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Keep imported tokens in the Assets list (#16167)

* Don't add a token if it's already added

* Pass tokens directly

* Add toLowerCase
This commit is contained in:
Daniel 2022-10-13 21:46:23 +02:00 committed by GitHub
parent 7eb93ff74b
commit c09e685bce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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(