aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-11-22 06:08:45 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-11-24 05:13:36 +0800
commit131236305bff6cdf85a7edb7e3c61c50ffbb1956 (patch)
treeb97bd84c5168343de8a652986d78e9cfa9efb4fd /packages/0x.js
parent45c9171a2c1991e2eb75a1d9d8656a8b1ad7e2e6 (diff)
downloaddexon-sol-tools-131236305bff6cdf85a7edb7e3c61c50ffbb1956.tar
dexon-sol-tools-131236305bff6cdf85a7edb7e3c61c50ffbb1956.tar.gz
dexon-sol-tools-131236305bff6cdf85a7edb7e3c61c50ffbb1956.tar.bz2
dexon-sol-tools-131236305bff6cdf85a7edb7e3c61c50ffbb1956.tar.lz
dexon-sol-tools-131236305bff6cdf85a7edb7e3c61c50ffbb1956.tar.xz
dexon-sol-tools-131236305bff6cdf85a7edb7e3c61c50ffbb1956.tar.zst
dexon-sol-tools-131236305bff6cdf85a7edb7e3c61c50ffbb1956.zip
Store networkId in web3Wrapper
Diffstat (limited to 'packages/0x.js')
-rw-r--r--packages/0x.js/src/0x.ts2
-rw-r--r--packages/0x.js/src/web3_wrapper.ts27
2 files changed, 9 insertions, 20 deletions
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts
index 1f4af9fea..a853aca1c 100644
--- a/packages/0x.js/src/0x.ts
+++ b/packages/0x.js/src/0x.ts
@@ -178,7 +178,7 @@ export class ZeroEx {
const defaults = {
gasPrice: config.gasPrice,
};
- this._web3Wrapper = new Web3Wrapper(provider, defaults);
+ this._web3Wrapper = new Web3Wrapper(provider, config.networkId, defaults);
this.token = new TokenWrapper(
this._web3Wrapper,
this._abiDecoder,
diff --git a/packages/0x.js/src/web3_wrapper.ts b/packages/0x.js/src/web3_wrapper.ts
index 7bd8ea093..8ce696513 100644
--- a/packages/0x.js/src/web3_wrapper.ts
+++ b/packages/0x.js/src/web3_wrapper.ts
@@ -18,10 +18,11 @@ interface RawLogEntry {
export class Web3Wrapper {
private web3: Web3;
+ private networkId: number;
private defaults: Partial<Web3.TxData>;
private networkIdIfExists?: number;
private jsonRpcRequestId: number;
- constructor(provider: Web3.Provider, defaults?: Partial<Web3.TxData>) {
+ constructor(provider: Web3.Provider, networkId: number, defaults?: Partial<Web3.TxData>) {
if (_.isUndefined((provider as any).sendAsync)) {
// Web3@1.0 provider doesn't support synchronous http requests,
// so it only has an async `send` method, instead of a `send` and `sendAsync` in web3@0.x.x`
@@ -29,6 +30,7 @@ export class Web3Wrapper {
(provider as any).sendAsync = (provider as any).send;
}
this.web3 = new Web3();
+ this.networkId = networkId;
this.web3.setProvider(provider);
this.defaults = defaults || {};
this.jsonRpcRequestId = 0;
@@ -58,31 +60,18 @@ export class Web3Wrapper {
public getCurrentProvider(): Web3.Provider {
return this.web3.currentProvider;
}
- public async getNetworkIdIfExistsAsync(): Promise<number|undefined> {
- 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 getNetworkId(): number {
+ return this.networkId;
}
public async getContractInstanceFromArtifactAsync<A extends Web3.ContractInstance>(artifact: Artifact,
address?: string): Promise<A> {
let contractAddress: string;
if (_.isUndefined(address)) {
- const networkIdIfExists = await this.getNetworkIdIfExistsAsync();
- if (_.isUndefined(networkIdIfExists)) {
- throw new Error(ZeroExError.NoNetworkId);
- }
- if (_.isUndefined(artifact.networks[networkIdIfExists])) {
+ const networkId = this.getNetworkId();
+ if (_.isUndefined(artifact.networks[networkId])) {
throw new Error(ZeroExError.ContractNotDeployedOnNetwork);
}
- contractAddress = artifact.networks[networkIdIfExists].address.toLowerCase();
+ contractAddress = artifact.networks[networkId].address.toLowerCase();
} else {
contractAddress = address;
}