aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers/token_wrapper.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-09-18 18:26:16 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-09-18 21:18:04 +0800
commit8db90538a17a0458fba6d2ed8a8b51bf9edf0fa4 (patch)
tree0b7eecf9ec6b3f394203d6f3f6240eb2825ae9a9 /src/contract_wrappers/token_wrapper.ts
parentfe9f692a4f472e5decbda96aad6afaf98c10d850 (diff)
downloaddexon-sol-tools-8db90538a17a0458fba6d2ed8a8b51bf9edf0fa4.tar
dexon-sol-tools-8db90538a17a0458fba6d2ed8a8b51bf9edf0fa4.tar.gz
dexon-sol-tools-8db90538a17a0458fba6d2ed8a8b51bf9edf0fa4.tar.bz2
dexon-sol-tools-8db90538a17a0458fba6d2ed8a8b51bf9edf0fa4.tar.lz
dexon-sol-tools-8db90538a17a0458fba6d2ed8a8b51bf9edf0fa4.tar.xz
dexon-sol-tools-8db90538a17a0458fba6d2ed8a8b51bf9edf0fa4.tar.zst
dexon-sol-tools-8db90538a17a0458fba6d2ed8a8b51bf9edf0fa4.zip
Fetch tokenTransferProxy address from exchange contract
Diffstat (limited to 'src/contract_wrappers/token_wrapper.ts')
-rw-r--r--src/contract_wrappers/token_wrapper.ts22
1 files changed, 9 insertions, 13 deletions
diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts
index bdfdf0c74..59c4a4e7b 100644
--- a/src/contract_wrappers/token_wrapper.ts
+++ b/src/contract_wrappers/token_wrapper.ts
@@ -31,10 +31,12 @@ export class TokenWrapper extends ContractWrapper {
public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
private _tokenContractsByAddress: {[address: string]: TokenContract};
private _tokenLogEventEmitters: ContractEventEmitter[];
- constructor(web3Wrapper: Web3Wrapper) {
+ private _tokenTransferProxyContractAddressFetcher: () => Promise<string>;
+ constructor(web3Wrapper: Web3Wrapper, tokenTransferProxyContractAddressFetcher: () => Promise<string>) {
super(web3Wrapper);
this._tokenContractsByAddress = {};
this._tokenLogEventEmitters = [];
+ this._tokenTransferProxyContractAddressFetcher = tokenTransferProxyContractAddressFetcher;
}
/**
* Retrieves an owner's ERC20 token balance.
@@ -133,7 +135,7 @@ export class TokenWrapper extends ContractWrapper {
assert.isETHAddressHex('ownerAddress', ownerAddress);
assert.isETHAddressHex('tokenAddress', tokenAddress);
- const proxyAddress = await this._getProxyAddressAsync();
+ const proxyAddress = await this._getTokentransferProxyAddressAsync();
const allowanceInBaseUnits = await this.getAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, methodOpts);
return allowanceInBaseUnits;
}
@@ -152,7 +154,7 @@ export class TokenWrapper extends ContractWrapper {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isBigNumber('amountInBaseUnits', amountInBaseUnits);
- const proxyAddress = await this._getProxyAddressAsync();
+ const proxyAddress = await this._getTokentransferProxyAddressAsync();
const txHash = await this.setAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, amountInBaseUnits);
return txHash;
}
@@ -299,15 +301,9 @@ export class TokenWrapper extends ContractWrapper {
this._tokenContractsByAddress[tokenAddress] = tokenContract;
return tokenContract;
}
- private async _getProxyAddressAsync() {
- const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync();
- const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ?
- undefined :
- artifacts.TokenTransferProxyArtifact.networks[networkIdIfExists];
- if (_.isUndefined(proxyNetworkConfigsIfExists)) {
- throw new Error(ZeroExError.ContractNotDeployedOnNetwork);
- }
- const proxyAddress = proxyNetworkConfigsIfExists.address.toLowerCase();
- return proxyAddress;
+ private async _getTokentransferProxyAddressAsync(): Promise<string> {
+ const tokenTransferProxyContractAddress = await this._tokenTransferProxyContractAddressFetcher();
+ const lowerCaseTokenTransferProxyContractAddress = tokenTransferProxyContractAddress.toLowerCase();
+ return lowerCaseTokenTransferProxyContractAddress;
}
}