aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-05-30 18:43:50 +0800
committerFabio Berger <me@fabioberger.com>2017-05-30 18:43:50 +0800
commita3ce892f85e7a8c1bb0e707f1e64f204a2ce29c6 (patch)
tree27bb9cbc2678b5342ce5064c4b57a70ebfbf2043 /src/contract_wrappers
parentcb31b21d28c20a0153199e9388202301e1385bfe (diff)
downloaddexon-sol-tools-a3ce892f85e7a8c1bb0e707f1e64f204a2ce29c6.tar
dexon-sol-tools-a3ce892f85e7a8c1bb0e707f1e64f204a2ce29c6.tar.gz
dexon-sol-tools-a3ce892f85e7a8c1bb0e707f1e64f204a2ce29c6.tar.bz2
dexon-sol-tools-a3ce892f85e7a8c1bb0e707f1e64f204a2ce29c6.tar.lz
dexon-sol-tools-a3ce892f85e7a8c1bb0e707f1e64f204a2ce29c6.tar.xz
dexon-sol-tools-a3ce892f85e7a8c1bb0e707f1e64f204a2ce29c6.tar.zst
dexon-sol-tools-a3ce892f85e7a8c1bb0e707f1e64f204a2ce29c6.zip
Make tokenRegistry contract instantiation lazy and clear it on provider update
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;
+ }
}