1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Fix NetworkController destroy before initialization (#17136)

The NetworkController `destroy` method has been updated to ensure that
it no longer throws if called before initialization.

This method was added recently in #17032, but we forgot to handle the
case where the controller was not initialized.
This commit is contained in:
Mark Stacey 2023-01-11 15:26:33 -03:30 committed by GitHub
parent e8e0cf5786
commit 6482848610
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -132,7 +132,7 @@ export default class NetworkController extends EventEmitter {
* In-progress requests will not be aborted.
*/
async destroy() {
await this._blockTracker.destroy();
await this._blockTracker?.destroy();
}
async initializeProvider() {

View File

@ -91,6 +91,12 @@ describe('NetworkController', () => {
});
describe('destroy', () => {
it('should not throw if called before initialization', async () => {
await expect(
async () => await networkController.destroy(),
).not.toThrow();
});
it('should stop the block tracker for the current selected network', async () => {
nock('http://localhost:8545')
.persist()