From 0a73bbe279ccc0f39363f0bb700c5f581ec5f654 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 30 Jan 2018 14:35:04 +0100 Subject: Add zeroEx.etherToken.getContractAddressifExists --- packages/0x.js/src/contract_wrappers/contract_wrapper.ts | 2 +- packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'packages/0x.js/src') diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 27551c01d..09de77452 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -34,7 +34,7 @@ const CONTRACT_NAME_TO_NOT_FOUND_ERROR: { export class ContractWrapper { protected _web3Wrapper: Web3Wrapper; - private _networkId: number; + protected _networkId: number; private _abiDecoder?: AbiDecoder; private _blockAndLogStreamerIfExists: BlockAndLogStreamer | undefined; private _blockAndLogStreamInterval: NodeJS.Timer; diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts index b03571636..1373e7baf 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -163,6 +163,15 @@ export class EtherTokenWrapper extends ContractWrapper { public unsubscribeAll(): void { super.unsubscribeAll(); } + /** + * Retrieves the Ethereum address of the EtherToken contract deployed on the network + * that the user-passed web3 provider is connected to. If it's an unknown private network - undefined is returned. + * @returns The Ethereum address of the EtherToken contract or undefined. + */ + public getContractAddressIfExists(): string | undefined { + const contractAddress = artifacts.EtherTokenArtifact.networks[this._networkId].address; + return contractAddress; + } private _invalidateContractInstance(): void { this.unsubscribeAll(); this._etherTokenContractsByAddress = {}; -- cgit From a816fb5958116127b1fffb78f5fca07624b5b0a5 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 5 Feb 2018 12:28:27 +0100 Subject: Improve the comment and fix an exception --- packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'packages/0x.js/src') diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts index 1373e7baf..ead6fe9d1 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -165,12 +165,16 @@ export class EtherTokenWrapper extends ContractWrapper { } /** * Retrieves the Ethereum address of the EtherToken contract deployed on the network - * that the user-passed web3 provider is connected to. If it's an unknown private network - undefined is returned. + * that the user-passed web3 provider is connected to. If it's not Kovan, Ropsten, Rinkeby, Mainnet or TestRPC + * (networkId: 50), it will return undefined (e.g a private network). * @returns The Ethereum address of the EtherToken contract or undefined. */ public getContractAddressIfExists(): string | undefined { - const contractAddress = artifacts.EtherTokenArtifact.networks[this._networkId].address; - return contractAddress; + const networkSpecificArtifact = artifacts.EtherTokenArtifact.networks[this._networkId]; + const contractAddressIfExists = _.isUndefined(networkSpecificArtifact) + ? undefined + : networkSpecificArtifact.address; + return contractAddressIfExists; } private _invalidateContractInstance(): void { this.unsubscribeAll(); -- cgit