aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers
diff options
context:
space:
mode:
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r--src/contract_wrappers/token_registry_wrapper.ts18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/contract_wrappers/token_registry_wrapper.ts b/src/contract_wrappers/token_registry_wrapper.ts
index 8dd79171e..69bad2bac 100644
--- a/src/contract_wrappers/token_registry_wrapper.ts
+++ b/src/contract_wrappers/token_registry_wrapper.ts
@@ -6,17 +6,20 @@ import {ContractWrapper} from './contract_wrapper';
import * as TokenRegistryArtifacts from '../artifacts/TokenRegistry.json';
export class TokenRegistryWrapper extends ContractWrapper {
+ private tokenRegistryContractIfExists: TokenRegistryContract;
constructor(web3Wrapper: Web3Wrapper) {
super(web3Wrapper);
}
+ public invalidateContractInstance() {
+ delete this.tokenRegistryContractIfExists;
+ }
public async getTokensAsync(): Promise<Token[]> {
- const contractInstance = await this.instantiateContractIfExistsAsync((TokenRegistryArtifacts as any));
- const tokenRegistryContract = contractInstance as TokenRegistryContract;
+ await this.instantiateTokenRegistryContractIfDoesntExistAsync();
- const addresses = await tokenRegistryContract.getTokenAddresses.call();
+ const addresses = await this.tokenRegistryContractIfExists.getTokenAddresses.call();
const tokenMetadataPromises: Array<Promise<TokenMetadata>> = _.map(
addresses,
- (address: string) => (tokenRegistryContract.getTokenMetaData.call(address)),
+ (address: string) => (this.tokenRegistryContractIfExists.getTokenMetaData.call(address)),
);
const tokensMetadata = await Promise.all(tokenMetadataPromises);
const tokens = _.map(tokensMetadata, metadata => {
@@ -30,4 +33,11 @@ export class TokenRegistryWrapper extends ContractWrapper {
});
return tokens;
}
+ private async instantiateTokenRegistryContractIfDoesntExistAsync() {
+ if (!_.isUndefined(this.tokenRegistryContractIfExists)) {
+ return;
+ }
+ const contractInstance = await this.instantiateContractIfExistsAsync((TokenRegistryArtifacts as any));
+ this.tokenRegistryContractIfExists = contractInstance as TokenRegistryContract;
+ }
}