aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/blockchain_watcher.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-29 17:34:38 +0800
committerFabio Berger <me@fabioberger.com>2018-06-29 17:34:38 +0800
commitaa2616b307d3384791f1dbafc76999e7c4cf801f (patch)
tree0d8f11f66dcd595fefb184dd0dabc2d69183b782 /packages/website/ts/blockchain_watcher.ts
parent3062c18ebda8e55831038f140313000fd6d2cf71 (diff)
parent518a2da0275632a5dd61f99a105163ff5a074927 (diff)
downloaddexon-sol-tools-aa2616b307d3384791f1dbafc76999e7c4cf801f.tar
dexon-sol-tools-aa2616b307d3384791f1dbafc76999e7c4cf801f.tar.gz
dexon-sol-tools-aa2616b307d3384791f1dbafc76999e7c4cf801f.tar.bz2
dexon-sol-tools-aa2616b307d3384791f1dbafc76999e7c4cf801f.tar.lz
dexon-sol-tools-aa2616b307d3384791f1dbafc76999e7c4cf801f.tar.xz
dexon-sol-tools-aa2616b307d3384791f1dbafc76999e7c4cf801f.tar.zst
dexon-sol-tools-aa2616b307d3384791f1dbafc76999e7c4cf801f.zip
Merge v2-prototype
Diffstat (limited to 'packages/website/ts/blockchain_watcher.ts')
-rw-r--r--packages/website/ts/blockchain_watcher.ts46
1 files changed, 13 insertions, 33 deletions
diff --git a/packages/website/ts/blockchain_watcher.ts b/packages/website/ts/blockchain_watcher.ts
index c576db6ac..df5f73fd1 100644
--- a/packages/website/ts/blockchain_watcher.ts
+++ b/packages/website/ts/blockchain_watcher.ts
@@ -6,24 +6,17 @@ import { Dispatcher } from 'ts/redux/dispatcher';
export class BlockchainWatcher {
private _dispatcher: Dispatcher;
private _web3Wrapper: Web3Wrapper;
- private _prevNetworkId: number;
private _shouldPollUserAddress: boolean;
- private _watchNetworkAndBalanceIntervalId: NodeJS.Timer;
+ private _watchBalanceIntervalId: NodeJS.Timer;
private _prevUserEtherBalanceInWei?: BigNumber;
private _prevUserAddressIfExists: string;
- constructor(
- dispatcher: Dispatcher,
- web3Wrapper: Web3Wrapper,
- networkIdIfExists: number,
- shouldPollUserAddress: boolean,
- ) {
+ constructor(dispatcher: Dispatcher, web3Wrapper: Web3Wrapper, shouldPollUserAddress: boolean) {
this._dispatcher = dispatcher;
- this._prevNetworkId = networkIdIfExists;
this._shouldPollUserAddress = shouldPollUserAddress;
this._web3Wrapper = web3Wrapper;
}
public destroy(): void {
- this._stopEmittingNetworkConnectionAndUserBalanceState();
+ this._stopEmittingUserBalanceState();
// HACK: stop() is only available on providerEngine instances
const provider = this._web3Wrapper.getProvider();
if (!_.isUndefined((provider as any).stop)) {
@@ -34,36 +27,23 @@ export class BlockchainWatcher {
public updatePrevUserAddress(userAddress: string): void {
this._prevUserAddressIfExists = userAddress;
}
- public async startEmittingNetworkConnectionAndUserBalanceStateAsync(): Promise<void> {
- if (!_.isUndefined(this._watchNetworkAndBalanceIntervalId)) {
+ public async startEmittingUserBalanceStateAsync(): Promise<void> {
+ if (!_.isUndefined(this._watchBalanceIntervalId)) {
return; // we are already emitting the state
}
this._prevUserEtherBalanceInWei = undefined;
- this._dispatcher.updateNetworkId(this._prevNetworkId);
- await this._updateNetworkAndBalanceAsync();
- this._watchNetworkAndBalanceIntervalId = intervalUtils.setAsyncExcludingInterval(
- this._updateNetworkAndBalanceAsync.bind(this),
+ await this._updateBalanceAsync();
+ this._watchBalanceIntervalId = intervalUtils.setAsyncExcludingInterval(
+ this._updateBalanceAsync.bind(this),
5000,
(err: Error) => {
logUtils.log(`Watching network and balances failed: ${err.stack}`);
- this._stopEmittingNetworkConnectionAndUserBalanceState();
+ this._stopEmittingUserBalanceState();
},
);
}
- private async _updateNetworkAndBalanceAsync(): Promise<void> {
- // Check for network state changes
+ private async _updateBalanceAsync(): Promise<void> {
let prevNodeVersion: string;
- let currentNetworkId;
- try {
- currentNetworkId = await this._web3Wrapper.getNetworkIdAsync();
- } catch (err) {
- // Noop
- }
- if (currentNetworkId !== this._prevNetworkId) {
- this._prevNetworkId = currentNetworkId;
- this._dispatcher.updateNetworkId(currentNetworkId);
- }
-
// Check for node version changes
const currentNodeVersion = await this._web3Wrapper.getNodeVersionAsync();
if (currentNodeVersion !== prevNodeVersion) {
@@ -99,9 +79,9 @@ export class BlockchainWatcher {
this._dispatcher.updateUserWeiBalance(balanceInWei);
}
}
- private _stopEmittingNetworkConnectionAndUserBalanceState(): void {
- if (!_.isUndefined(this._watchNetworkAndBalanceIntervalId)) {
- intervalUtils.clearAsyncExcludingInterval(this._watchNetworkAndBalanceIntervalId);
+ private _stopEmittingUserBalanceState(): void {
+ if (!_.isUndefined(this._watchBalanceIntervalId)) {
+ intervalUtils.clearAsyncExcludingInterval(this._watchBalanceIntervalId);
}
}
}