From b04819e20da3947f0553fa4f690c6275b3f94b50 Mon Sep 17 00:00:00 2001 From: Brian Bergeron Date: Wed, 9 Oct 2024 13:02:42 -0700 Subject: [PATCH] fix token list controller switching networks --- app/core/Engine.ts | 2 +- .../@metamask+assets-controllers+31.0.0.patch | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/app/core/Engine.ts b/app/core/Engine.ts index 4a224f09191..6ad2dec9370 100644 --- a/app/core/Engine.ts +++ b/app/core/Engine.ts @@ -683,7 +683,7 @@ class Engine { // @ts-expect-error TODO: Resolve mismatch between base-controller versions. messenger: this.controllerMessenger.getRestricted({ name: 'TokenListController', - allowedActions: [], + allowedActions: [`${networkController.name}:getNetworkClientById`], allowedEvents: [`${networkController.name}:stateChange`], }), }); diff --git a/patches/@metamask+assets-controllers+31.0.0.patch b/patches/@metamask+assets-controllers+31.0.0.patch index 4ff3c0e02fc..7de2ffecb6a 100644 --- a/patches/@metamask+assets-controllers+31.0.0.patch +++ b/patches/@metamask+assets-controllers+31.0.0.patch @@ -598,6 +598,28 @@ index f7509a1..52bc67e 100644 var TokenBalancesController_default = TokenBalancesController; +diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-JUI3XNEF.js b/node_modules/@metamask/assets-controllers/dist/chunk-JUI3XNEF.js +index 44804c8..911a6e6 100644 +--- a/node_modules/@metamask/assets-controllers/dist/chunk-JUI3XNEF.js ++++ b/node_modules/@metamask/assets-controllers/dist/chunk-JUI3XNEF.js +@@ -247,10 +247,15 @@ var TokenListController = class extends _pollingcontroller.StaticIntervalPolling + }; + _onNetworkControllerStateChange = new WeakSet(); + onNetworkControllerStateChange_fn = async function(networkControllerState) { +- if (this.chainId !== networkControllerState.providerConfig.chainId) { ++ const selectedNetworkClient = this.messagingSystem.call( ++ "NetworkController:getNetworkClientById", ++ networkControllerState.selectedNetworkClientId ++ ); ++ const { chainId } = selectedNetworkClient.configuration; ++ if (this.chainId !== chainId) { + this.abortController.abort(); + this.abortController = new AbortController(); +- this.chainId = networkControllerState.providerConfig.chainId; ++ this.chainId = chainId; + if (this.state.preventPollingOnNetworkRestart) { + this.clearingTokenListData(); + } else { diff --git a/node_modules/@metamask/assets-controllers/dist/chunk-QFDTOEYR.js b/node_modules/@metamask/assets-controllers/dist/chunk-QFDTOEYR.js index 5335fa5..ae37683 100644 --- a/node_modules/@metamask/assets-controllers/dist/chunk-QFDTOEYR.js