diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-08 05:20:39 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-08 05:21:00 +0800 |
commit | 73a48ddb0d36064a1c5f50c3b917992fe5de89b4 (patch) | |
tree | 341a0b69c4b72ddf437780fc952fa344979b29ef | |
parent | 0876fc6cabb914c6db5206182c8bd8d747b40674 (diff) | |
download | dexon-sol-tools-73a48ddb0d36064a1c5f50c3b917992fe5de89b4.tar dexon-sol-tools-73a48ddb0d36064a1c5f50c3b917992fe5de89b4.tar.gz dexon-sol-tools-73a48ddb0d36064a1c5f50c3b917992fe5de89b4.tar.bz2 dexon-sol-tools-73a48ddb0d36064a1c5f50c3b917992fe5de89b4.tar.lz dexon-sol-tools-73a48ddb0d36064a1c5f50c3b917992fe5de89b4.tar.xz dexon-sol-tools-73a48ddb0d36064a1c5f50c3b917992fe5de89b4.tar.zst dexon-sol-tools-73a48ddb0d36064a1c5f50c3b917992fe5de89b4.zip |
Refactor net_version caching logic
-rw-r--r-- | src/web3_wrapper.ts | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 8c410eef7..61bac45c9 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -11,7 +11,7 @@ export class Web3Wrapper { this.web3.setProvider(provider); } public setProvider(provider: Web3.Provider) { - this.networkIdIfExists = undefined; + delete this.networkIdIfExists; this.web3.setProvider(provider); } public isAddress(address: string): boolean { @@ -29,16 +29,16 @@ export class Web3Wrapper { return this.web3.currentProvider; } public async getNetworkIdIfExistsAsync(): Promise<number|undefined> { - if (_.isUndefined(this.networkIdIfExists)) { - try { - const networkId = await this.getNetworkAsync(); - this.networkIdIfExists = Number(networkId); - return this.networkIdIfExists; - } catch (err) { - return undefined; - } - } else { + if (!_.isUndefined(this.networkIdIfExists)) { + return this.networkIdIfExists; + } + + try { + const networkId = await this.getNetworkAsync(); + this.networkIdIfExists = Number(networkId); return this.networkIdIfExists; + } catch (err) { + return undefined; } } public toWei(ethAmount: BigNumber.BigNumber): BigNumber.BigNumber { |