diff options
author | Fabio Berger <me@fabioberger.com> | 2017-05-30 20:23:44 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-05-30 20:23:44 +0800 |
commit | ad14c307cec8e0e7621b47e9e1ecb2652985190f (patch) | |
tree | 4800127dea7cd267ab57622d875fa92a49f1a98e /src/contract_wrappers/token_registry_wrapper.ts | |
parent | 8561258ded12bc7d284933e61f6d052941258f40 (diff) | |
download | dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar.gz dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar.bz2 dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar.lz dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar.xz dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.tar.zst dexon-sol-tools-ad14c307cec8e0e7621b47e9e1ecb2652985190f.zip |
Refactor exchangeWrapper and tokenRegistryWrapper to use contract getter that instantiates contract instance if not already instantiated
Diffstat (limited to 'src/contract_wrappers/token_registry_wrapper.ts')
-rw-r--r-- | src/contract_wrappers/token_registry_wrapper.ts | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts index 69bad2bac..86bea1c5d 100644 --- a/src/contract_wrappers/token_registry_wrapper.ts +++ b/src/contract_wrappers/token_registry_wrapper.ts @@ -6,20 +6,20 @@ import {ContractWrapper} from './contract_wrapper'; import * as TokenRegistryArtifacts from '../artifacts/TokenRegistry.json'; export class TokenRegistryWrapper extends ContractWrapper { - private tokenRegistryContractIfExists: TokenRegistryContract; + private tokenRegistryContractIfExists?: TokenRegistryContract; constructor(web3Wrapper: Web3Wrapper) { super(web3Wrapper); } - public invalidateContractInstance() { + public invalidateContractInstance(): void { delete this.tokenRegistryContractIfExists; } public async getTokensAsync(): Promise<Token[]> { - await this.instantiateTokenRegistryContractIfDoesntExistAsync(); + const tokenRegistryContract = await this.getTokenRegistryContractAsync(); - const addresses = await this.tokenRegistryContractIfExists.getTokenAddresses.call(); + const addresses = await tokenRegistryContract.getTokenAddresses.call(); const tokenMetadataPromises: Array<Promise<TokenMetadata>> = _.map( addresses, - (address: string) => (this.tokenRegistryContractIfExists.getTokenMetaData.call(address)), + (address: string) => (tokenRegistryContract.getTokenMetaData.call(address)), ); const tokensMetadata = await Promise.all(tokenMetadataPromises); const tokens = _.map(tokensMetadata, metadata => { @@ -33,11 +33,12 @@ export class TokenRegistryWrapper extends ContractWrapper { }); return tokens; } - private async instantiateTokenRegistryContractIfDoesntExistAsync() { + private async getTokenRegistryContractAsync(): Promise<TokenRegistryContract> { if (!_.isUndefined(this.tokenRegistryContractIfExists)) { - return; + return this.tokenRegistryContractIfExists; } const contractInstance = await this.instantiateContractIfExistsAsync((TokenRegistryArtifacts as any)); this.tokenRegistryContractIfExists = contractInstance as TokenRegistryContract; + return this.tokenRegistryContractIfExists; } } |