From c72745b0b27218a2a11529a90e0789f9e1b81d69 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 22 Nov 2017 13:15:48 -0600 Subject: Make zeroEx.tokenRegistry.getContractAddress non-async --- .../src/contract_wrappers/token_registry_wrapper.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'packages/0x.js') 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 2cc5a9aa0..ae561f0d2 100644 --- a/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/token_registry_wrapper.ts @@ -1,7 +1,7 @@ import * as _ from 'lodash'; import {Web3Wrapper} from '../web3_wrapper'; import {assert} from '../utils/assert'; -import {Token, TokenRegistryContract, TokenMetadata} from '../types'; +import {Token, TokenRegistryContract, TokenMetadata, ZeroExError} from '../types'; import {constants} from '../utils/constants'; import {ContractWrapper} from './contract_wrapper'; import {artifacts} from '../artifacts'; @@ -89,10 +89,17 @@ export class TokenRegistryWrapper extends ContractWrapper { * that the user-passed web3 provider is connected to. * @returns The Ethereum address of the TokenRegistry contract being used. */ - public async getContractAddressAsync(): Promise { - const tokenRegistryInstance = await this._getTokenRegistryContractAsync(); - const tokenRegistryAddress = tokenRegistryInstance.address; - return tokenRegistryAddress; + 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; + } } private _createTokenFromMetadata(metadata: TokenMetadata): Token|undefined { if (metadata[0] === constants.NULL_ADDRESS) { -- cgit