-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Upgrade assets controllers to 43 with multichain polling for token lists + detection #28447
Changes from all commits
f024224
cfb46d1
2f36b23
25f5ed0
6c216f8
2822c58
3d5323a
ae198fb
e1f3843
b090b3c
38fc254
6338a00
6b22521
5206a35
757d880
abf8e11
c662098
8f1cfb1
1411c2a
05554a3
729d07d
21fcda3
8b6391f
b635ab8
ec38722
79a451f
979a3af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2606,24 +2606,12 @@ export default class MetamaskController extends EventEmitter { | |
this.accountTrackerController.start(); | ||
this.txController.startIncomingTransactionPolling(); | ||
this.tokenDetectionController.enable(); | ||
|
||
const preferencesControllerState = this.preferencesController.state; | ||
|
||
if (this.#isTokenListPollingRequired(preferencesControllerState)) { | ||
this.tokenListController.start(); | ||
} | ||
} | ||
|
||
stopNetworkRequests() { | ||
this.accountTrackerController.stop(); | ||
this.txController.stopIncomingTransactionPolling(); | ||
this.tokenDetectionController.disable(); | ||
|
||
const preferencesControllerState = this.preferencesController.state; | ||
|
||
if (this.#isTokenListPollingRequired(preferencesControllerState)) { | ||
this.tokenListController.stop(); | ||
} | ||
} | ||
|
||
resetStates(resetMethods) { | ||
|
@@ -3243,6 +3231,7 @@ export default class MetamaskController extends EventEmitter { | |
currencyRateController, | ||
tokenDetectionController, | ||
ensController, | ||
tokenListController, | ||
gasFeeController, | ||
metaMetricsController, | ||
networkController, | ||
|
@@ -4045,6 +4034,19 @@ export default class MetamaskController extends EventEmitter { | |
tokenRatesController, | ||
), | ||
|
||
tokenDetectionStartPolling: tokenDetectionController.startPolling.bind( | ||
tokenDetectionController, | ||
), | ||
tokenDetectionStopPollingByPollingToken: | ||
tokenDetectionController.stopPollingByPollingToken.bind( | ||
tokenDetectionController, | ||
), | ||
|
||
tokenListStartPolling: | ||
tokenListController.startPolling.bind(tokenListController), | ||
tokenListStopPollingByPollingToken: | ||
tokenListController.stopPollingByPollingToken.bind(tokenListController), | ||
|
||
// GasFeeController | ||
gasFeeStartPollingByNetworkClientId: | ||
gasFeeController.startPollingByNetworkClientId.bind(gasFeeController), | ||
|
@@ -4408,6 +4410,7 @@ export default class MetamaskController extends EventEmitter { | |
if (balance === '0x0') { | ||
// This account has no balance, so check for tokens | ||
await this.tokenDetectionController.detectTokens({ | ||
chainIds: [chainId], | ||
selectedAddress: address, | ||
}); | ||
|
||
|
@@ -6676,6 +6679,8 @@ export default class MetamaskController extends EventEmitter { | |
this.gasFeeController.stopAllPolling(); | ||
this.currencyRateController.stopAllPolling(); | ||
this.tokenRatesController.stopAllPolling(); | ||
this.tokenDetectionController.stopAllPolling(); | ||
this.tokenListController.stopAllPolling(); | ||
this.appStateController.clearPollingTokens(); | ||
} catch (error) { | ||
console.error(error); | ||
|
@@ -7211,15 +7216,6 @@ export default class MetamaskController extends EventEmitter { | |
} | ||
|
||
this.tokenListController.updatePreventPollingOnNetworkRestart(!newEnabled); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've never understood the purpose of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw this same thing and had similar thoughts. Sounds good |
||
|
||
if (newEnabled) { | ||
log.debug('Started token list controller polling'); | ||
this.tokenListController.start(); | ||
} else { | ||
log.debug('Stopped token list controller polling'); | ||
this.tokenListController.clearingTokenListData(); | ||
this.tokenListController.stop(); | ||
} | ||
} | ||
|
||
#isTokenListPollingRequired(preferencesControllerState) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MetaMask/core#4928