Add new underscore-privates rule to @0xproject/tslint-config and fix lint errors
This commit is contained in:
		
				
					committed by
					
						
						Leonid Logvinov
					
				
			
			
				
	
			
			
			
						parent
						
							972e1675f6
						
					
				
				
					commit
					cb11aec84d
				
			@@ -11,24 +11,24 @@ import {constants} from './constants';
 | 
			
		||||
const INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS = new BigNumber(100);
 | 
			
		||||
 | 
			
		||||
export class FillScenarios {
 | 
			
		||||
    private zeroEx: ZeroEx;
 | 
			
		||||
    private userAddresses: string[];
 | 
			
		||||
    private tokens: Token[];
 | 
			
		||||
    private coinbase: string;
 | 
			
		||||
    private zrxTokenAddress: string;
 | 
			
		||||
    private exchangeContractAddress: string;
 | 
			
		||||
    private _zeroEx: ZeroEx;
 | 
			
		||||
    private _userAddresses: string[];
 | 
			
		||||
    private _tokens: Token[];
 | 
			
		||||
    private _coinbase: string;
 | 
			
		||||
    private _zrxTokenAddress: string;
 | 
			
		||||
    private _exchangeContractAddress: string;
 | 
			
		||||
    constructor(zeroEx: ZeroEx, userAddresses: string[],
 | 
			
		||||
                tokens: Token[], zrxTokenAddress: string, exchangeContractAddress: string) {
 | 
			
		||||
        this.zeroEx = zeroEx;
 | 
			
		||||
        this.userAddresses = userAddresses;
 | 
			
		||||
        this.tokens = tokens;
 | 
			
		||||
        this.coinbase = userAddresses[0];
 | 
			
		||||
        this.zrxTokenAddress = zrxTokenAddress;
 | 
			
		||||
        this.exchangeContractAddress = exchangeContractAddress;
 | 
			
		||||
        this._zeroEx = zeroEx;
 | 
			
		||||
        this._userAddresses = userAddresses;
 | 
			
		||||
        this._tokens = tokens;
 | 
			
		||||
        this._coinbase = userAddresses[0];
 | 
			
		||||
        this._zrxTokenAddress = zrxTokenAddress;
 | 
			
		||||
        this._exchangeContractAddress = exchangeContractAddress;
 | 
			
		||||
    }
 | 
			
		||||
    public async initTokenBalancesAsync() {
 | 
			
		||||
        const web3Wrapper = (this.zeroEx as any)._web3Wrapper as Web3Wrapper;
 | 
			
		||||
        for (const token of this.tokens) {
 | 
			
		||||
        const web3Wrapper = (this._zeroEx as any)._web3Wrapper as Web3Wrapper;
 | 
			
		||||
        for (const token of this._tokens) {
 | 
			
		||||
            if (token.symbol !== 'ZRX' && token.symbol !== 'WETH') {
 | 
			
		||||
                const contractInstance = web3Wrapper.getContractInstance(
 | 
			
		||||
                    artifacts.DummyTokenArtifact.abi, token.address,
 | 
			
		||||
@@ -36,10 +36,10 @@ export class FillScenarios {
 | 
			
		||||
                const defaults = {};
 | 
			
		||||
                const dummyToken = new DummyTokenContract(contractInstance, defaults);
 | 
			
		||||
                const tokenSupply = ZeroEx.toBaseUnitAmount(INITIAL_COINBASE_TOKEN_SUPPLY_IN_UNITS, token.decimals);
 | 
			
		||||
                const txHash = await dummyToken.setBalance.sendTransactionAsync(this.coinbase, tokenSupply, {
 | 
			
		||||
                    from: this.coinbase,
 | 
			
		||||
                const txHash = await dummyToken.setBalance.sendTransactionAsync(this._coinbase, tokenSupply, {
 | 
			
		||||
                    from: this._coinbase,
 | 
			
		||||
                });
 | 
			
		||||
                await this.zeroEx.awaitTransactionMinedAsync(txHash);
 | 
			
		||||
                await this._zeroEx.awaitTransactionMinedAsync(txHash);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -60,7 +60,7 @@ export class FillScenarios {
 | 
			
		||||
        fillableAmount: BigNumber,
 | 
			
		||||
        feeRecepient: string, expirationUnixTimestampSec?: BigNumber,
 | 
			
		||||
    ): Promise<SignedOrder> {
 | 
			
		||||
        return this.createAsymmetricFillableSignedOrderWithFeesAsync(
 | 
			
		||||
        return this._createAsymmetricFillableSignedOrderWithFeesAsync(
 | 
			
		||||
            makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress,
 | 
			
		||||
            fillableAmount, fillableAmount, feeRecepient, expirationUnixTimestampSec,
 | 
			
		||||
        );
 | 
			
		||||
@@ -72,7 +72,7 @@ export class FillScenarios {
 | 
			
		||||
        const makerFee = new BigNumber(0);
 | 
			
		||||
        const takerFee = new BigNumber(0);
 | 
			
		||||
        const feeRecepient = constants.NULL_ADDRESS;
 | 
			
		||||
        return this.createAsymmetricFillableSignedOrderWithFeesAsync(
 | 
			
		||||
        return this._createAsymmetricFillableSignedOrderWithFeesAsync(
 | 
			
		||||
            makerTokenAddress, takerTokenAddress, makerFee, takerFee, makerAddress, takerAddress,
 | 
			
		||||
            makerFillableAmount, takerFillableAmount, feeRecepient, expirationUnixTimestampSec,
 | 
			
		||||
        );
 | 
			
		||||
@@ -80,18 +80,18 @@ export class FillScenarios {
 | 
			
		||||
    public async createPartiallyFilledSignedOrderAsync(makerTokenAddress: string, takerTokenAddress: string,
 | 
			
		||||
                                                       takerAddress: string, fillableAmount: BigNumber,
 | 
			
		||||
                                                       partialFillAmount: BigNumber) {
 | 
			
		||||
        const [makerAddress] = this.userAddresses;
 | 
			
		||||
        const [makerAddress] = this._userAddresses;
 | 
			
		||||
        const signedOrder = await this.createAsymmetricFillableSignedOrderAsync(
 | 
			
		||||
            makerTokenAddress, takerTokenAddress, makerAddress, takerAddress,
 | 
			
		||||
            fillableAmount, fillableAmount,
 | 
			
		||||
        );
 | 
			
		||||
        const shouldThrowOnInsufficientBalanceOrAllowance = false;
 | 
			
		||||
        await this.zeroEx.exchange.fillOrderAsync(
 | 
			
		||||
        await this._zeroEx.exchange.fillOrderAsync(
 | 
			
		||||
            signedOrder, partialFillAmount, shouldThrowOnInsufficientBalanceOrAllowance, takerAddress,
 | 
			
		||||
        );
 | 
			
		||||
        return signedOrder;
 | 
			
		||||
    }
 | 
			
		||||
    private async createAsymmetricFillableSignedOrderWithFeesAsync(
 | 
			
		||||
    private async _createAsymmetricFillableSignedOrderWithFeesAsync(
 | 
			
		||||
        makerTokenAddress: string, takerTokenAddress: string,
 | 
			
		||||
        makerFee: BigNumber, takerFee: BigNumber,
 | 
			
		||||
        makerAddress: string, takerAddress: string,
 | 
			
		||||
@@ -99,39 +99,39 @@ export class FillScenarios {
 | 
			
		||||
        feeRecepient: string, expirationUnixTimestampSec?: BigNumber): Promise<SignedOrder> {
 | 
			
		||||
 | 
			
		||||
        await Promise.all([
 | 
			
		||||
            this.increaseBalanceAndAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount),
 | 
			
		||||
            this.increaseBalanceAndAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount),
 | 
			
		||||
            this._increaseBalanceAndAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount),
 | 
			
		||||
            this._increaseBalanceAndAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount),
 | 
			
		||||
        ]);
 | 
			
		||||
        await Promise.all([
 | 
			
		||||
            this.increaseBalanceAndAllowanceAsync(this.zrxTokenAddress, makerAddress, makerFee),
 | 
			
		||||
            this.increaseBalanceAndAllowanceAsync(this.zrxTokenAddress, takerAddress, takerFee),
 | 
			
		||||
            this._increaseBalanceAndAllowanceAsync(this._zrxTokenAddress, makerAddress, makerFee),
 | 
			
		||||
            this._increaseBalanceAndAllowanceAsync(this._zrxTokenAddress, takerAddress, takerFee),
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx,
 | 
			
		||||
        const signedOrder = await orderFactory.createSignedOrderAsync(this._zeroEx,
 | 
			
		||||
            makerAddress, takerAddress, makerFee, takerFee,
 | 
			
		||||
            makerFillableAmount, makerTokenAddress, takerFillableAmount, takerTokenAddress,
 | 
			
		||||
            this.exchangeContractAddress, feeRecepient, expirationUnixTimestampSec);
 | 
			
		||||
            this._exchangeContractAddress, feeRecepient, expirationUnixTimestampSec);
 | 
			
		||||
        return signedOrder;
 | 
			
		||||
    }
 | 
			
		||||
    private async increaseBalanceAndAllowanceAsync(
 | 
			
		||||
    private async _increaseBalanceAndAllowanceAsync(
 | 
			
		||||
        tokenAddress: string, address: string, amount: BigNumber): Promise<void> {
 | 
			
		||||
        if (amount.isZero() || address === ZeroEx.NULL_ADDRESS) {
 | 
			
		||||
            return; // noop
 | 
			
		||||
        }
 | 
			
		||||
        await Promise.all([
 | 
			
		||||
            this.increaseBalanceAsync(tokenAddress, address, amount),
 | 
			
		||||
            this.increaseAllowanceAsync(tokenAddress, address, amount),
 | 
			
		||||
            this._increaseBalanceAsync(tokenAddress, address, amount),
 | 
			
		||||
            this._increaseAllowanceAsync(tokenAddress, address, amount),
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
    private async increaseBalanceAsync(
 | 
			
		||||
    private async _increaseBalanceAsync(
 | 
			
		||||
        tokenAddress: string, address: string, amount: BigNumber): Promise<void> {
 | 
			
		||||
        await this.zeroEx.token.transferAsync(tokenAddress, this.coinbase, address, amount);
 | 
			
		||||
        await this._zeroEx.token.transferAsync(tokenAddress, this._coinbase, address, amount);
 | 
			
		||||
    }
 | 
			
		||||
    private async increaseAllowanceAsync(
 | 
			
		||||
    private async _increaseAllowanceAsync(
 | 
			
		||||
        tokenAddress: string, address: string, amount: BigNumber): Promise<void> {
 | 
			
		||||
        const oldMakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(tokenAddress, address);
 | 
			
		||||
        const oldMakerAllowance = await this._zeroEx.token.getProxyAllowanceAsync(tokenAddress, address);
 | 
			
		||||
        const newMakerAllowance = oldMakerAllowance.plus(amount);
 | 
			
		||||
        await this.zeroEx.token.setProxyAllowanceAsync(
 | 
			
		||||
        await this._zeroEx.token.setProxyAllowanceAsync(
 | 
			
		||||
            tokenAddress, address, newMakerAllowance,
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -9,16 +9,16 @@ import {JSONRPCPayload} from '../../../src/types';
 | 
			
		||||
 * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js
 | 
			
		||||
 */
 | 
			
		||||
export class FakeGasEstimateSubprovider {
 | 
			
		||||
    private constantGasAmount: number;
 | 
			
		||||
    private _constantGasAmount: number;
 | 
			
		||||
    constructor(constantGasAmount: number) {
 | 
			
		||||
        this.constantGasAmount = constantGasAmount;
 | 
			
		||||
        this._constantGasAmount = constantGasAmount;
 | 
			
		||||
    }
 | 
			
		||||
    // This method needs to be here to satisfy the interface but linter wants it to be static.
 | 
			
		||||
    // tslint:disable-next-line:prefer-function-over-method
 | 
			
		||||
    public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error|null, result: any) => void) {
 | 
			
		||||
        switch (payload.method) {
 | 
			
		||||
            case 'eth_estimateGas':
 | 
			
		||||
                end(null, this.constantGasAmount);
 | 
			
		||||
                end(null, this._constantGasAmount);
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            default:
 | 
			
		||||
 
 | 
			
		||||
@@ -6,19 +6,19 @@ const PROTOCOL_TOKEN_SYMBOL = 'ZRX';
 | 
			
		||||
const WETH_TOKEN_SYMBOL = 'WETH';
 | 
			
		||||
 | 
			
		||||
export class TokenUtils {
 | 
			
		||||
    private tokens: Token[];
 | 
			
		||||
    private _tokens: Token[];
 | 
			
		||||
    constructor(tokens: Token[]) {
 | 
			
		||||
        this.tokens = tokens;
 | 
			
		||||
        this._tokens = tokens;
 | 
			
		||||
    }
 | 
			
		||||
    public getProtocolTokenOrThrow(): Token {
 | 
			
		||||
        const zrxToken = _.find(this.tokens, {symbol: PROTOCOL_TOKEN_SYMBOL});
 | 
			
		||||
        const zrxToken = _.find(this._tokens, {symbol: PROTOCOL_TOKEN_SYMBOL});
 | 
			
		||||
        if (_.isUndefined(zrxToken)) {
 | 
			
		||||
            throw new Error(InternalZeroExError.ZrxNotInTokenRegistry);
 | 
			
		||||
        }
 | 
			
		||||
        return zrxToken;
 | 
			
		||||
    }
 | 
			
		||||
    public getDummyTokens(): Token[] {
 | 
			
		||||
        const dummyTokens = _.filter(this.tokens, token => {
 | 
			
		||||
        const dummyTokens = _.filter(this._tokens, token => {
 | 
			
		||||
            return !_.includes([PROTOCOL_TOKEN_SYMBOL, WETH_TOKEN_SYMBOL], token.symbol);
 | 
			
		||||
        });
 | 
			
		||||
        return dummyTokens;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user