Skip to content

Commit

Permalink
Gracefully remove old blockTracker event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpshr committed Aug 1, 2018
1 parent 7d6af73 commit 580d317
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gaba",
"version": "1.0.0-beta.13",
"version": "1.0.0-beta.14",
"description": "Collection of platform-agnostic modules for creating secure data models for cryptocurrency wallets",
"license": "MIT",
"scripts": {
Expand Down
13 changes: 1 addition & 12 deletions src/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,7 @@ export class NetworkController extends BaseController<NetworkState, NetworkConfi
}

private updateProvider(provider: any) {
if (this.provider) {
const oldBlockTracker = this.provider._blockTracker;
const newBlockTracker = provider._blockTracker;
Object.keys(oldBlockTracker._events).forEach((event) => {
const listeners = oldBlockTracker.listeners(event);
listeners.forEach((listener: EventListener) => {
newBlockTracker.on(event, listener);
oldBlockTracker.removeListener(event, listener);
});
});
this.provider.stop();
}
this.provider && this.provider.stop();
this.provider = provider;
}

Expand Down
2 changes: 1 addition & 1 deletion src/TokenRatesController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'isomorphic-fetch';
import BaseController, { BaseConfig, BaseState } from './BaseController';
import { PreferencesController } from './PreferencesController';
import PreferencesController from './PreferencesController';
import { safelyExecute } from './util';

/**
Expand Down

0 comments on commit 580d317

Please sign in to comment.