Skip to content

Commit

Permalink
Merge branch 'main' into fix/1519-spoofing-site
Browse files Browse the repository at this point in the history
  • Loading branch information
frankvonhoven authored Jun 28, 2024
2 parents f52fdb4 + fe986fe commit 1a97bac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
12 changes: 12 additions & 0 deletions app/components/hooks/DisplayName/useTokenList.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from 'react';
import { type TokenListMap } from '@metamask/assets-controllers';
import { selectChainId } from '../../../selectors/networkController';
import { selectUseTokenDetection } from '../../../selectors/preferencesController';
Expand Down Expand Up @@ -69,6 +70,17 @@ describe('useTokenList', () => {
selectUseTokenDetectionMock.mockReturnValue(true);
selectTokenListMock.mockReturnValue(TOKEN_LIST_MOCK);
isMainnetByChainIdMock.mockReturnValue(true);

const memoizedValues = new Map();
jest.spyOn(React, 'useMemo').mockImplementation((factory, deps) => {
const depsKey = (deps as []).join('|');
if (memoizedValues.has(depsKey)) {
return memoizedValues.get(depsKey);
}
const newValue = factory();
memoizedValues.set(depsKey, newValue);
return newValue;
});
});

it('returns normalized STATIC_MAINNET_TOKEN_LIST if token detection is disabled and chain is mainnet', () => {
Expand Down
15 changes: 9 additions & 6 deletions app/components/hooks/DisplayName/useTokenList.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMemo } from 'react';
import { type TokenListMap } from '@metamask/assets-controllers';
import contractMap from '@metamask/contract-metadata';

Expand Down Expand Up @@ -25,11 +26,13 @@ export default function useTokenList(): TokenListMap {
const chainId = useSelector(selectChainId);
const isMainnet = isMainnetByChainId(chainId);
const isTokenDetectionEnabled = useSelector(selectUseTokenDetection);
const tokenList = useSelector(selectTokenList) || [];
const tokenList = useSelector(selectTokenList);
const shouldUseStaticList = !isTokenDetectionEnabled && isMainnet;

if (!isTokenDetectionEnabled && isMainnet) {
return NORMALIZED_MAINNET_TOKEN_LIST;
}

return normalizeTokenAddresses(tokenList);
return useMemo(() => {
if (shouldUseStaticList) {
return NORMALIZED_MAINNET_TOKEN_LIST;
}
return normalizeTokenAddresses(tokenList);
}, [shouldUseStaticList, tokenList]);
}
5 changes: 4 additions & 1 deletion metro.transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ module.exports.transform = async ({ src, filename, options }) => {
* Params based on builds we're code splitting
* i.e: flavorDimensions "version" productFlavors from android/app/build.gradle
*/
if (fileExtsToScan.includes(path.extname(filename))) {
if (
!path.normalize(filename).split(path.sep).includes('node_modules') &&
fileExtsToScan.includes(path.extname(filename))
) {
const [processedSource, didModify] = removeFencedCode(filename, src, {
all: availableFeatures,
active: getBuildTypeFeatures(),
Expand Down

0 comments on commit 1a97bac

Please sign in to comment.