1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-25 20:02:58 +01:00

use network did change instead of state update for assetsContractController (#18629)

This commit is contained in:
Brad Decker 2023-04-18 11:33:12 -05:00 committed by GitHub
parent 1fe28ee15a
commit 7fa7c05586
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -348,18 +348,29 @@ export default class MetamaskController extends EventEmitter {
{ {
onPreferencesStateChange: (listener) => onPreferencesStateChange: (listener) =>
this.preferencesController.store.subscribe(listener), this.preferencesController.store.subscribe(listener),
onNetworkStateChange: (cb) => { // This handler is misnamed, and is a known issue that will be resolved
this.networkController.store.subscribe((networkState) => { // by planned refactors. It should be onNetworkDidChange which happens
const modifiedNetworkState = { // AFTER the provider in the network controller is updated to reflect
...networkState, // the new state of the network controller. In #18041 we changed this
providerConfig: { // handler to be triggered by the change in the network state because
...networkState.provider, // that is what the handler name implies, but this triggers too soon
chainId: hexToDecimal(networkState.provider.chainId), // causing the provider of the AssetsContractController to trail the
}, // network provider by one update.
}; onNetworkStateChange: (cb) =>
return cb(modifiedNetworkState); networkControllerMessenger.subscribe(
}); NetworkControllerEventType.NetworkDidChange,
}, () => {
const networkState = this.networkController.store.getState();
const modifiedNetworkState = {
...networkState,
providerConfig: {
...networkState.provider,
chainId: hexToDecimal(networkState.provider.chainId),
},
};
return cb(modifiedNetworkState);
},
),
}, },
{ {
provider: this.provider, provider: this.provider,