the token detction change affected swap performace, this is fixing it (#15607)

feature/default_network_editable
Niranjana Binoy 2 years ago committed by GitHub
parent b27672bd0e
commit d09bdbe3df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      ui/hooks/useTokensToSearch.js
  2. 7
      ui/pages/swaps/build-quote/build-quote.js

@ -8,6 +8,7 @@ import {
getCurrentCurrency,
getSwapsDefaultToken,
getCurrentChainId,
getTokenList,
} from '../selectors';
import { getConversionRate } from '../ducks/metamask/metamask';
@ -23,7 +24,7 @@ export function getRenderableTokenData(
conversionRate,
currentCurrency,
chainId,
shuffledTokenList,
tokenList,
) {
const { symbol, name, address, iconUrl, string, balance, decimals } = token;
let contractExchangeRate;
@ -54,15 +55,12 @@ export function getRenderableTokenData(
)
: '';
const tokenMetadata = shuffledTokenList.find(
(tokenData) => tokenData.address === address?.toLowerCase(),
);
const usedIconUrl = iconUrl || tokenMetadata?.iconUrl || token?.image;
const usedIconUrl =
iconUrl || tokenList[address?.toLowerCase()]?.iconUrl || token?.image;
return {
...token,
primaryLabel: symbol,
secondaryLabel: name || tokenMetadata?.name,
secondaryLabel: name || tokenList[address?.toLowerCase()]?.name,
rightPrimaryLabel:
string && `${new BigNumber(string).round(6).toString()} ${symbol}`,
rightSecondaryLabel: formattedFiat,
@ -70,7 +68,7 @@ export function getRenderableTokenData(
identiconAddress: usedIconUrl ? null : address,
balance,
decimals,
name: name || tokenMetadata?.name,
name: name || tokenList[address?.toLowerCase()]?.name,
rawFiat,
};
}
@ -86,6 +84,7 @@ export function useTokensToSearch({
const conversionRate = useSelector(getConversionRate);
const currentCurrency = useSelector(getCurrentCurrency);
const defaultSwapsToken = useSelector(getSwapsDefaultToken, shallowEqual);
const tokenList = useSelector(getTokenList, isEqual);
const memoizedTopTokens = useEqualityCheck(topTokens);
const memoizedUsersToken = useEqualityCheck(usersTokens);
@ -96,7 +95,7 @@ export function useTokensToSearch({
conversionRate,
currentCurrency,
chainId,
shuffledTokensList,
tokenList,
);
const memoizedDefaultToken = useEqualityCheck(defaultToken);
@ -136,7 +135,7 @@ export function useTokensToSearch({
conversionRate,
currentCurrency,
chainId,
shuffledTokensList,
tokenList,
);
if (tokenBucketPriority === TOKEN_BUCKET_PRIORITY.OWNED) {
if (
@ -192,7 +191,7 @@ export function useTokensToSearch({
currentCurrency,
memoizedDefaultToken,
chainId,
shuffledTokensList,
tokenList,
tokenBucketPriority,
]);
}

@ -66,7 +66,7 @@ import {
getCurrentCurrency,
getCurrentChainId,
getRpcPrefsForCurrentProvider,
getUseTokenDetection,
getTokenList,
isHardwareWallet,
getHardwareWalletType,
} from '../../../selectors';
@ -150,7 +150,7 @@ export default function BuildQuote({
const defaultSwapsToken = useSelector(getSwapsDefaultToken, isEqual);
const chainId = useSelector(getCurrentChainId);
const rpcPrefs = useSelector(getRpcPrefsForCurrentProvider, shallowEqual);
const useTokenDetection = useSelector(getUseTokenDetection);
const tokenList = useSelector(getTokenList, isEqual);
const quotes = useSelector(getQuotes, isEqual);
const areQuotesPresent = Object.keys(quotes).length > 0;
@ -212,8 +212,7 @@ export default function BuildQuote({
conversionRate,
currentCurrency,
chainId,
shuffledTokensList,
useTokenDetection,
tokenList,
);
const tokensToSearchSwapFrom = useTokensToSearch({

Loading…
Cancel
Save