From 34beee1edcd59b0f78c3dcce51cf847291ae06b4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Thu, 23 Nov 2017 09:41:05 -0600 Subject: Refactor getContractAddress to contractWrapper --- packages/0x.js/src/contract_wrappers/contract_wrapper.ts | 2 +- .../0x.js/src/contract_wrappers/ether_token_wrapper.ts | 14 ++++---------- packages/0x.js/src/contract_wrappers/exchange_wrapper.ts | 14 ++++---------- .../0x.js/src/contract_wrappers/token_registry_wrapper.ts | 14 ++++---------- .../src/contract_wrappers/token_transfer_proxy_wrapper.ts | 14 ++++---------- 5 files changed, 17 insertions(+), 41 deletions(-) (limited to 'packages') diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 2b99cfe4c..522b40d52 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -141,7 +141,7 @@ export class ContractWrapper { // We need to coerce to Block type cause Web3.Block includes types for mempool blocks if (!_.isUndefined(this._blockAndLogStreamer)) { // If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined - await this._blockAndLogStreamer.reconcileNewBlock(latestBlock as any as Block); + this._blockAndLogStreamer.reconcileNewBlock(latestBlock as any as Block); } } catch (err) { const filterTokens = _.keys(this._filterCallbacks); 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 0ac21cb78..7a3f2bc52 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -70,16 +70,10 @@ export class EtherTokenWrapper extends ContractWrapper { * @return The Wrapped Ether token contract address */ public getContractAddress(): string { - const networkId = this._web3Wrapper.getNetworkId(); - if (_.isUndefined(this._contractAddressIfExists)) { - const contractAddress = artifacts.EtherTokenArtifact.networks[networkId].address; - if (_.isUndefined(contractAddress)) { - throw new Error(ZeroExError.ExchangeContractDoesNotExist); - } - return contractAddress; - } else { - return this._contractAddressIfExists; - } + const contractAddress = this._getContractAddress( + artifacts.EtherTokenArtifact, this._contractAddressIfExists, + ); + return contractAddress; } private _invalidateContractInstance(): void { delete this._etherTokenContractIfExists; diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index b35219b24..883cc0f49 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -830,16 +830,10 @@ export class ExchangeWrapper extends ContractWrapper { * @return Address of ZRX token */ public getZRXTokenAddress(): string { - const networkId = this._web3Wrapper.getNetworkId(); - if (_.isUndefined(this._zrxContractAddressIfExists)) { - const zrxTokenAddress = artifacts.ZRXArtifact.networks[networkId].address; - if (_.isUndefined(zrxTokenAddress)) { - throw new Error(ZeroExError.ZRXContractDoesNotExist); - } - return zrxTokenAddress; - } else { - return this._zrxContractAddressIfExists; - } + const contractAddress = this._getContractAddress( + artifacts.ZRXArtifact, this._zrxContractAddressIfExists, + ); + return contractAddress; } private async _invalidateContractInstancesAsync(): Promise { this.unsubscribeAll(); diff --git a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts index 468e58350..35337fa35 100644 --- a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts @@ -104,16 +104,10 @@ export class TokenRegistryWrapper extends ContractWrapper { * @returns The Ethereum address of the TokenRegistry contract being used. */ public getContractAddress(): string { - const networkId = this._web3Wrapper.getNetworkId(); - if (_.isUndefined(this._contractAddressIfExists)) { - const contractAddress = artifacts.TokenRegistryArtifact.networks[networkId].address; - if (_.isUndefined(contractAddress)) { - throw new Error(ZeroExError.ExchangeContractDoesNotExist); - } - return contractAddress; - } else { - return this._contractAddressIfExists; - } + const contractAddress = this._getContractAddress( + artifacts.TokenRegistryArtifact, this._contractAddressIfExists, + ); + return contractAddress; } private _invalidateContractInstance(): void { delete this._tokenRegistryContractIfExists; diff --git a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts index 33adc0a9b..c3df7d3eb 100644 --- a/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_transfer_proxy_wrapper.ts @@ -41,16 +41,10 @@ export class TokenTransferProxyWrapper extends ContractWrapper { * @returns The Ethereum address of the TokenTransferProxy contract being used. */ public getContractAddress(): string { - const networkId = this._web3Wrapper.getNetworkId(); - if (_.isUndefined(this._contractAddressIfExists)) { - const contractAddress = artifacts.TokenTransferProxyArtifact.networks[networkId].address; - if (_.isUndefined(contractAddress)) { - throw new Error(ZeroExError.ExchangeContractDoesNotExist); - } - return contractAddress; - } else { - return this._contractAddressIfExists; - } + const contractAddress = this._getContractAddress( + artifacts.TokenTransferProxyArtifact, this._contractAddressIfExists, + ); + return contractAddress; } private _invalidateContractInstance(): void { delete this._tokenTransferProxyContractIfExists; -- cgit v1.2.3