aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-01-30 21:35:04 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-01-30 21:35:04 +0800
commit0a73bbe279ccc0f39363f0bb700c5f581ec5f654 (patch)
tree5b9d1834fb0f708d264a10f2393f752b6ecea239
parent2e3c02887efc24de35ce82b3662d9c47a0056a8c (diff)
downloaddexon-0x-contracts-0a73bbe279ccc0f39363f0bb700c5f581ec5f654.tar.gz
dexon-0x-contracts-0a73bbe279ccc0f39363f0bb700c5f581ec5f654.tar.zst
dexon-0x-contracts-0a73bbe279ccc0f39363f0bb700c5f581ec5f654.zip
Add zeroEx.etherToken.getContractAddressifExists
-rw-r--r--packages/0x.js/src/contract_wrappers/contract_wrapper.ts2
-rw-r--r--packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts9
-rw-r--r--packages/0x.js/test/ether_token_wrapper_test.ts2
3 files changed, 11 insertions, 2 deletions
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 = {};
diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts
index b810fc9f1..6d7d953a8 100644
--- a/packages/0x.js/test/ether_token_wrapper_test.ts
+++ b/packages/0x.js/test/ether_token_wrapper_test.ts
@@ -61,7 +61,7 @@ describe('EtherTokenWrapper', () => {
tokens = await zeroEx.tokenRegistry.getTokensAsync();
userAddresses = await zeroEx.getAvailableAddressesAsync();
addressWithETH = userAddresses[0];
- wethContractAddress = (zeroEx.etherToken as any)._getContractAddress(artifacts.EtherTokenArtifact);
+ wethContractAddress = zeroEx.etherToken.getContractAddressIfExists() as string;
depositWeiAmount = (zeroEx as any)._web3Wrapper.toWei(new BigNumber(5));
decimalPlaces = 7;
addressWithoutFunds = userAddresses[1];