From d727bed6ab6fef90717a45845c544b409657e3c2 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Sat, 10 Jun 2017 15:36:52 +0200 Subject: Prefix private vars with _ --- src/contract_wrappers/token_wrapper.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/contract_wrappers/token_wrapper.ts') diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index bb79cac47..b0101c0da 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -11,13 +11,13 @@ import {TokenContract, ZeroExError} from '../types'; const ALLOWANCE_TO_ZERO_GAS_AMOUNT = 45730; export class TokenWrapper extends ContractWrapper { - private tokenContractsByAddress: {[address: string]: TokenContract}; + private _tokenContractsByAddress: {[address: string]: TokenContract}; constructor(web3Wrapper: Web3Wrapper) { super(web3Wrapper); - this.tokenContractsByAddress = {}; + this._tokenContractsByAddress = {}; } public invalidateContractInstances() { - this.tokenContractsByAddress = {}; + this._tokenContractsByAddress = {}; } /** * Retrieves an owner's ERC20 token balance. @@ -29,7 +29,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); await assert.isUserAddressAvailableAsync(this.web3Wrapper); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); let balance = await tokenContract.balanceOf.call(ownerAddress); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber balance = new BigNumber(balance); @@ -51,7 +51,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); // Hack: for some reason default estimated gas amount causes `base fee exceeds gas limit` exception // on testrpc. Probably related to https://github.com/ethereumjs/testrpc/issues/294 // TODO: Debug issue in testrpc and submit a PR, then remove this hack @@ -74,7 +74,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); await assert.isUserAddressAvailableAsync(this.web3Wrapper); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress); // Wrap BigNumbers returned from web3 with our own (later) version of BigNumber allowanceInBaseUnits = new BigNumber(allowanceInBaseUnits); @@ -89,7 +89,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); - const proxyAddress = await this.getProxyAddressAsync(); + const proxyAddress = await this._getProxyAddressAsync(); const allowanceInBaseUnits = await this.getAllowanceAsync(tokenAddress, ownerAddress, proxyAddress); return allowanceInBaseUnits; } @@ -107,7 +107,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const proxyAddress = await this.getProxyAddressAsync(); + const proxyAddress = await this._getProxyAddressAsync(); await this.setAllowanceAsync(tokenAddress, ownerAddress, proxyAddress, amountInBaseUnits); } /** @@ -124,7 +124,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('toAddress', toAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); const fromAddressBalance = await this.getBalanceAsync(tokenAddress, fromAddress); if (fromAddressBalance.lessThan(amountInBaseUnits)) { @@ -155,7 +155,7 @@ export class TokenWrapper extends ContractWrapper { await assert.isSenderAddressAsync('senderAddress', senderAddress, this.web3Wrapper); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); - const tokenContract = await this.getTokenContractAsync(tokenAddress); + const tokenContract = await this._getTokenContractAsync(tokenAddress); const fromAddressAllowance = await this.getAllowanceAsync(tokenAddress, fromAddress, senderAddress); if (fromAddressAllowance.lessThan(amountInBaseUnits)) { @@ -171,17 +171,17 @@ export class TokenWrapper extends ContractWrapper { from: senderAddress, }); } - private async getTokenContractAsync(tokenAddress: string): Promise { - let tokenContract = this.tokenContractsByAddress[tokenAddress]; + private async _getTokenContractAsync(tokenAddress: string): Promise { + let tokenContract = this._tokenContractsByAddress[tokenAddress]; if (!_.isUndefined(tokenContract)) { return tokenContract; } - const contractInstance = await this.instantiateContractIfExistsAsync((TokenArtifacts as any), tokenAddress); + const contractInstance = await this._instantiateContractIfExistsAsync((TokenArtifacts as any), tokenAddress); tokenContract = contractInstance as TokenContract; - this.tokenContractsByAddress[tokenAddress] = tokenContract; + this._tokenContractsByAddress[tokenAddress] = tokenContract; return tokenContract; } - private async getProxyAddressAsync() { + private async _getProxyAddressAsync() { const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : -- cgit v1.2.3 From 6b152edb985d836c91c6d816c03cc15e77be2c6e Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Sun, 11 Jun 2017 13:14:46 +0200 Subject: Fix last tests --- src/contract_wrappers/token_wrapper.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/contract_wrappers/token_wrapper.ts') diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index b0101c0da..98da6c2cd 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -27,7 +27,7 @@ export class TokenWrapper extends ContractWrapper { public async getBalanceAsync(tokenAddress: string, ownerAddress: string): Promise { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); - await assert.isUserAddressAvailableAsync(this.web3Wrapper); + await assert.isUserAddressAvailableAsync(this._web3Wrapper); const tokenContract = await this._getTokenContractAsync(tokenAddress); let balance = await tokenContract.balanceOf.call(ownerAddress); @@ -46,7 +46,7 @@ export class TokenWrapper extends ContractWrapper { */ public async setAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string, amountInBaseUnits: BigNumber.BigNumber): Promise { - await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('ownerAddress', ownerAddress, this._web3Wrapper); assert.isETHAddressHex('spenderAddress', spenderAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); @@ -55,7 +55,7 @@ export class TokenWrapper extends ContractWrapper { // Hack: for some reason default estimated gas amount causes `base fee exceeds gas limit` exception // on testrpc. Probably related to https://github.com/ethereumjs/testrpc/issues/294 // TODO: Debug issue in testrpc and submit a PR, then remove this hack - const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); + const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const gas = networkIdIfExists === constants.TESTRPC_NETWORK_ID ? ALLOWANCE_TO_ZERO_GAS_AMOUNT : undefined; await tokenContract.approve(spenderAddress, amountInBaseUnits, { from: ownerAddress, @@ -72,7 +72,7 @@ export class TokenWrapper extends ContractWrapper { public async getAllowanceAsync(tokenAddress: string, ownerAddress: string, spenderAddress: string) { assert.isETHAddressHex('ownerAddress', ownerAddress); assert.isETHAddressHex('tokenAddress', tokenAddress); - await assert.isUserAddressAvailableAsync(this.web3Wrapper); + await assert.isUserAddressAvailableAsync(this._web3Wrapper); const tokenContract = await this._getTokenContractAsync(tokenAddress); let allowanceInBaseUnits = await tokenContract.allowance.call(ownerAddress, spenderAddress); @@ -120,7 +120,7 @@ export class TokenWrapper extends ContractWrapper { public async transferAsync(tokenAddress: string, fromAddress: string, toAddress: string, amountInBaseUnits: BigNumber.BigNumber): Promise { assert.isETHAddressHex('tokenAddress', tokenAddress); - await assert.isSenderAddressAsync('fromAddress', fromAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('fromAddress', fromAddress, this._web3Wrapper); assert.isETHAddressHex('toAddress', toAddress); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); @@ -152,7 +152,7 @@ export class TokenWrapper extends ContractWrapper { assert.isETHAddressHex('tokenAddress', tokenAddress); assert.isETHAddressHex('fromAddress', fromAddress); assert.isETHAddressHex('toAddress', toAddress); - await assert.isSenderAddressAsync('senderAddress', senderAddress, this.web3Wrapper); + await assert.isSenderAddressAsync('senderAddress', senderAddress, this._web3Wrapper); assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); const tokenContract = await this._getTokenContractAsync(tokenAddress); @@ -182,7 +182,7 @@ export class TokenWrapper extends ContractWrapper { return tokenContract; } private async _getProxyAddressAsync() { - const networkIdIfExists = await this.web3Wrapper.getNetworkIdIfExistsAsync(); + const networkIdIfExists = await this._web3Wrapper.getNetworkIdIfExistsAsync(); const proxyNetworkConfigsIfExists = _.isUndefined(networkIdIfExists) ? undefined : (ProxyArtifacts as any).networks[networkIdIfExists]; -- cgit v1.2.3