From b106bbf1d9accc39a27f2deb28a04a5557e8888b Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Wed, 22 Feb 2023 10:43:37 -0700 Subject: [PATCH] Remove extraneous methods from NetworkController (#17522) The network controller has a variety of methods that just retrieve controller state. These methods are not necessary because controller state is already part of the public API of the controller and can be accessed directly. These methods are: - getCurrentChainId - getCurrentRpcUrl - getNetworkIdentifier - getNetworkState - getProviderConfig - isNetworkLoading This is part of a larger effort to normalize the API of both network controllers, to make them easier to merge. --- app/scripts/background.js | 5 +- app/scripts/controllers/metametrics.test.js | 25 ++-- .../controllers/network/network-controller.js | 47 ++------ .../network/network-controller.test.js | 107 +++++++++++++++++- app/scripts/controllers/preferences.test.js | 14 ++- app/scripts/metamask-controller.js | 100 ++++++++-------- 6 files changed, 182 insertions(+), 116 deletions(-) diff --git a/app/scripts/background.js b/app/scripts/background.js index d420929a2..65ed6e147 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -439,9 +439,8 @@ export function setupController(initState, initLangCode, overrides) { }); setupEnsIpfsResolver({ - getCurrentChainId: controller.networkController.getCurrentChainId.bind( - controller.networkController, - ), + getCurrentChainId: () => + controller.networkController.store.getState().provider.chainId, getIpfsGateway: controller.preferencesController.getIpfsGateway.bind( controller.preferencesController, ), diff --git a/app/scripts/controllers/metametrics.test.js b/app/scripts/controllers/metametrics.test.js index fc5ce0f6d..fde46385e 100644 --- a/app/scripts/controllers/metametrics.test.js +++ b/app/scripts/controllers/metametrics.test.js @@ -64,23 +64,24 @@ const DEFAULT_PAGE_PROPERTIES = { ...DEFAULT_SHARED_PROPERTIES, }; -function getMockNetworkController( - chainId = FAKE_CHAIN_ID, - provider = { type: NETWORK_TYPES.MAINNET }, -) { - let networkStore = { chainId, provider }; +function getMockNetworkController() { + let state = { + provider: { + type: NETWORK_TYPES.GOERLI, + chainId: FAKE_CHAIN_ID, + }, + network: 'loading', + }; const on = sinon.stub().withArgs(NETWORK_EVENTS.NETWORK_DID_CHANGE); const updateState = (newState) => { - networkStore = { ...networkStore, ...newState }; + state = { ...state, ...newState }; on.getCall(0).args[1](); }; return { store: { - getState: () => networkStore, + getState: () => state, updateState, }, - getCurrentChainId: () => networkStore.chainId, - getNetworkIdentifier: () => networkStore.provider.type, on, }; } @@ -132,8 +133,8 @@ function getMetaMetricsController({ } = {}) { return new MetaMetricsController({ segment: segmentInstance || segment, - getCurrentChainId: - networkController.getCurrentChainId.bind(networkController), + getCurrentChainId: () => + networkController.store.getState().provider.chainId, onNetworkDidChange: networkController.on.bind( networkController, NETWORK_EVENTS.NETWORK_DID_CHANGE, @@ -206,8 +207,8 @@ describe('MetaMetricsController', function () { networkController.store.updateState({ provider: { type: 'NEW_NETWORK', + chainId: '0xaab', }, - chainId: '0xaab', }); assert.strictEqual(metaMetricsController.chainId, '0xaab'); }); diff --git a/app/scripts/controllers/network/network-controller.js b/app/scripts/controllers/network/network-controller.js index 25e90378d..2595ae99d 100644 --- a/app/scripts/controllers/network/network-controller.js +++ b/app/scripts/controllers/network/network-controller.js @@ -140,7 +140,7 @@ export default class NetworkController extends EventEmitter { } async initializeProvider() { - const { type, rpcUrl, chainId } = this.getProviderConfig(); + const { type, rpcUrl, chainId } = this.providerStore.getState(); this._configureProvider({ type, rpcUrl, chainId }); await this.lookupNetwork(); } @@ -172,14 +172,6 @@ export default class NetworkController extends EventEmitter { return supportsEIP1559; } - getNetworkState() { - return this.networkStore.getState(); - } - - isNetworkLoading() { - return this.getNetworkState() === 'loading'; - } - async lookupNetwork() { // Prevent firing when provider is not defined. if (!this._provider) { @@ -189,23 +181,19 @@ export default class NetworkController extends EventEmitter { return; } - // NOTE: This will never happen in practice because you can't pass null or - // undefined for chainId to setRpcTarget, and all of the known networks have - // a chain ID - const chainId = this.getCurrentChainId(); + const { chainId } = this.providerStore.getState(); if (!chainId) { log.warn( 'NetworkController - lookupNetwork aborted due to missing chainId', ); this._setNetworkState('loading'); - // keep network details in sync with network state this._clearNetworkDetails(); return; } // Ping the RPC endpoint so we can confirm that it works - const initialNetwork = this.getNetworkState(); - const { type } = this.getProviderConfig(); + const initialNetwork = this.networkStore.getState(); + const { type } = this.providerStore.getState(); const isInfura = INFURA_PROVIDER_TYPES.includes(type); if (isInfura) { @@ -221,7 +209,7 @@ export default class NetworkController extends EventEmitter { } catch (error) { networkVersionError = error; } - if (initialNetwork !== this.getNetworkState()) { + if (initialNetwork !== this.networkStore.getState()) { return; } @@ -236,16 +224,6 @@ export default class NetworkController extends EventEmitter { } } - getCurrentChainId() { - const { type, chainId: configChainId } = this.getProviderConfig(); - return BUILT_IN_NETWORKS[type]?.chainId || configChainId; - } - - getCurrentRpcUrl() { - const { rpcUrl } = this.getProviderConfig(); - return rpcUrl; - } - setRpcTarget(rpcUrl, chainId, ticker = 'ETH', nickname = '', rpcPrefs) { assert.ok( isPrefixedFormattedHexString(chainId), @@ -286,7 +264,7 @@ export default class NetworkController extends EventEmitter { } resetConnection() { - this._setProviderConfig(this.getProviderConfig()); + this._setProviderConfig(this.providerStore.getState()); } rollbackToPreviousProvider() { @@ -295,17 +273,6 @@ export default class NetworkController extends EventEmitter { this._switchNetwork(config); } - getProviderConfig() { - return this.providerStore.getState(); - } - - getNetworkIdentifier() { - const provider = this.providerStore.getState(); - return provider.type === NETWORK_TYPES.RPC - ? provider.rpcUrl - : provider.type; - } - // // Private // @@ -380,7 +347,7 @@ export default class NetworkController extends EventEmitter { * @param config */ _setProviderConfig(config) { - this.previousProviderStore.updateState(this.getProviderConfig()); + this.previousProviderStore.updateState(this.providerStore.getState()); this.providerStore.updateState(config); this._switchNetwork(config); } diff --git a/app/scripts/controllers/network/network-controller.test.js b/app/scripts/controllers/network/network-controller.test.js index b86298692..939d9aa07 100644 --- a/app/scripts/controllers/network/network-controller.test.js +++ b/app/scripts/controllers/network/network-controller.test.js @@ -580,6 +580,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID + // of the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -606,6 +609,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID + // of the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -631,6 +637,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID + // of the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -650,6 +659,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID + // of the network selected, it just needs to exist + chainId: '0x9999999', }, }, networkDetails: { @@ -1120,6 +1132,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID + // of the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -1167,6 +1182,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID + // of the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -1228,6 +1246,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID + // of the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -1266,6 +1287,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID + // of the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -1330,6 +1354,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID + // of the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -1369,6 +1396,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -1400,6 +1430,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -1444,6 +1477,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, networkDetails: { EIPS: {}, @@ -1471,6 +1507,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, networkDetails: { EIPS: {}, @@ -1503,6 +1542,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, networkDetails: { EIPS: {}, @@ -1560,6 +1602,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -1673,6 +1718,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3124,6 +3172,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3149,6 +3200,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3183,6 +3237,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3226,6 +3283,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3252,6 +3312,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3276,6 +3339,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3301,6 +3367,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3326,6 +3395,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3351,6 +3423,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3679,6 +3754,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID + // of the network selected, it just needs to exist + chainId: '0x999', }, }, }, @@ -3716,7 +3794,7 @@ describe('NetworkController', () => { expect(controller.store.getState().provider).toStrictEqual({ type: networkType, rpcUrl: 'https://mock-rpc-url', - chainId: '0x1337', + chainId: '0x999', ticker: 'ETH', nickname: '', rpcPrefs: undefined, @@ -3731,6 +3809,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3774,6 +3855,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3827,6 +3911,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3886,6 +3973,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3930,6 +4020,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -3971,6 +4064,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -4014,6 +4110,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -4058,6 +4157,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, @@ -4103,6 +4205,9 @@ describe('NetworkController', () => { state: { provider: { type: networkType, + // NOTE: This doesn't need to match the logical chain ID of + // the network selected, it just needs to exist + chainId: '0x9999999', }, }, }, diff --git a/app/scripts/controllers/preferences.test.js b/app/scripts/controllers/preferences.test.js index b0b232c65..7c4e2d110 100644 --- a/app/scripts/controllers/preferences.test.js +++ b/app/scripts/controllers/preferences.test.js @@ -19,7 +19,15 @@ describe('preferences controller', function () { const networkControllerProviderConfig = { getAccounts: () => undefined, }; - network = new NetworkController({ infuraProjectId: 'foo' }); + network = new NetworkController({ + infuraProjectId: 'foo', + state: { + provider: { + type: 'mainnet', + chainId: currentChainId, + }, + }, + }); network.initializeProvider(networkControllerProviderConfig); provider = network.getProviderAndBlockTracker().provider; const tokenListMessenger = new ControllerMessenger().getRestricted({ @@ -36,10 +44,6 @@ describe('preferences controller', function () { sandbox .stub(network, '_getLatestBlock') .callsFake(() => Promise.resolve({})); - sandbox.stub(network, 'getCurrentChainId').callsFake(() => currentChainId); - sandbox - .stub(network, 'getProviderConfig') - .callsFake(() => ({ type: 'mainnet' })); preferencesController = new PreferencesController({ initLangCode: 'en_US', diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index eaf78c97b..25ad328cd 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -75,7 +75,7 @@ import { GAS_DEV_API_BASE_URL, SWAPS_CLIENT_ID, } from '../../shared/constants/swaps'; -import { CHAIN_IDS } from '../../shared/constants/network'; +import { CHAIN_IDS, NETWORK_TYPES } from '../../shared/constants/network'; import { HardwareDeviceNames, HardwareKeyringTypes, @@ -275,7 +275,9 @@ export default class MetamaskController extends EventEmitter { }); this.tokenListController = new TokenListController({ - chainId: hexToDecimal(this.networkController.getCurrentChainId()), + chainId: hexToDecimal( + this.networkController.store.getState().provider.chainId, + ), preventPollingOnNetworkRestart: initState.TokenListController ? initState.TokenListController.preventPollingOnNetworkRestart : true, @@ -440,12 +442,13 @@ export default class MetamaskController extends EventEmitter { this.networkController, NETWORK_EVENTS.NETWORK_DID_CHANGE, ), - getNetworkIdentifier: this.networkController.getNetworkIdentifier.bind( - this.networkController, - ), - getCurrentChainId: this.networkController.getCurrentChainId.bind( - this.networkController, - ), + getNetworkIdentifier: () => { + const { type, rpcUrl } = + this.networkController.store.getState().provider; + return type === NETWORK_TYPES.RPC ? rpcUrl : type; + }, + getCurrentChainId: () => + this.networkController.store.getState().provider.chainId, version: this.platform.getVersion(), environment: process.env.METAMASK_ENVIRONMENT, extension: this.extension, @@ -485,13 +488,13 @@ export default class MetamaskController extends EventEmitter { legacyAPIEndpoint: `${gasApiBaseUrl}/networks//gasPrices`, EIP1559APIEndpoint: `${gasApiBaseUrl}/networks//suggestedGasFees`, getCurrentNetworkLegacyGasAPICompatibility: () => { - const chainId = this.networkController.getCurrentChainId(); + const { chainId } = this.networkController.store.getState().provider; return process.env.IN_TEST || chainId === CHAIN_IDS.MAINNET; }, getChainId: () => { return process.env.IN_TEST ? CHAIN_IDS.MAINNET - : this.networkController.getCurrentChainId(); + : this.networkController.store.getState().provider.chainId; }, }); @@ -583,9 +586,8 @@ export default class MetamaskController extends EventEmitter { this.ensController = new EnsController({ provider: this.provider, - getCurrentChainId: this.networkController.getCurrentChainId.bind( - this.networkController, - ), + getCurrentChainId: () => + this.networkController.store.getState().provider.chainId, onNetworkDidChange: this.networkController.on.bind( this.networkController, NETWORK_EVENTS.NETWORK_DID_CHANGE, @@ -602,9 +604,8 @@ export default class MetamaskController extends EventEmitter { this.networkController, NETWORK_EVENTS.NETWORK_DID_CHANGE, ), - getCurrentChainId: this.networkController.getCurrentChainId.bind( - this.networkController, - ), + getCurrentChainId: () => + this.networkController.store.getState().provider.chainId, preferencesController: this.preferencesController, onboardingController: this.onboardingController, initState: initState.IncomingTransactionsController, @@ -614,12 +615,13 @@ export default class MetamaskController extends EventEmitter { this.accountTracker = new AccountTracker({ provider: this.provider, blockTracker: this.blockTracker, - getCurrentChainId: this.networkController.getCurrentChainId.bind( - this.networkController, - ), - getNetworkIdentifier: this.networkController.getNetworkIdentifier.bind( - this.networkController, - ), + getCurrentChainId: () => + this.networkController.store.getState().provider.chainId, + getNetworkIdentifier: () => { + const { type, rpcUrl } = + this.networkController.store.getState().provider; + return type === NETWORK_TYPES.RPC ? rpcUrl : type; + }, preferencesController: this.preferencesController, onboardingController: this.onboardingController, }); @@ -647,9 +649,8 @@ export default class MetamaskController extends EventEmitter { this.cachedBalancesController = new CachedBalancesController({ accountTracker: this.accountTracker, - getCurrentChainId: this.networkController.getCurrentChainId.bind( - this.networkController, - ), + getCurrentChainId: () => + this.networkController.store.getState().provider.chainId, initState: initState.CachedBalancesController, }); @@ -903,21 +904,18 @@ export default class MetamaskController extends EventEmitter { initState: initState.TransactionController || initState.TransactionManager, getPermittedAccounts: this.getPermittedAccounts.bind(this), - getProviderConfig: this.networkController.getProviderConfig.bind( - this.networkController, - ), + getProviderConfig: () => this.networkController.store.getState().provider, getCurrentNetworkEIP1559Compatibility: this.networkController.getEIP1559Compatibility.bind( this.networkController, ), getCurrentAccountEIP1559Compatibility: this.getCurrentAccountEIP1559Compatibility.bind(this), - getNetworkState: () => this.networkController.networkStore.getState(), + getNetworkState: () => this.networkController.store.getState().network, onNetworkStateChange: (listener) => this.networkController.networkStore.subscribe(listener), - getCurrentChainId: this.networkController.getCurrentChainId.bind( - this.networkController, - ), + getCurrentChainId: () => + this.networkController.store.getState().provider.chainId, preferencesStore: this.preferencesController.store, txHistoryLimit: 60, signTransaction: this.keyringController.signTransaction.bind( @@ -1039,7 +1037,7 @@ export default class MetamaskController extends EventEmitter { }); this.networkController.on(NETWORK_EVENTS.NETWORK_DID_CHANGE, async () => { - const { ticker } = this.networkController.getProviderConfig(); + const { ticker } = this.networkController.store.getState().provider; try { await this.currencyRateController.setNativeCurrency(ticker); } catch (error) { @@ -1072,9 +1070,8 @@ export default class MetamaskController extends EventEmitter { ), }); this.typedMessageManager = new TypedMessageManager({ - getCurrentChainId: this.networkController.getCurrentChainId.bind( - this.networkController, - ), + getCurrentChainId: () => + this.networkController.store.getState().provider.chainId, metricsEvent: this.metaMetricsController.trackEvent.bind( this.metaMetricsController, ), @@ -1087,13 +1084,10 @@ export default class MetamaskController extends EventEmitter { ), networkController: this.networkController, provider: this.provider, - getProviderConfig: this.networkController.getProviderConfig.bind( - this.networkController, - ), + getProviderConfig: () => this.networkController.store.getState().provider, getTokenRatesState: () => this.tokenRatesController.state, - getCurrentChainId: this.networkController.getCurrentChainId.bind( - this.networkController, - ), + getCurrentChainId: () => + this.networkController.store.getState().provider.chainId, getEIP1559GasFeeEstimates: this.gasFeeController.fetchGasFeeEstimates.bind(this.gasFeeController), }); @@ -1110,9 +1104,7 @@ export default class MetamaskController extends EventEmitter { return cb(modifiedNetworkState); }); }, - getNetwork: this.networkController.getNetworkState.bind( - this.networkController, - ), + getNetwork: () => this.networkController.store.getState().network, getNonceLock: this.txController.nonceTracker.getNonceLock.bind( this.txController.nonceTracker, ), @@ -1630,7 +1622,7 @@ export default class MetamaskController extends EventEmitter { updatePublicConfigStore(this.getState()); function updatePublicConfigStore(memState) { - const chainId = networkController.getCurrentChainId(); + const { chainId } = networkController.store.getState().provider; if (memState.network !== 'loading') { publicConfigStore.putState(selectPublicState(chainId, memState)); } @@ -1676,7 +1668,7 @@ export default class MetamaskController extends EventEmitter { getProviderNetworkState(memState) { const { network } = memState || this.getState(); return { - chainId: this.networkController.getCurrentChainId(), + chainId: this.networkController.store.getState().provider.chainId, networkVersion: network, }; } @@ -2710,7 +2702,7 @@ export default class MetamaskController extends EventEmitter { this.appStateController.setTrezorModel(model); } - keyring.network = this.networkController.getProviderConfig().type; + keyring.network = this.networkController.store.getState().provider.type; return keyring; } @@ -4020,12 +4012,10 @@ export default class MetamaskController extends EventEmitter { ); }, findCustomRpcBy: this.findCustomRpcBy.bind(this), - getCurrentChainId: this.networkController.getCurrentChainId.bind( - this.networkController, - ), - getCurrentRpcUrl: this.networkController.getCurrentRpcUrl.bind( - this.networkController, - ), + getCurrentChainId: () => + this.networkController.store.getState().provider.chainId, + getCurrentRpcUrl: + this.networkController.store.getState().provider.rpcUrl, setProviderType: this.networkController.setProviderType.bind( this.networkController, ), @@ -4693,7 +4683,7 @@ export default class MetamaskController extends EventEmitter { this.preferencesController.store.getState(); const chainId = Number( - hexToDecimal(this.networkController.getCurrentChainId()), + hexToDecimal(this.networkController.store.getState().provider.chainId), ); if (transactionSecurityCheckEnabled) {