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

Make rollbackToPreviousProvider async (#18599)

The network controller method `rollbackToPreviousProvider` is now
async. It will resolve when the network switch has completed.

Relates to https://github.com/MetaMask/metamask-extension/issues/18587
This commit is contained in:
Mark Stacey 2023-04-15 10:31:59 -02:30 committed by GitHub
parent 1406885115
commit 73efd2edeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 33 deletions

View File

@ -5761,8 +5761,8 @@ describe('NetworkController', () => {
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
expect(controller.store.getState().provider).toStrictEqual({
@ -5827,8 +5827,8 @@ describe('NetworkController', () => {
const networkWillChange = await waitForPublishedEvents({
messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.NetworkWillChange,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
@ -5891,6 +5891,8 @@ describe('NetworkController', () => {
// happens before networkDidChange
count: 1,
operation: () => {
// Intentionally not awaited because we want to check state
// while this operation is in-progress
controller.rollbackToPreviousProvider();
},
});
@ -5959,6 +5961,8 @@ describe('NetworkController', () => {
// happens before networkDidChange
count: 1,
operation: () => {
// Intentionally not awaited because we want to check state
// while this operation is in-progress
controller.rollbackToPreviousProvider();
},
});
@ -6015,8 +6019,8 @@ describe('NetworkController', () => {
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
@ -6077,8 +6081,8 @@ describe('NetworkController', () => {
controller.getProviderAndBlockTracker();
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
const { provider: providerAfter } =
@ -6138,8 +6142,8 @@ describe('NetworkController', () => {
const networkDidChange = await waitForPublishedEvents({
messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.NetworkDidChange,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
expect(networkDidChange).toBeTruthy();
@ -6203,7 +6207,7 @@ describe('NetworkController', () => {
await waitForLookupNetworkToComplete({
controller,
operation: async () => {
controller.rollbackToPreviousProvider();
await controller.rollbackToPreviousProvider();
},
});
@ -6266,8 +6270,8 @@ describe('NetworkController', () => {
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
expect(controller.store.getState().networkStatus).toBe(
@ -6323,8 +6327,8 @@ describe('NetworkController', () => {
await waitForLookupNetworkToComplete({
controller,
numberOfNetworkDetailsChanges: 2,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
expect(controller.store.getState().networkDetails).toStrictEqual({
@ -6408,8 +6412,8 @@ describe('NetworkController', () => {
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
expect(controller.store.getState().provider).toStrictEqual({
@ -6475,8 +6479,8 @@ describe('NetworkController', () => {
const networkWillChange = await waitForPublishedEvents({
messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.NetworkWillChange,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
@ -6532,6 +6536,8 @@ describe('NetworkController', () => {
// happens before networkDidChange
count: 1,
operation: () => {
// Intentionally not awaited because we want to check state
// while this operation is in-progress
controller.rollbackToPreviousProvider();
},
});
@ -6595,6 +6601,8 @@ describe('NetworkController', () => {
// happens before networkDidChange
count: 1,
operation: () => {
// Intentionally not awaited because we want to check state
// while this operation is in-progress
controller.rollbackToPreviousProvider();
},
});
@ -6646,8 +6654,8 @@ describe('NetworkController', () => {
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
@ -6703,8 +6711,8 @@ describe('NetworkController', () => {
controller.getProviderAndBlockTracker();
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
const { provider: providerAfter } =
@ -6759,8 +6767,8 @@ describe('NetworkController', () => {
const networkDidChange = await waitForPublishedEvents({
messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.NetworkDidChange,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
expect(networkDidChange).toBeTruthy();
@ -6814,8 +6822,8 @@ describe('NetworkController', () => {
const infuraIsUnblocked = await waitForPublishedEvents({
messenger: unrestrictedMessenger,
eventType: NetworkControllerEventType.InfuraIsUnblocked,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
@ -6871,8 +6879,8 @@ describe('NetworkController', () => {
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
expect(controller.store.getState().networkStatus).toBe('unknown');
@ -6925,8 +6933,8 @@ describe('NetworkController', () => {
await waitForLookupNetworkToComplete({
controller,
operation: () => {
controller.rollbackToPreviousProvider();
operation: async () => {
await controller.rollbackToPreviousProvider();
},
});
expect(controller.store.getState().networkDetails).toStrictEqual({

View File

@ -787,10 +787,10 @@ export class NetworkController extends EventEmitter {
* different than the initial network (if it is, then this is equivalent to
* calling `resetConnection`).
*/
rollbackToPreviousProvider(): void {
async rollbackToPreviousProvider() {
const config = this.#previousProviderConfig;
this.providerStore.putState(config);
this._switchNetwork(config);
await this._switchNetwork(config);
}
/**