1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

make network-controller methods overwrite rather than merge provider state (#18127)

* make network-controller methods overwrite rather than merge provider state
This commit is contained in:
Alex Donesky 2023-03-16 15:53:29 -05:00 committed by GitHub
parent d7f7d9c706
commit d45c4ed497
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 11 deletions

View File

@ -289,7 +289,7 @@ export default class NetworkController extends EventEmitter {
rollbackToPreviousProvider() { rollbackToPreviousProvider() {
const config = this.previousProviderStore.getState(); const config = this.previousProviderStore.getState();
this.providerStore.updateState(config); this.providerStore.putState(config);
this._switchNetwork(config); this._switchNetwork(config);
} }
@ -347,7 +347,7 @@ export default class NetworkController extends EventEmitter {
* @param {boolean} isSupported - True if the EIP is supported * @param {boolean} isSupported - True if the EIP is supported
*/ */
_setNetworkEIPSupport(EIPNumber, isSupported) { _setNetworkEIPSupport(EIPNumber, isSupported) {
this.networkDetails.updateState({ this.networkDetails.putState({
EIPS: { EIPS: {
[EIPNumber]: isSupported, [EIPNumber]: isSupported,
}, },
@ -367,8 +367,8 @@ export default class NetworkController extends EventEmitter {
* @param config * @param config
*/ */
_setProviderConfig(config) { _setProviderConfig(config) {
this.previousProviderStore.updateState(this.providerStore.getState()); this.previousProviderStore.putState(this.providerStore.getState());
this.providerStore.updateState(config); this.providerStore.putState(config);
this._switchNetwork(config); this._switchNetwork(config);
} }
@ -550,7 +550,7 @@ export default class NetworkController extends EventEmitter {
)?.id; )?.id;
const newNetworkConfigurationId = oldNetworkConfigurationId || random(); const newNetworkConfigurationId = oldNetworkConfigurationId || random();
this.networkConfigurationsStore.updateState({ this.networkConfigurationsStore.putState({
...networkConfigurations, ...networkConfigurations,
[newNetworkConfigurationId]: { [newNetworkConfigurationId]: {
...newNetworkConfiguration, ...newNetworkConfiguration,

View File

@ -3218,7 +3218,6 @@ describe('NetworkController', () => {
blockExplorerUrl: blockExplorerUrl:
BUILT_IN_NETWORKS[networkType].blockExplorerUrl, BUILT_IN_NETWORKS[networkType].blockExplorerUrl,
}, },
id: 'testNetworkConfigurationId2',
}); });
}, },
); );
@ -4213,7 +4212,7 @@ describe('NetworkController', () => {
networkVersion, networkVersion,
} of INFURA_NETWORKS) { } of INFURA_NETWORKS) {
describe(`if the previous provider configuration had a type of "${networkType}"`, () => { describe(`if the previous provider configuration had a type of "${networkType}"`, () => {
it('merges the previous configuration into the current provider configuration', async () => { it('overwrites the the current provider configuration with the previous provider configuration', async () => {
await withController( await withController(
{ {
state: { state: {
@ -4295,7 +4294,6 @@ describe('NetworkController', () => {
chainId: BUILT_IN_NETWORKS[networkType].chainId, chainId: BUILT_IN_NETWORKS[networkType].chainId,
ticker: BUILT_IN_NETWORKS[networkType].ticker, ticker: BUILT_IN_NETWORKS[networkType].ticker,
nickname: '', nickname: '',
id: 'testNetworkConfigurationId1',
rpcPrefs: { rpcPrefs: {
blockExplorerUrl: blockExplorerUrl:
BUILT_IN_NETWORKS[networkType].blockExplorerUrl, BUILT_IN_NETWORKS[networkType].blockExplorerUrl,
@ -4871,7 +4869,7 @@ describe('NetworkController', () => {
} }
describe(`if the previous provider configuration had a type of "rpc"`, () => { describe(`if the previous provider configuration had a type of "rpc"`, () => {
it('merges the previous configuration into the current provider configuration', async () => { it('overwrites the the current provider configuration with the previous provider configuration', async () => {
await withController( await withController(
{ {
state: { state: {
@ -4940,7 +4938,6 @@ describe('NetworkController', () => {
rpcPrefs: { rpcPrefs: {
blockExplorerUrl: 'https://goerli.etherscan.io', blockExplorerUrl: 'https://goerli.etherscan.io',
}, },
id: 'testNetworkConfigurationId2',
}); });
await waitForLookupNetworkToComplete({ await waitForLookupNetworkToComplete({
@ -4953,8 +4950,8 @@ describe('NetworkController', () => {
type: 'rpc', type: 'rpc',
rpcUrl: 'https://mock-rpc-url-2', rpcUrl: 'https://mock-rpc-url-2',
chainId: '0x1337', chainId: '0x1337',
ticker: 'TEST2',
nickname: 'test-chain-2', nickname: 'test-chain-2',
ticker: 'TEST2',
rpcPrefs: { rpcPrefs: {
blockExplorerUrl: 'test-block-explorer-2.com', blockExplorerUrl: 'test-block-explorer-2.com',
}, },