From 4fe28ec53c4e84544c3c21853dff57c4c6a4e45d Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 11:53:04 -0600 Subject: Make zeroEx.exchange.getContractAddress non-async --- .../0x.js/src/contract_wrappers/exchange_wrapper.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'packages/0x.js/src/contract_wrappers') diff --git a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts index 96b642a90..9ab03454c 100644 --- a/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/exchange_wrapper.ts @@ -664,7 +664,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); assert.isFunction('callback', callback); - const exchangeContractAddress = await this.getContractAddressAsync(); + const exchangeContractAddress = this.getContractAddress(); const subscriptionToken = this._subscribe( exchangeContractAddress, eventName, indexFilterValues, artifacts.ExchangeArtifact.abi, callback, ); @@ -691,7 +691,7 @@ export class ExchangeWrapper extends ContractWrapper { assert.doesBelongToStringEnum('eventName', eventName, ExchangeEvents); assert.doesConformToSchema('subscriptionOpts', subscriptionOpts, schemas.subscriptionOptsSchema); assert.doesConformToSchema('indexFilterValues', indexFilterValues, schemas.indexFilterValuesSchema); - const exchangeContractAddress = await this.getContractAddressAsync(); + const exchangeContractAddress = this.getContractAddress(); const logs = await this._getLogsAsync( exchangeContractAddress, eventName, subscriptionOpts, indexFilterValues, artifacts.ExchangeArtifact.abi, ); @@ -702,10 +702,17 @@ export class ExchangeWrapper extends ContractWrapper { * that the user-passed web3 provider is connected to. * @returns The Ethereum address of the Exchange contract being used. */ - public async getContractAddressAsync(): Promise { - const exchangeInstance = await this._getExchangeContractAsync(); - const exchangeAddress = exchangeInstance.address; - return exchangeAddress; + public getContractAddress(): string { + const networkId = this._web3Wrapper.getNetworkId(); + if (_.isUndefined(this._contractAddressIfExists)) { + const contractAddress = artifacts.ExchangeArtifact.networks[networkId].address; + if (_.isUndefined(contractAddress)) { + throw new Error(ZeroExError.ExchangeContractDoesNotExist); + } + return contractAddress; + } else { + return this._contractAddressIfExists; + } } /** * Checks if order is still fillable and throws an error otherwise. Useful for orderbook -- cgit v1.2.3