diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-07-08 05:21:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-08 05:21:25 +0800 |
commit | 3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53 (patch) | |
tree | 341a0b69c4b72ddf437780fc952fa344979b29ef /src/web3_wrapper.ts | |
parent | 6593ddf35cdcd7f474ea0cd108c19f673bdc441c (diff) | |
parent | 73a48ddb0d36064a1c5f50c3b917992fe5de89b4 (diff) | |
download | dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar.gz dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar.bz2 dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar.lz dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar.xz dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.tar.zst dexon-sol-tools-3eb21a76c18f4bbf7deed7c66ebd80bc59dddc53.zip |
Merge pull request #95 from 0xProject/cache_net_version
Cache `net_version` requests
Diffstat (limited to 'src/web3_wrapper.ts')
-rw-r--r-- | src/web3_wrapper.ts | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 630f0bef3..61bac45c9 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -5,11 +5,13 @@ import promisify = require('es6-promisify'); export class Web3Wrapper { private web3: Web3; + private networkIdIfExists?: number; constructor(provider: Web3.Provider) { this.web3 = new Web3(); this.web3.setProvider(provider); } public setProvider(provider: Web3.Provider) { + delete this.networkIdIfExists; this.web3.setProvider(provider); } public isAddress(address: string): boolean { @@ -27,9 +29,14 @@ export class Web3Wrapper { return this.web3.currentProvider; } public async getNetworkIdIfExistsAsync(): Promise<number|undefined> { + if (!_.isUndefined(this.networkIdIfExists)) { + return this.networkIdIfExists; + } + try { const networkId = await this.getNetworkAsync(); - return Number(networkId); + this.networkIdIfExists = Number(networkId); + return this.networkIdIfExists; } catch (err) { return undefined; } |