diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-19 21:22:40 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-12-20 21:01:59 +0800 |
commit | 0056c66d324ca4d8cee82a84ff64b4832ea360f9 (patch) | |
tree | a35cdcb64dff6bddd9f099fdbd29d4c80810ba6e /packages/0x.js/src | |
parent | 613fada49f9d168fb949a370b884367f99deb401 (diff) | |
download | dexon-0x-contracts-0056c66d324ca4d8cee82a84ff64b4832ea360f9.tar dexon-0x-contracts-0056c66d324ca4d8cee82a84ff64b4832ea360f9.tar.gz dexon-0x-contracts-0056c66d324ca4d8cee82a84ff64b4832ea360f9.tar.bz2 dexon-0x-contracts-0056c66d324ca4d8cee82a84ff64b4832ea360f9.tar.lz dexon-0x-contracts-0056c66d324ca4d8cee82a84ff64b4832ea360f9.tar.xz dexon-0x-contracts-0056c66d324ca4d8cee82a84ff64b4832ea360f9.tar.zst dexon-0x-contracts-0056c66d324ca4d8cee82a84ff64b4832ea360f9.zip |
Enable multiple EtherTokenContract instances
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r-- | packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts index 7b5b4d02a..1edc50cb0 100644 --- a/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/ether_token_wrapper.ts @@ -27,7 +27,7 @@ import {TokenWrapper} from './token_wrapper'; * The caller can convert ETH into the equivalent number of wrapped ETH ERC20 tokens and back. */ export class EtherTokenWrapper extends ContractWrapper { - private _etherTokenContractIfExists?: EtherTokenContract; + private _etherTokenContractsByAddress: {[address: string]: EtherTokenContract}; private _tokenWrapper: TokenWrapper; constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder: AbiDecoder, tokenWrapper: TokenWrapper) { super(web3Wrapper, networkId, abiDecoder); @@ -144,14 +144,19 @@ export class EtherTokenWrapper extends ContractWrapper { } private _invalidateContractInstance(): void { this.unsubscribeAll(); - delete this._etherTokenContractIfExists; + this._etherTokenContractsByAddress = {}; } private async _getEtherTokenContractAsync(etherTokenAddress: string): Promise<EtherTokenContract> { + let etherTokenContract = this._etherTokenContractsByAddress[etherTokenAddress]; + if (!_.isUndefined(etherTokenContract)) { + return etherTokenContract; + } const web3ContractInstance = await this._instantiateContractIfExistsAsync( artifacts.EtherTokenArtifact, etherTokenAddress, ); const contractInstance = new EtherTokenContract(web3ContractInstance, this._web3Wrapper.getContractDefaults()); - this._etherTokenContractIfExists = contractInstance; - return this._etherTokenContractIfExists; + etherTokenContract = contractInstance; + this._etherTokenContractsByAddress[etherTokenAddress] = etherTokenContract; + return etherTokenContract; } } |