From 0a0da63ac7913f0c3a27147a700c9a3dbccf0c40 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 26 Jun 2018 12:33:38 -0700 Subject: Make unsubscribing work --- packages/website/ts/blockchain.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 0d8cbdcd4..7bd6fe800 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -82,6 +82,7 @@ export class Blockchain { private _web3Wrapper?: Web3Wrapper; private _blockchainWatcher?: BlockchainWatcher; private _injectedProviderObservable?: InjectedProviderObservable; + private _injectedProviderUpdateHandler: (update: InjectedProviderUpdate) => Promise; private _userAddressIfExists: string; private _ledgerSubprovider: LedgerSubprovider; private _defaultGasPrice: BigNumber; @@ -186,6 +187,8 @@ export class Blockchain { this._dispatcher = dispatcher; const defaultGasPrice = GWEI_IN_WEI * 30; this._defaultGasPrice = new BigNumber(defaultGasPrice); + // We need a unique reference to this function so we can use it to unsubcribe. + this._injectedProviderUpdateHandler = this._handleInjectedProviderUpdateAsync.bind(this); // tslint:disable-next-line:no-floating-promises this._updateDefaultGasPriceAsync(); // tslint:disable-next-line:no-floating-promises @@ -521,6 +524,7 @@ export class Blockchain { } public destroy(): void { this._blockchainWatcher.destroy(); + this._injectedProviderObservable.unsubscribe(this._injectedProviderUpdateHandler); this._stopWatchingExchangeLogFillEvents(); } public async fetchTokenInformationAsync(): Promise { @@ -776,7 +780,7 @@ export class Blockchain { const injectedProviderObservable = injectedWeb3.currentProvider.publicConfigStore; if (injectedProviderObservable && !this._injectedProviderObservable) { this._injectedProviderObservable = injectedProviderObservable; - this._injectedProviderObservable.subscribe(this._handleInjectedProviderUpdateAsync.bind(this)); + this._injectedProviderObservable.subscribe(this._injectedProviderUpdateHandler); } } this._updateProviderName(injectedWeb3); -- cgit v1.2.3