-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Upgrade assets controllers to 43 with multichain polling for to…
…ken lists + detection (#28447) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This upgrades assets controllers to version 43. It allows us to poll for token lists and token detection across chains. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28447?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Onboard to metamask 2. Verify your erc20 tokens are detected 3. Click a token 4. Verify data on token details page 5. Switch networks 6. Repeat steps 2-4 ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension 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. --------- Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
- Loading branch information
1 parent
1700422
commit a597a8e
Showing
23 changed files
with
516 additions
and
184 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
...s-controllers-npm-42.0.0-57b3d695bb.patch → ...s-controllers-npm-43.1.1-c223d56176.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.yarn/patches/@metamask-assets-controllers-patch-9e00573eb4.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
diff --git a/dist/TokenDetectionController.cjs b/dist/TokenDetectionController.cjs | ||
index ab23c95d667357db365f925c4c4acce4736797f8..8fd5efde7a3c24080f8a43f79d10300e8c271245 100644 | ||
--- a/dist/TokenDetectionController.cjs | ||
+++ b/dist/TokenDetectionController.cjs | ||
@@ -204,13 +204,10 @@ class TokenDetectionController extends (0, polling_controller_1.StaticIntervalPo | ||
// Try detecting tokens via Account API first if conditions allow | ||
if (supportedNetworks && chainsToDetectUsingAccountAPI.length > 0) { | ||
const apiResult = await __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_attemptAccountAPIDetection).call(this, chainsToDetectUsingAccountAPI, addressToDetect, supportedNetworks); | ||
- // If API succeeds and no chains are left for RPC detection, we can return early | ||
- if (apiResult?.result === 'success' && | ||
- chainsToDetectUsingRpc.length === 0) { | ||
- return; | ||
+ // If the account API call failed, have those chains fall back to RPC detection | ||
+ if (apiResult?.result === 'failed') { | ||
+ __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_addChainsToRpcDetection).call(this, chainsToDetectUsingRpc, chainsToDetectUsingAccountAPI, clientNetworks); | ||
} | ||
- // If API fails or chainsToDetectUsingRpc still has items, add chains to RPC detection | ||
- __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_addChainsToRpcDetection).call(this, chainsToDetectUsingRpc, chainsToDetectUsingAccountAPI, clientNetworks); | ||
} | ||
// Proceed with RPC detection if there are chains remaining in chainsToDetectUsingRpc | ||
if (chainsToDetectUsingRpc.length > 0) { | ||
@@ -446,8 +443,7 @@ async function _TokenDetectionController_addDetectedTokensViaAPI({ selectedAddre | ||
const tokenBalancesByChain = await __classPrivateFieldGet(this, _TokenDetectionController_accountsAPI, "f") | ||
.getMultiNetworksBalances(selectedAddress, chainIds, supportedNetworks) | ||
.catch(() => null); | ||
- if (!tokenBalancesByChain || | ||
- Object.keys(tokenBalancesByChain).length === 0) { | ||
+ if (tokenBalancesByChain === null) { | ||
return { result: 'failed' }; | ||
} | ||
// Process each chain ID individually | ||
diff --git a/dist/TokenDetectionController.mjs b/dist/TokenDetectionController.mjs | ||
index f75eb5c2c74f2a9d15a79760985111171dc938e1..ebc30bb915cc39dabf49f9e0da84a7948ae1ed48 100644 | ||
--- a/dist/TokenDetectionController.mjs | ||
+++ b/dist/TokenDetectionController.mjs | ||
@@ -205,13 +205,10 @@ export class TokenDetectionController extends StaticIntervalPollingController() | ||
// Try detecting tokens via Account API first if conditions allow | ||
if (supportedNetworks && chainsToDetectUsingAccountAPI.length > 0) { | ||
const apiResult = await __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_attemptAccountAPIDetection).call(this, chainsToDetectUsingAccountAPI, addressToDetect, supportedNetworks); | ||
- // If API succeeds and no chains are left for RPC detection, we can return early | ||
- if (apiResult?.result === 'success' && | ||
- chainsToDetectUsingRpc.length === 0) { | ||
- return; | ||
+ // If the account API call failed, have those chains fall back to RPC detection | ||
+ if (apiResult?.result === 'failed') { | ||
+ __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_addChainsToRpcDetection).call(this, chainsToDetectUsingRpc, chainsToDetectUsingAccountAPI, clientNetworks); | ||
} | ||
- // If API fails or chainsToDetectUsingRpc still has items, add chains to RPC detection | ||
- __classPrivateFieldGet(this, _TokenDetectionController_instances, "m", _TokenDetectionController_addChainsToRpcDetection).call(this, chainsToDetectUsingRpc, chainsToDetectUsingAccountAPI, clientNetworks); | ||
} | ||
// Proceed with RPC detection if there are chains remaining in chainsToDetectUsingRpc | ||
if (chainsToDetectUsingRpc.length > 0) { | ||
@@ -446,8 +443,7 @@ async function _TokenDetectionController_addDetectedTokensViaAPI({ selectedAddre | ||
const tokenBalancesByChain = await __classPrivateFieldGet(this, _TokenDetectionController_accountsAPI, "f") | ||
.getMultiNetworksBalances(selectedAddress, chainIds, supportedNetworks) | ||
.catch(() => null); | ||
- if (!tokenBalancesByChain || | ||
- Object.keys(tokenBalancesByChain).length === 0) { | ||
+ if (tokenBalancesByChain === null) { | ||
return { result: 'failed' }; | ||
} | ||
// Process each chain ID individually |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.