fix(contract-wrappers): Fix tslint errors that were lingering due to misconfiguration

This commit is contained in:
Alex Browne
2018-10-23 18:30:27 -07:00
parent 2c04ee3f5e
commit 9c26334eff
9 changed files with 31 additions and 28 deletions

View File

@@ -28,10 +28,10 @@ export abstract class ContractWrapper {
protected _networkId: number; protected _networkId: number;
protected _web3Wrapper: Web3Wrapper; protected _web3Wrapper: Web3Wrapper;
private _blockAndLogStreamerIfExists: BlockAndLogStreamer<Block, Log> | undefined; private _blockAndLogStreamerIfExists: BlockAndLogStreamer<Block, Log> | undefined;
private _blockPollingIntervalMs: number; private readonly _blockPollingIntervalMs: number;
private _blockAndLogStreamIntervalIfExists?: NodeJS.Timer; private _blockAndLogStreamIntervalIfExists?: NodeJS.Timer;
private _filters: { [filterToken: string]: FilterObject }; private readonly _filters: { [filterToken: string]: FilterObject };
private _filterCallbacks: { private readonly _filterCallbacks: {
[filterToken: string]: EventCallback<ContractEventArgs>; [filterToken: string]: EventCallback<ContractEventArgs>;
}; };
private _onLogAddedSubscriptionToken: string | undefined; private _onLogAddedSubscriptionToken: string | undefined;

View File

@@ -34,6 +34,7 @@ export class ERC20ProxyWrapper extends ContractWrapper {
*/ */
public async getProxyIdAsync(): Promise<AssetProxyId> { public async getProxyIdAsync(): Promise<AssetProxyId> {
const ERC20ProxyContractInstance = this._getERC20ProxyContract(); const ERC20ProxyContractInstance = this._getERC20ProxyContract();
/* tslint:disable-next-line:no-unnecessary-type-assertion */
const proxyId = (await ERC20ProxyContractInstance.getProxyId.callAsync()) as AssetProxyId; const proxyId = (await ERC20ProxyContractInstance.getProxyId.callAsync()) as AssetProxyId;
return proxyId; return proxyId;
} }

View File

@@ -18,12 +18,11 @@ import {
} from '../types'; } from '../types';
import { assert } from '../utils/assert'; import { assert } from '../utils/assert';
import { constants } from '../utils/constants'; import { constants } from '../utils/constants';
import { utils } from '../utils/utils';
import { ContractWrapper } from './contract_wrapper'; import { ContractWrapper } from './contract_wrapper';
import { ERC20ProxyWrapper } from './erc20_proxy_wrapper'; import { ERC20ProxyWrapper } from './erc20_proxy_wrapper';
const removeUndefinedProperties = _.pickBy;
/** /**
* This class includes all the functionality related to interacting with ERC20 token contracts. * This class includes all the functionality related to interacting with ERC20 token contracts.
* All ERC20 method calls are supported, along with some convenience methods for getting/setting allowances * All ERC20 method calls are supported, along with some convenience methods for getting/setting allowances
@@ -32,8 +31,8 @@ const removeUndefinedProperties = _.pickBy;
export class ERC20TokenWrapper extends ContractWrapper { export class ERC20TokenWrapper extends ContractWrapper {
public abi: ContractAbi = ERC20Token.compilerOutput.abi; public abi: ContractAbi = ERC20Token.compilerOutput.abi;
public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS; public UNLIMITED_ALLOWANCE_IN_BASE_UNITS = constants.UNLIMITED_ALLOWANCE_IN_BASE_UNITS;
private _tokenContractsByAddress: { [address: string]: ERC20TokenContract }; private readonly _tokenContractsByAddress: { [address: string]: ERC20TokenContract };
private _erc20ProxyWrapper: ERC20ProxyWrapper; private readonly _erc20ProxyWrapper: ERC20ProxyWrapper;
/** /**
* Instantiate ERC20TokenWrapper * Instantiate ERC20TokenWrapper
* @param web3Wrapper Web3Wrapper instance to use * @param web3Wrapper Web3Wrapper instance to use
@@ -108,7 +107,7 @@ export class ERC20TokenWrapper extends ContractWrapper {
const txHash = await tokenContract.approve.sendTransactionAsync( const txHash = await tokenContract.approve.sendTransactionAsync(
normalizedSpenderAddress, normalizedSpenderAddress,
amountInBaseUnits, amountInBaseUnits,
removeUndefinedProperties({ utils.removeUndefinedProperties({
from: normalizedOwnerAddress, from: normalizedOwnerAddress,
gas: txOpts.gasLimit, gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice, gasPrice: txOpts.gasPrice,
@@ -278,7 +277,7 @@ export class ERC20TokenWrapper extends ContractWrapper {
const txHash = await tokenContract.transfer.sendTransactionAsync( const txHash = await tokenContract.transfer.sendTransactionAsync(
normalizedToAddress, normalizedToAddress,
amountInBaseUnits, amountInBaseUnits,
removeUndefinedProperties({ utils.removeUndefinedProperties({
from: normalizedFromAddress, from: normalizedFromAddress,
gas: txOpts.gasLimit, gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice, gasPrice: txOpts.gasPrice,
@@ -339,7 +338,7 @@ export class ERC20TokenWrapper extends ContractWrapper {
normalizedFromAddress, normalizedFromAddress,
normalizedToAddress, normalizedToAddress,
amountInBaseUnits, amountInBaseUnits,
removeUndefinedProperties({ utils.removeUndefinedProperties({
from: normalizedSenderAddress, from: normalizedSenderAddress,
gas: txOpts.gasLimit, gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice, gasPrice: txOpts.gasPrice,

View File

@@ -34,6 +34,7 @@ export class ERC721ProxyWrapper extends ContractWrapper {
*/ */
public async getProxyIdAsync(): Promise<AssetProxyId> { public async getProxyIdAsync(): Promise<AssetProxyId> {
const ERC721ProxyContractInstance = await this._getERC721ProxyContract(); const ERC721ProxyContractInstance = await this._getERC721ProxyContract();
/* tslint:disable-next-line:no-unnecessary-type-assertion */
const proxyId = (await ERC721ProxyContractInstance.getProxyId.callAsync()) as AssetProxyId; const proxyId = (await ERC721ProxyContractInstance.getProxyId.callAsync()) as AssetProxyId;
return proxyId; return proxyId;
} }

View File

@@ -18,12 +18,11 @@ import {
} from '../types'; } from '../types';
import { assert } from '../utils/assert'; import { assert } from '../utils/assert';
import { constants } from '../utils/constants'; import { constants } from '../utils/constants';
import { utils } from '../utils/utils';
import { ContractWrapper } from './contract_wrapper'; import { ContractWrapper } from './contract_wrapper';
import { ERC721ProxyWrapper } from './erc721_proxy_wrapper'; import { ERC721ProxyWrapper } from './erc721_proxy_wrapper';
const removeUndefinedProperties = _.pickBy;
/** /**
* This class includes all the functionality related to interacting with ERC721 token contracts. * This class includes all the functionality related to interacting with ERC721 token contracts.
* All ERC721 method calls are supported, along with some convenience methods for getting/setting allowances * All ERC721 method calls are supported, along with some convenience methods for getting/setting allowances
@@ -31,8 +30,8 @@ const removeUndefinedProperties = _.pickBy;
*/ */
export class ERC721TokenWrapper extends ContractWrapper { export class ERC721TokenWrapper extends ContractWrapper {
public abi: ContractAbi = ERC721Token.compilerOutput.abi; public abi: ContractAbi = ERC721Token.compilerOutput.abi;
private _tokenContractsByAddress: { [address: string]: ERC721TokenContract }; private readonly _tokenContractsByAddress: { [address: string]: ERC721TokenContract };
private _erc721ProxyWrapper: ERC721ProxyWrapper; private readonly _erc721ProxyWrapper: ERC721ProxyWrapper;
/** /**
* Instantiate ERC721TokenWrapper * Instantiate ERC721TokenWrapper
* @param web3Wrapper Web3Wrapper instance to use * @param web3Wrapper Web3Wrapper instance to use
@@ -235,7 +234,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
const txHash = await tokenContract.setApprovalForAll.sendTransactionAsync( const txHash = await tokenContract.setApprovalForAll.sendTransactionAsync(
normalizedOperatorAddress, normalizedOperatorAddress,
isApproved, isApproved,
removeUndefinedProperties({ utils.removeUndefinedProperties({
gas: txOpts.gasLimit, gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice, gasPrice: txOpts.gasPrice,
from: normalizedOwnerAddress, from: normalizedOwnerAddress,
@@ -295,7 +294,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
const txHash = await tokenContract.approve.sendTransactionAsync( const txHash = await tokenContract.approve.sendTransactionAsync(
normalizedApprovedAddress, normalizedApprovedAddress,
tokenId, tokenId,
removeUndefinedProperties({ utils.removeUndefinedProperties({
gas: txOpts.gasLimit, gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice, gasPrice: txOpts.gasPrice,
from: tokenOwnerAddress, from: tokenOwnerAddress,
@@ -366,7 +365,7 @@ export class ERC721TokenWrapper extends ContractWrapper {
ownerAddress, ownerAddress,
normalizedReceiverAddress, normalizedReceiverAddress,
tokenId, tokenId,
removeUndefinedProperties({ utils.removeUndefinedProperties({
gas: txOpts.gasLimit, gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice, gasPrice: txOpts.gasPrice,
from: normalizedSenderAddress, from: normalizedSenderAddress,

View File

@@ -8,22 +8,21 @@ import * as _ from 'lodash';
import { BlockRange, ContractWrappersError, EventCallback, IndexedFilterValues, TransactionOpts } from '../types'; import { BlockRange, ContractWrappersError, EventCallback, IndexedFilterValues, TransactionOpts } from '../types';
import { assert } from '../utils/assert'; import { assert } from '../utils/assert';
import { utils } from '../utils/utils';
import { ContractWrapper } from './contract_wrapper'; import { ContractWrapper } from './contract_wrapper';
import { ERC20TokenWrapper } from './erc20_token_wrapper'; import { ERC20TokenWrapper } from './erc20_token_wrapper';
const removeUndefinedProperties = _.pickBy;
/** /**
* This class includes all the functionality related to interacting with a wrapped Ether ERC20 token contract. * This class includes all the functionality related to interacting with a wrapped Ether ERC20 token contract.
* The caller can convert ETH into the equivalent number of wrapped ETH ERC20 tokens and back. * The caller can convert ETH into the equivalent number of wrapped ETH ERC20 tokens and back.
*/ */
export class EtherTokenWrapper extends ContractWrapper { export class EtherTokenWrapper extends ContractWrapper {
public abi: ContractAbi = WETH9.compilerOutput.abi; public abi: ContractAbi = WETH9.compilerOutput.abi;
private _etherTokenContractsByAddress: { private readonly _etherTokenContractsByAddress: {
[address: string]: WETH9Contract; [address: string]: WETH9Contract;
} = {}; } = {};
private _erc20TokenWrapper: ERC20TokenWrapper; private readonly _erc20TokenWrapper: ERC20TokenWrapper;
/** /**
* Instantiate EtherTokenWrapper. * Instantiate EtherTokenWrapper.
* @param web3Wrapper Web3Wrapper instance to use * @param web3Wrapper Web3Wrapper instance to use
@@ -67,7 +66,7 @@ export class EtherTokenWrapper extends ContractWrapper {
const wethContract = await this._getEtherTokenContractAsync(normalizedEtherTokenAddress); const wethContract = await this._getEtherTokenContractAsync(normalizedEtherTokenAddress);
const txHash = await wethContract.deposit.sendTransactionAsync( const txHash = await wethContract.deposit.sendTransactionAsync(
removeUndefinedProperties({ utils.removeUndefinedProperties({
from: normalizedDepositorAddress, from: normalizedDepositorAddress,
value: amountInWei, value: amountInWei,
gas: txOpts.gasLimit, gas: txOpts.gasLimit,
@@ -109,7 +108,7 @@ export class EtherTokenWrapper extends ContractWrapper {
const wethContract = await this._getEtherTokenContractAsync(normalizedEtherTokenAddress); const wethContract = await this._getEtherTokenContractAsync(normalizedEtherTokenAddress);
const txHash = await wethContract.withdraw.sendTransactionAsync( const txHash = await wethContract.withdraw.sendTransactionAsync(
amountInWei, amountInWei,
removeUndefinedProperties({ utils.removeUndefinedProperties({
from: normalizedWithdrawerAddress, from: normalizedWithdrawerAddress,
gas: txOpts.gasLimit, gas: txOpts.gasLimit,
gasPrice: txOpts.gasPrice, gasPrice: txOpts.gasPrice,

View File

@@ -46,8 +46,8 @@ export class ExchangeWrapper extends ContractWrapper {
public address: string; public address: string;
public zrxTokenAddress: string; public zrxTokenAddress: string;
private _exchangeContractIfExists?: ExchangeContract; private _exchangeContractIfExists?: ExchangeContract;
private _erc721TokenWrapper: ERC721TokenWrapper; private readonly _erc721TokenWrapper: ERC721TokenWrapper;
private _erc20TokenWrapper: ERC20TokenWrapper; private readonly _erc20TokenWrapper: ERC20TokenWrapper;
/** /**
* Instantiate ExchangeWrapper * Instantiate ExchangeWrapper
* @param web3Wrapper Web3Wrapper instance to use. * @param web3Wrapper Web3Wrapper instance to use.

View File

@@ -1,7 +1,7 @@
import { ForwarderContract } from '@0x/abi-gen-wrappers'; import { ForwarderContract } from '@0x/abi-gen-wrappers';
import { Forwarder } from '@0x/contract-artifacts'; import { Forwarder } from '@0x/contract-artifacts';
import { schemas } from '@0x/json-schemas'; import { schemas } from '@0x/json-schemas';
import { AssetProxyId, SignedOrder } from '@0x/types'; import { SignedOrder } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper'; import { Web3Wrapper } from '@0x/web3-wrapper';
import { ContractAbi } from 'ethereum-types'; import { ContractAbi } from 'ethereum-types';
@@ -118,7 +118,7 @@ export class ForwarderWrapper extends ContractWrapper {
optimizedFeeOrders, optimizedFeeOrders,
feeSignatures, feeSignatures,
formattedFeePercentage, formattedFeePercentage,
feeRecipientAddress, normalizedFeeRecipientAddress,
{ {
value: ethAmount, value: ethAmount,
from: normalizedTakerAddress, from: normalizedTakerAddress,
@@ -207,7 +207,7 @@ export class ForwarderWrapper extends ContractWrapper {
optimizedFeeOrders, optimizedFeeOrders,
feeSignatures, feeSignatures,
formattedFeePercentage, formattedFeePercentage,
feeRecipientAddress, normalizedFeeRecipientAddress,
{ {
value: ethAmount, value: ethAmount,
from: normalizedTakerAddress, from: normalizedTakerAddress,

View File

@@ -1,5 +1,6 @@
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper'; import { Web3Wrapper } from '@0x/web3-wrapper';
import * as _ from 'lodash';
import { constants } from './constants'; import { constants } from './constants';
@@ -14,4 +15,7 @@ export const utils = {
numberPercentageToEtherTokenAmountPercentage(percentage: number): BigNumber { numberPercentageToEtherTokenAmountPercentage(percentage: number): BigNumber {
return Web3Wrapper.toBaseUnitAmount(constants.ONE_AMOUNT, constants.ETHER_TOKEN_DECIMALS).mul(percentage); return Web3Wrapper.toBaseUnitAmount(constants.ONE_AMOUNT, constants.ETHER_TOKEN_DECIMALS).mul(percentage);
}, },
removeUndefinedProperties<T extends object>(obj: T): Partial<T> {
return _.pickBy(obj);
},
}; };