diff options
author | Fabio Berger <me@fabioberger.com> | 2018-01-31 04:27:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-31 04:27:21 +0800 |
commit | 1feac1a30886944ccadc00b2ff4f493e0d495301 (patch) | |
tree | be68e9a62e3de3caf6e5e841899df16d8decc7e5 /packages/website/ts/web3_wrapper.ts | |
parent | 2bcb7d56394c43acd68d1823092de2ad047abc6d (diff) | |
parent | d3e42e4b3e2f893b616246d35f46dba92f251e83 (diff) | |
download | dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar.gz dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar.bz2 dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar.lz dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar.xz dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.tar.zst dexon-sol-tools-1feac1a30886944ccadc00b2ff4f493e0d495301.zip |
Merge pull request #351 from 0xProject/feature/portal-ledger-support
Portal Ledger Support, Lazy-loading token balances/allowances
Diffstat (limited to 'packages/website/ts/web3_wrapper.ts')
-rw-r--r-- | packages/website/ts/web3_wrapper.ts | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/packages/website/ts/web3_wrapper.ts b/packages/website/ts/web3_wrapper.ts index 415df6e8b..9d8d771af 100644 --- a/packages/website/ts/web3_wrapper.ts +++ b/packages/website/ts/web3_wrapper.ts @@ -24,9 +24,6 @@ export class Web3Wrapper { this._web3 = new Web3(); this._web3.setProvider(provider); - - // tslint:disable-next-line:no-floating-promises - this._startEmittingNetworkConnectionAndUserBalanceStateAsync(); } public isAddress(address: string) { return this._web3.isAddress(address); @@ -90,11 +87,7 @@ export class Web3Wrapper { public updatePrevUserAddress(userAddress: string) { this._prevUserAddress = userAddress; } - private async _getNetworkAsync() { - const networkId = await promisify(this._web3.version.getNetwork)(); - return networkId; - } - private async _startEmittingNetworkConnectionAndUserBalanceStateAsync() { + public startEmittingNetworkConnectionAndUserBalanceState() { if (!_.isUndefined(this._watchNetworkAndBalanceIntervalId)) { return; // we are already emitting the state } @@ -127,7 +120,7 @@ export class Web3Wrapper { } // Check for user ether balance changes - if (userAddressIfExists !== '') { + if (!_.isEmpty(userAddressIfExists)) { await this._updateUserEtherBalanceAsync(userAddressIfExists); } } else { @@ -140,11 +133,15 @@ export class Web3Wrapper { }, 5000, (err: Error) => { - utils.consoleLog(`Watching network and balances failed: ${err}`); + utils.consoleLog(`Watching network and balances failed: ${err.stack}`); this._stopEmittingNetworkConnectionAndUserBalanceStateAsync(); }, ); } + private async _getNetworkAsync() { + const networkId = await promisify(this._web3.version.getNetwork)(); + return networkId; + } private async _updateUserEtherBalanceAsync(userAddress: string) { const balance = await this.getBalanceInEthAsync(userAddress); if (!balance.eq(this._prevUserEtherBalanceInEth)) { @@ -153,6 +150,8 @@ export class Web3Wrapper { } } private _stopEmittingNetworkConnectionAndUserBalanceStateAsync() { - intervalUtils.clearAsyncExcludingInterval(this._watchNetworkAndBalanceIntervalId); + if (!_.isUndefined(this._watchNetworkAndBalanceIntervalId)) { + intervalUtils.clearAsyncExcludingInterval(this._watchNetworkAndBalanceIntervalId); + } } } |