Skip to content

Commit

Permalink
make network-controller methods overwrite rather than merge provider …
Browse files Browse the repository at this point in the history
…state (#18127)

* make network-controller methods overwrite rather than merge provider state
  • Loading branch information
adonesky1 authored Mar 16, 2023
1 parent d7f7d9c commit d45c4ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
10 changes: 5 additions & 5 deletions app/scripts/controllers/network/network-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export default class NetworkController extends EventEmitter {

rollbackToPreviousProvider() {
const config = this.previousProviderStore.getState();
this.providerStore.updateState(config);
this.providerStore.putState(config);
this._switchNetwork(config);
}

Expand Down Expand Up @@ -347,7 +347,7 @@ export default class NetworkController extends EventEmitter {
* @param {boolean} isSupported - True if the EIP is supported
*/
_setNetworkEIPSupport(EIPNumber, isSupported) {
this.networkDetails.updateState({
this.networkDetails.putState({
EIPS: {
[EIPNumber]: isSupported,
},
Expand All @@ -367,8 +367,8 @@ export default class NetworkController extends EventEmitter {
* @param config
*/
_setProviderConfig(config) {
this.previousProviderStore.updateState(this.providerStore.getState());
this.providerStore.updateState(config);
this.previousProviderStore.putState(this.providerStore.getState());
this.providerStore.putState(config);
this._switchNetwork(config);
}

Expand Down Expand Up @@ -550,7 +550,7 @@ export default class NetworkController extends EventEmitter {
)?.id;

const newNetworkConfigurationId = oldNetworkConfigurationId || random();
this.networkConfigurationsStore.updateState({
this.networkConfigurationsStore.putState({
...networkConfigurations,
[newNetworkConfigurationId]: {
...newNetworkConfiguration,
Expand Down
9 changes: 3 additions & 6 deletions app/scripts/controllers/network/network-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3218,7 +3218,6 @@ describe('NetworkController', () => {
blockExplorerUrl:
BUILT_IN_NETWORKS[networkType].blockExplorerUrl,
},
id: 'testNetworkConfigurationId2',
});
},
);
Expand Down Expand Up @@ -4213,7 +4212,7 @@ describe('NetworkController', () => {
networkVersion,
} of INFURA_NETWORKS) {
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(
{
state: {
Expand Down Expand Up @@ -4295,7 +4294,6 @@ describe('NetworkController', () => {
chainId: BUILT_IN_NETWORKS[networkType].chainId,
ticker: BUILT_IN_NETWORKS[networkType].ticker,
nickname: '',
id: 'testNetworkConfigurationId1',
rpcPrefs: {
blockExplorerUrl:
BUILT_IN_NETWORKS[networkType].blockExplorerUrl,
Expand Down Expand Up @@ -4871,7 +4869,7 @@ describe('NetworkController', () => {
}

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(
{
state: {
Expand Down Expand Up @@ -4940,7 +4938,6 @@ describe('NetworkController', () => {
rpcPrefs: {
blockExplorerUrl: 'https://goerli.etherscan.io',
},
id: 'testNetworkConfigurationId2',
});

await waitForLookupNetworkToComplete({
Expand All @@ -4953,8 +4950,8 @@ describe('NetworkController', () => {
type: 'rpc',
rpcUrl: 'https://mock-rpc-url-2',
chainId: '0x1337',
ticker: 'TEST2',
nickname: 'test-chain-2',
ticker: 'TEST2',
rpcPrefs: {
blockExplorerUrl: 'test-block-explorer-2.com',
},
Expand Down

0 comments on commit d45c4ed

Please sign in to comment.