Skip to content

Commit

Permalink
feat: token detection on 7 more networks (#24121)
Browse files Browse the repository at this point in the history
## **Description**

Adds support for erc20 token detection on 7 more networks.

Patching this from core because it's small:
MetaMask/core#4184


[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24121?quickstart=1)

## **Related issues**

https://consensyssoftware.atlassian.net/browse/MMASSETS-207

## **Manual testing steps**

1. Visit one of the new chains (cronos, celo, gnosis, fantom, polygon
zk, moonbeam, moonriver) on a wallet that has tokens on the network
2.  They should be autodetected


## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

None of the chains support token lists or detection:

<img width="345" alt="Screenshot 2024-04-22 at 9 50 03 PM"
src="https://github.com/MetaMask/metamask-extension/assets/3500406/97c08793-0b08-44b9-aef4-71f551b8a803">

### **After**

All 7 chains support detection:


https://github.com/MetaMask/metamask-extension/assets/3500406/16c8e763-ccc0-4070-8ac3-28a7dfa88e1f


<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
bergeron authored Apr 24, 2024
1 parent 4b55476 commit f3c4676
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 7 deletions.
57 changes: 57 additions & 0 deletions .yarn/patches/@metamask-assets-controllers-patch-7616cc1669.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
diff --git a/dist/AssetsContractController.js b/dist/AssetsContractController.js
index e8bae0bc514db69398fc2c378ca42eeb8f135e60..33c1e894f0318a59ec43f1b0a51500118c49bef6 100644
--- a/dist/AssetsContractController.js
+++ b/dist/AssetsContractController.js
@@ -40,6 +40,13 @@ exports.SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID = {
[assetsUtil_1.SupportedTokenDetectionNetworks.optimism]: '0xB1c568e9C3E6bdaf755A60c7418C269eb11524FC',
[assetsUtil_1.SupportedTokenDetectionNetworks.base]: '0x6AA75276052D96696134252587894ef5FFA520af',
[assetsUtil_1.SupportedTokenDetectionNetworks.zksync]: '0x458fEd3144680a5b8bcfaa0F9594aa19B4Ea2D34',
+ [assetsUtil_1.SupportedTokenDetectionNetworks.cronos]: '0x768ca200f0fc702ac9ea502498c18f5eff176378',
+ [assetsUtil_1.SupportedTokenDetectionNetworks.celo]: '0x6aa75276052d96696134252587894ef5ffa520af',
+ [assetsUtil_1.SupportedTokenDetectionNetworks.gnosis]: '0x6aa75276052d96696134252587894ef5ffa520af',
+ [assetsUtil_1.SupportedTokenDetectionNetworks.fantom]: '0x6aa75276052d96696134252587894ef5ffa520af',
+ [assetsUtil_1.SupportedTokenDetectionNetworks.polygon_zkevm]: '0x6aa75276052d96696134252587894ef5ffa520af',
+ [assetsUtil_1.SupportedTokenDetectionNetworks.moonbeam]: '0x6aa75276052d96696134252587894ef5ffa520af',
+ [assetsUtil_1.SupportedTokenDetectionNetworks.moonriver]: '0x6aa75276052d96696134252587894ef5ffa520af',
};
exports.MISSING_PROVIDER_ERROR = 'AssetsContractController failed to set the provider correctly. A provider must be set for this method to be available';
/**
diff --git a/dist/assetsUtil.d.ts b/dist/assetsUtil.d.ts
index 85c85697971f08cd74cbb0fd9b305ee844a0519e..5d90c63f0cf8ab5d694467afc003c7e83ed8e64b 100644
--- a/dist/assetsUtil.d.ts
+++ b/dist/assetsUtil.d.ts
@@ -53,7 +53,15 @@ export declare enum SupportedTokenDetectionNetworks {
arbitrum = "0xa4b1",
optimism = "0xa",
base = "0x2105",
- zksync = "0x144"
+ zksync = "0x144",
+ zksync = "0x144",
+ cronos = "0x19",
+ celo = "0xa4ec",
+ gnosis = "0x64",
+ fantom = "0xfa",
+ polygon_zkevm = "0x44d",
+ moonbeam = "0x504",
+ moonriver = "0x505"
}
/**
* Check if token detection is enabled for certain networks.
diff --git a/dist/assetsUtil.js b/dist/assetsUtil.js
index 27689263f0af453ac35c6f3240cc11e6b307458e..8d7098eff7080a4846c6b8c55650df102a6d8f2f 100644
--- a/dist/assetsUtil.js
+++ b/dist/assetsUtil.js
@@ -119,6 +119,13 @@ var SupportedTokenDetectionNetworks;
SupportedTokenDetectionNetworks["optimism"] = "0xa";
SupportedTokenDetectionNetworks["base"] = "0x2105";
SupportedTokenDetectionNetworks["zksync"] = "0x144";
+ SupportedTokenDetectionNetworks["cronos"] = "0x19";
+ SupportedTokenDetectionNetworks["celo"] = "0xa4ec";
+ SupportedTokenDetectionNetworks["gnosis"] = "0x64";
+ SupportedTokenDetectionNetworks["fantom"] = "0xfa";
+ SupportedTokenDetectionNetworks["polygon_zkevm"] = "0x44d";
+ SupportedTokenDetectionNetworks["moonbeam"] = "0x504";
+ SupportedTokenDetectionNetworks["moonriver"] = "0x505";
})(SupportedTokenDetectionNetworks = exports.SupportedTokenDetectionNetworks || (exports.SupportedTokenDetectionNetworks = {}));
/**
* Check if token detection is enabled for certain networks.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@
"@metamask/address-book-controller": "^3.1.7",
"@metamask/announcement-controller": "^6.1.0",
"@metamask/approval-controller": "^6.0.0",
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@npm%253A26.0.0%23~/.yarn/patches/@metamask-assets-controllers-npm-26.0.0-17c0e9432c.patch%3A%3Aversion=26.0.0&hash=cf1d54#~/.yarn/patches/@metamask-assets-controllers-patch-0f46262fea.patch",
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@patch%253A@metamask/assets-controllers@npm%25253A26.0.0%2523~/.yarn/patches/@metamask-assets-controllers-npm-26.0.0-17c0e9432c.patch%253A%253Aversion=26.0.0&hash=cf1d54%23~/.yarn/patches/@metamask-assets-controllers-patch-0f46262fea.patch%3A%3Aversion=26.0.0&hash=5c145e#~/.yarn/patches/@metamask-assets-controllers-patch-7616cc1669.patch",
"@metamask/base-controller": "^4.1.0",
"@metamask/browser-passworder": "^4.3.0",
"@metamask/contract-metadata": "^2.5.0",
Expand Down
7 changes: 6 additions & 1 deletion shared/constants/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const CHAIN_IDS = {
ARBITRUM_GOERLI: '0x66eed',
BLAST: '0x13e31',
FILECOIN: '0x13a',
POLYGON_ZKEVM: '0x44d',
SCROLL: '0x82750',
SCROLL_SEPOLIA: '0x8274f',
} as const;
Expand Down Expand Up @@ -194,7 +195,6 @@ const CHAINLIST_CHAIN_IDS_MAP = {
OASYS_MAINNET: '0xf8',
OKXCHAIN_MAINNET: '0x42',
PGN_PUBLIC_GOODS_NETWORK: '0x1a8',
POLYGON_ZKEVM: '0x44d',
PULSECHAIN_MAINNET: '0x171',
SHARDEUM_LIBERTY_2X: '0x1f91',
SHARDEUM_SPHINX_1X: '0x1f92',
Expand Down Expand Up @@ -248,6 +248,10 @@ export const GNOSIS_DISPLAY_NAME = 'Gnosis';
export const ZK_SYNC_ERA_DISPLAY_NAME = 'zkSync Era Mainnet';
export const BASE_DISPLAY_NAME = 'Base Mainnet';
export const AURORA_ETH_DISPLAY_NAME = 'Aurora';
export const CRONOS_DISPLAY_NAME = 'Cronos';
export const POLYGON_ZKEVM_DISPLAY_NAME = 'Polygon zkEVM';
export const MOONBEAM_DISPLAY_NAME = 'Moonbeam';
export const MOONRIVER_DISPLAY_NAME = 'Moonriver';
export const SCROLL_DISPLAY_NAME = 'Scroll';
export const SCROLL_SEPOLIA_DISPLAY_NAME = 'Scroll Sepolia';

Expand Down Expand Up @@ -895,6 +899,7 @@ export const BUYABLE_CHAINS_MAP: {
| typeof CHAIN_IDS.ARBITRUM_GOERLI
| typeof CHAIN_IDS.BLAST
| typeof CHAIN_IDS.FILECOIN
| typeof CHAIN_IDS.POLYGON_ZKEVM
| typeof CHAIN_IDS.SCROLL
| typeof CHAIN_IDS.SCROLL_SEPOLIA
>]: BuyableChainSettings;
Expand Down
7 changes: 7 additions & 0 deletions shared/modules/network.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ export function isTokenDetectionEnabledForNetwork(chainId: string | undefined) {
case CHAIN_IDS.OPTIMISM:
case CHAIN_IDS.BASE:
case CHAIN_IDS.ZKSYNC_ERA:
case CHAIN_IDS.CRONOS:
case CHAIN_IDS.CELO:
case CHAIN_IDS.GNOSIS:
case CHAIN_IDS.FANTOM:
case CHAIN_IDS.POLYGON_ZKEVM:
case CHAIN_IDS.MOONBEAM:
case CHAIN_IDS.MOONRIVER:
return true;
default:
return false;
Expand Down
32 changes: 29 additions & 3 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ import {
CHAIN_ID_TOKEN_IMAGE_MAP,
LINEA_SEPOLIA_TOKEN_IMAGE_URL,
LINEA_SEPOLIA_DISPLAY_NAME,
CRONOS_DISPLAY_NAME,
CELO_DISPLAY_NAME,
GNOSIS_DISPLAY_NAME,
FANTOM_DISPLAY_NAME,
POLYGON_ZKEVM_DISPLAY_NAME,
MOONBEAM_DISPLAY_NAME,
MOONRIVER_DISPLAY_NAME,
} from '../../shared/constants/network';
import {
WebHIDConnectedStatuses,
Expand Down Expand Up @@ -2048,14 +2055,26 @@ export const getTokenDetectionSupportNetworkByChainId = (state) => {
return BASE_DISPLAY_NAME;
case CHAIN_IDS.ZKSYNC_ERA:
return ZK_SYNC_ERA_DISPLAY_NAME;
case CHAIN_IDS.CRONOS:
return CRONOS_DISPLAY_NAME;
case CHAIN_IDS.CELO:
return CELO_DISPLAY_NAME;
case CHAIN_IDS.GNOSIS:
return GNOSIS_DISPLAY_NAME;
case CHAIN_IDS.FANTOM:
return FANTOM_DISPLAY_NAME;
case CHAIN_IDS.POLYGON_ZKEVM:
return POLYGON_ZKEVM_DISPLAY_NAME;
case CHAIN_IDS.MOONBEAM:
return MOONBEAM_DISPLAY_NAME;
case CHAIN_IDS.MOONRIVER:
return MOONRIVER_DISPLAY_NAME;
default:
return '';
}
};
/**
* To check if the chainId supports token detection,
* currently it returns true for Ethereum Mainnet, BSC, Polygon,
* Avalanche, Linea, Arbitrum, Optimism, Base, and zkSync
* Returns true if a token list is available for the current network.
*
* @param {*} state
* @returns Boolean
Expand All @@ -2074,6 +2093,13 @@ export function getIsDynamicTokenListAvailable(state) {
CHAIN_IDS.OPTIMISM,
CHAIN_IDS.BASE,
CHAIN_IDS.ZKSYNC_ERA,
CHAIN_IDS.CRONOS,
CHAIN_IDS.CELO,
CHAIN_IDS.GNOSIS,
CHAIN_IDS.FANTOM,
CHAIN_IDS.POLYGON_ZKEVM,
CHAIN_IDS.MOONBEAM,
CHAIN_IDS.MOONRIVER,
].includes(chainId);
}

Expand Down
46 changes: 44 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4098,7 +4098,7 @@ __metadata:
languageName: node
linkType: hard

"@metamask/assets-controllers@patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@npm%253A26.0.0%23~/.yarn/patches/@metamask-assets-controllers-npm-26.0.0-17c0e9432c.patch%3A%3Aversion=26.0.0&hash=cf1d54#~/.yarn/patches/@metamask-assets-controllers-patch-0f46262fea.patch":
"@metamask/assets-controllers@patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@npm%253A26.0.0%23~/.yarn/patches/@metamask-assets-controllers-npm-26.0.0-17c0e9432c.patch%3A%3Aversion=26.0.0&hash=cf1d54#~/.yarn/patches/@metamask-assets-controllers-patch-0f46262fea.patch::version=26.0.0&hash=5c145e":
version: 26.0.0
resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@npm%253A26.0.0%23~/.yarn/patches/@metamask-assets-controllers-npm-26.0.0-17c0e9432c.patch%3A%3Aversion=26.0.0&hash=cf1d54#~/.yarn/patches/@metamask-assets-controllers-patch-0f46262fea.patch::version=26.0.0&hash=5c145e"
dependencies:
Expand Down Expand Up @@ -4140,6 +4140,48 @@ __metadata:
languageName: node
linkType: hard

"@metamask/assets-controllers@patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@patch%253A@metamask/assets-controllers@npm%25253A26.0.0%2523~/.yarn/patches/@metamask-assets-controllers-npm-26.0.0-17c0e9432c.patch%253A%253Aversion=26.0.0&hash=cf1d54%23~/.yarn/patches/@metamask-assets-controllers-patch-0f46262fea.patch%3A%3Aversion=26.0.0&hash=5c145e#~/.yarn/patches/@metamask-assets-controllers-patch-7616cc1669.patch":
version: 26.0.0
resolution: "@metamask/assets-controllers@patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@patch%253A@metamask/assets-controllers@npm%25253A26.0.0%2523~/.yarn/patches/@metamask-assets-controllers-npm-26.0.0-17c0e9432c.patch%253A%253Aversion=26.0.0&hash=cf1d54%23~/.yarn/patches/@metamask-assets-controllers-patch-0f46262fea.patch%3A%3Aversion=26.0.0&hash=5c145e#~/.yarn/patches/@metamask-assets-controllers-patch-7616cc1669.patch::version=26.0.0&hash=fd4d03"
dependencies:
"@ethereumjs/util": "npm:^8.1.0"
"@ethersproject/address": "npm:^5.7.0"
"@ethersproject/bignumber": "npm:^5.7.0"
"@ethersproject/contracts": "npm:^5.7.0"
"@ethersproject/providers": "npm:^5.7.0"
"@metamask/abi-utils": "npm:^2.0.2"
"@metamask/accounts-controller": "npm:^11.0.0"
"@metamask/approval-controller": "npm:^5.1.3"
"@metamask/base-controller": "npm:^4.1.1"
"@metamask/contract-metadata": "npm:^2.4.0"
"@metamask/controller-utils": "npm:^8.0.4"
"@metamask/eth-query": "npm:^4.0.0"
"@metamask/keyring-controller": "npm:^13.0.0"
"@metamask/metamask-eth-abis": "npm:3.0.0"
"@metamask/network-controller": "npm:^17.2.1"
"@metamask/polling-controller": "npm:^5.0.1"
"@metamask/preferences-controller": "npm:^8.0.0"
"@metamask/rpc-errors": "npm:^6.2.1"
"@metamask/utils": "npm:^8.3.0"
"@types/bn.js": "npm:^5.1.5"
"@types/uuid": "npm:^8.3.0"
async-mutex: "npm:^0.2.6"
bn.js: "npm:^5.2.1"
cockatiel: "npm:^3.1.2"
lodash: "npm:^4.17.21"
multiformats: "npm:^9.5.2"
single-call-balance-checker-abi: "npm:^1.0.0"
uuid: "npm:^8.3.2"
peerDependencies:
"@metamask/accounts-controller": ^11.0.0
"@metamask/approval-controller": ^5.1.2
"@metamask/keyring-controller": ^13.0.0
"@metamask/network-controller": ^17.2.0
"@metamask/preferences-controller": ^8.0.0
checksum: 6614539d9f802a83b014469d806d34d72725d31f200914cf8db327828562a9c2559e79ff2103b8a58cf561fb00a0d0599704429b11c5e48708f557867117895e
languageName: node
linkType: hard

"@metamask/auto-changelog@npm:^2.1.0":
version: 2.6.1
resolution: "@metamask/auto-changelog@npm:2.6.1"
Expand Down Expand Up @@ -24824,7 +24866,7 @@ __metadata:
"@metamask/address-book-controller": "npm:^3.1.7"
"@metamask/announcement-controller": "npm:^6.1.0"
"@metamask/approval-controller": "npm:^6.0.0"
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@npm%253A26.0.0%23~/.yarn/patches/@metamask-assets-controllers-npm-26.0.0-17c0e9432c.patch%3A%3Aversion=26.0.0&hash=cf1d54#~/.yarn/patches/@metamask-assets-controllers-patch-0f46262fea.patch"
"@metamask/assets-controllers": "patch:@metamask/assets-controllers@patch%3A@metamask/assets-controllers@patch%253A@metamask/assets-controllers@npm%25253A26.0.0%2523~/.yarn/patches/@metamask-assets-controllers-npm-26.0.0-17c0e9432c.patch%253A%253Aversion=26.0.0&hash=cf1d54%23~/.yarn/patches/@metamask-assets-controllers-patch-0f46262fea.patch%3A%3Aversion=26.0.0&hash=5c145e#~/.yarn/patches/@metamask-assets-controllers-patch-7616cc1669.patch"
"@metamask/auto-changelog": "npm:^2.1.0"
"@metamask/base-controller": "npm:^4.1.0"
"@metamask/browser-passworder": "npm:^4.3.0"
Expand Down

0 comments on commit f3c4676

Please sign in to comment.