Fix Tslint issues

This commit is contained in:
Fabio Berger 2018-06-25 22:58:36 +02:00
parent 7ce1e9b18d
commit 87d66ccf6c
9 changed files with 31 additions and 41 deletions

View File

@ -30,8 +30,8 @@ const schemaErrorTransformer = (error: Error) => {
*/ */
const asyncErrorHandlerFactory = (errorTransformer: ErrorTransformer) => { const asyncErrorHandlerFactory = (errorTransformer: ErrorTransformer) => {
const asyncErrorHandlingDecorator = ( const asyncErrorHandlingDecorator = (
target: object, _target: object,
key: string | symbol, _key: string | symbol,
descriptor: TypedPropertyDescriptor<AsyncMethod>, descriptor: TypedPropertyDescriptor<AsyncMethod>,
) => { ) => {
const originalMethod = descriptor.value as AsyncMethod; const originalMethod = descriptor.value as AsyncMethod;
@ -57,8 +57,8 @@ const asyncErrorHandlerFactory = (errorTransformer: ErrorTransformer) => {
const syncErrorHandlerFactory = (errorTransformer: ErrorTransformer) => { const syncErrorHandlerFactory = (errorTransformer: ErrorTransformer) => {
const syncErrorHandlingDecorator = ( const syncErrorHandlingDecorator = (
target: object, _target: object,
key: string | symbol, _key: string | symbol,
descriptor: TypedPropertyDescriptor<SyncMethod>, descriptor: TypedPropertyDescriptor<SyncMethod>,
) => { ) => {
const originalMethod = descriptor.value as SyncMethod; const originalMethod = descriptor.value as SyncMethod;

View File

@ -1,8 +1,7 @@
import { BlockParamLiteral, ExchangeContractErrs } from '@0xproject/types'; import { ExchangeContractErrs } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils'; import { BigNumber } from '@0xproject/utils';
import { AbstractBalanceAndProxyAllowanceLazyStore } from '../abstract/abstract_balance_and_proxy_allowance_lazy_store'; import { AbstractBalanceAndProxyAllowanceLazyStore } from '../abstract/abstract_balance_and_proxy_allowance_lazy_store';
import { TokenWrapper } from '../contract_wrappers/token_wrapper';
import { TradeSide, TransferType } from '../types'; import { TradeSide, TransferType } from '../types';
import { constants } from '../utils/constants'; import { constants } from '../utils/constants';

View File

@ -30,7 +30,7 @@ export const filterUtils = {
blockRange?: BlockRange, blockRange?: BlockRange,
): FilterObject { ): FilterObject {
const eventAbi = _.find(abi, { name: eventName }) as EventAbi; const eventAbi = _.find(abi, { name: eventName }) as EventAbi;
const eventSignature = filterUtils.getEventSignatureFromAbiByName(eventAbi, eventName); const eventSignature = filterUtils.getEventSignatureFromAbiByName(eventAbi);
const topicForEventSignature = ethUtil.addHexPrefix(jsSHA3.keccak256(eventSignature)); const topicForEventSignature = ethUtil.addHexPrefix(jsSHA3.keccak256(eventSignature));
const topicsForIndexedArgs = filterUtils.getTopicsForIndexedArgs(eventAbi, indexFilterValues); const topicsForIndexedArgs = filterUtils.getTopicsForIndexedArgs(eventAbi, indexFilterValues);
const topics = [topicForEventSignature, ...topicsForIndexedArgs]; const topics = [topicForEventSignature, ...topicsForIndexedArgs];
@ -46,7 +46,7 @@ export const filterUtils = {
} }
return filter; return filter;
}, },
getEventSignatureFromAbiByName(eventAbi: EventAbi, eventName: ContractEvents): string { getEventSignatureFromAbiByName(eventAbi: EventAbi): string {
const types = _.map(eventAbi.inputs, 'type'); const types = _.map(eventAbi.inputs, 'type');
const signature = `${eventAbi.name}(${types.join(',')})`; const signature = `${eventAbi.name}(${types.join(',')})`;
return signature; return signature;

View File

@ -277,7 +277,7 @@ describe('EtherTokenWrapper', () => {
it('should cancel outstanding subscriptions when ZeroEx.setProvider is called', (done: DoneCallback) => { it('should cancel outstanding subscriptions when ZeroEx.setProvider is called', (done: DoneCallback) => {
(async () => { (async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)( const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
(logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => { (_logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled')); done(new Error('Expected this subscription to have been cancelled'));
}, },
); );
@ -307,7 +307,7 @@ describe('EtherTokenWrapper', () => {
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => { it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => { (async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)( const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
(logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => { (_logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled')); done(new Error('Expected this subscription to have been cancelled'));
}, },
); );

View File

@ -999,7 +999,7 @@ describe('ExchangeWrapper', () => {
it('Outstanding subscriptions are cancelled when contractWrappers.setProvider called', (done: DoneCallback) => { it('Outstanding subscriptions are cancelled when contractWrappers.setProvider called', (done: DoneCallback) => {
(async () => { (async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)( const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
(logEvent: DecodedLogEvent<LogFillContractEventArgs>) => { (_logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled')); done(new Error('Expected this subscription to have been cancelled'));
}, },
); );
@ -1024,7 +1024,7 @@ describe('ExchangeWrapper', () => {
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => { it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => { (async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)( const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
(logEvent: DecodedLogEvent<LogFillContractEventArgs>) => { (_logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled')); done(new Error('Expected this subscription to have been cancelled'));
}, },
); );

View File

@ -80,7 +80,7 @@ describe('SubscriptionTest', () => {
}); });
it('Should allow unsubscribeAll to be called successfully after an error', (done: DoneCallback) => { it('Should allow unsubscribeAll to be called successfully after an error', (done: DoneCallback) => {
(async () => { (async () => {
const callback = (err: Error | null, logEvent?: DecodedLogEvent<ApprovalContractEventArgs>) => _.noop; const callback = (_err: Error | null, _logEvent?: DecodedLogEvent<ApprovalContractEventArgs>) => _.noop;
contractWrappers.token.subscribe(tokenAddress, TokenEvents.Approval, indexFilterValues, callback); contractWrappers.token.subscribe(tokenAddress, TokenEvents.Approval, indexFilterValues, callback);
stubs = [ stubs = [
Sinon.stub((contractWrappers as any)._web3Wrapper, 'getBlockAsync').throws( Sinon.stub((contractWrappers as any)._web3Wrapper, 'getBlockAsync').throws(

View File

@ -484,7 +484,7 @@ describe('TokenWrapper', () => {
it('Outstanding subscriptions are cancelled when contractWrappers.setProvider called', (done: DoneCallback) => { it('Outstanding subscriptions are cancelled when contractWrappers.setProvider called', (done: DoneCallback) => {
(async () => { (async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)( const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
(logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => { (_logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled')); done(new Error('Expected this subscription to have been cancelled'));
}, },
); );
@ -508,7 +508,7 @@ describe('TokenWrapper', () => {
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => { it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => { (async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)( const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
(logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => { (_logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled')); done(new Error('Expected this subscription to have been cancelled'));
}, },
); );

View File

@ -19,24 +19,9 @@ import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { artifacts } from '../artifacts'; import { artifacts } from '../artifacts';
import { import { EtherTokenContractEventArgs, EtherTokenEvents } from '../generated_contract_wrappers/ether_token';
DepositContractEventArgs, import { ExchangeContractEventArgs, ExchangeEvents } from '../generated_contract_wrappers/exchange';
EtherTokenContractEventArgs, import { TokenContractEventArgs, TokenEvents } from '../generated_contract_wrappers/token';
EtherTokenEvents,
WithdrawalContractEventArgs,
} from '../generated_contract_wrappers/ether_token';
import {
ExchangeContractEventArgs,
ExchangeEvents,
LogCancelContractEventArgs,
LogFillContractEventArgs,
} from '../generated_contract_wrappers/exchange';
import {
ApprovalContractEventArgs,
TokenContractEventArgs,
TokenEvents,
TransferContractEventArgs,
} from '../generated_contract_wrappers/token';
import { OnOrderStateChangeCallback, OrderWatcherConfig, OrderWatcherError } from '../types'; import { OnOrderStateChangeCallback, OrderWatcherConfig, OrderWatcherError } from '../types';
import { assert } from '../utils/assert'; import { assert } from '../utils/assert';
@ -252,7 +237,7 @@ export class OrderWatcher {
switch (decodedLog.event) { switch (decodedLog.event) {
case TokenEvents.Approval: { case TokenEvents.Approval: {
// Invalidate cache // Invalidate cache
const args = decodedLog.args as ApprovalContractEventArgs; const args = decodedLog.args;
this._balanceAndProxyAllowanceLazyStore.deleteProxyAllowance(decodedLog.address, args._owner); this._balanceAndProxyAllowanceLazyStore.deleteProxyAllowance(decodedLog.address, args._owner);
// Revalidate orders // Revalidate orders
makerToken = decodedLog.address; makerToken = decodedLog.address;
@ -268,7 +253,7 @@ export class OrderWatcher {
} }
case TokenEvents.Transfer: { case TokenEvents.Transfer: {
// Invalidate cache // Invalidate cache
const args = decodedLog.args as TransferContractEventArgs; const args = decodedLog.args;
this._balanceAndProxyAllowanceLazyStore.deleteBalance(decodedLog.address, args._from); this._balanceAndProxyAllowanceLazyStore.deleteBalance(decodedLog.address, args._from);
this._balanceAndProxyAllowanceLazyStore.deleteBalance(decodedLog.address, args._to); this._balanceAndProxyAllowanceLazyStore.deleteBalance(decodedLog.address, args._to);
// Revalidate orders // Revalidate orders
@ -285,7 +270,7 @@ export class OrderWatcher {
} }
case EtherTokenEvents.Deposit: { case EtherTokenEvents.Deposit: {
// Invalidate cache // Invalidate cache
const args = decodedLog.args as DepositContractEventArgs; const args = decodedLog.args;
this._balanceAndProxyAllowanceLazyStore.deleteBalance(decodedLog.address, args._owner); this._balanceAndProxyAllowanceLazyStore.deleteBalance(decodedLog.address, args._owner);
// Revalidate orders // Revalidate orders
makerToken = decodedLog.address; makerToken = decodedLog.address;
@ -301,7 +286,7 @@ export class OrderWatcher {
} }
case EtherTokenEvents.Withdrawal: { case EtherTokenEvents.Withdrawal: {
// Invalidate cache // Invalidate cache
const args = decodedLog.args as WithdrawalContractEventArgs; const args = decodedLog.args;
this._balanceAndProxyAllowanceLazyStore.deleteBalance(decodedLog.address, args._owner); this._balanceAndProxyAllowanceLazyStore.deleteBalance(decodedLog.address, args._owner);
// Revalidate orders // Revalidate orders
makerToken = decodedLog.address; makerToken = decodedLog.address;
@ -317,7 +302,7 @@ export class OrderWatcher {
} }
case ExchangeEvents.LogFill: { case ExchangeEvents.LogFill: {
// Invalidate cache // Invalidate cache
const args = decodedLog.args as LogFillContractEventArgs; const args = decodedLog.args;
this._orderFilledCancelledLazyStore.deleteFilledTakerAmount(args.orderHash); this._orderFilledCancelledLazyStore.deleteFilledTakerAmount(args.orderHash);
// Revalidate orders // Revalidate orders
const orderHash = args.orderHash; const orderHash = args.orderHash;
@ -329,7 +314,7 @@ export class OrderWatcher {
} }
case ExchangeEvents.LogCancel: { case ExchangeEvents.LogCancel: {
// Invalidate cache // Invalidate cache
const args = decodedLog.args as LogCancelContractEventArgs; const args = decodedLog.args;
this._orderFilledCancelledLazyStore.deleteCancelledTakerAmount(args.orderHash); this._orderFilledCancelledLazyStore.deleteCancelledTakerAmount(args.orderHash);
// Revalidate orders // Revalidate orders
const orderHash = args.orderHash; const orderHash = args.orderHash;

View File

@ -33,6 +33,9 @@ describe('EthLightwalletSubprovider', () => {
return new Promise<lightwallet.keystore>(resolve => { return new Promise<lightwallet.keystore>(resolve => {
// Create Vault // Create Vault
lightwallet.keystore.createVault(vaultOptions, (err: Error, vaultKeystore) => { lightwallet.keystore.createVault(vaultOptions, (err: Error, vaultKeystore) => {
if (err) {
throw new Error(`Failed to createVault: ${err}`);
}
resolve(vaultKeystore); resolve(vaultKeystore);
}); });
}); });
@ -41,6 +44,9 @@ describe('EthLightwalletSubprovider', () => {
const deriveKeyFromPasswordAsync = async (vaultKeystore: lightwallet.keystore) => { const deriveKeyFromPasswordAsync = async (vaultKeystore: lightwallet.keystore) => {
return new Promise<Uint8Array>(resolve => { return new Promise<Uint8Array>(resolve => {
vaultKeystore.keyFromPassword(PASSWORD, (err: Error, passwordDerivedKey: Uint8Array) => { vaultKeystore.keyFromPassword(PASSWORD, (err: Error, passwordDerivedKey: Uint8Array) => {
if (err) {
throw new Error(`Failed to get key from password: ${err}`);
}
resolve(passwordDerivedKey); resolve(passwordDerivedKey);
}); });
}); });
@ -154,7 +160,7 @@ describe('EthLightwalletSubprovider', () => {
params: ['0x0000000000000000000000000000000000000000', nonHexMessage], params: ['0x0000000000000000000000000000000000000000', nonHexMessage],
id: 1, id: 1,
}; };
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { const callback = reportCallbackErrors(done)((err: Error, _response: JSONRPCResponsePayload) => {
expect(err).to.not.be.a('null'); expect(err).to.not.be.a('null');
expect(err.message).to.be.equal('Expected data to be of type HexString, encountered: hello world'); expect(err.message).to.be.equal('Expected data to be of type HexString, encountered: hello world');
done(); done();
@ -169,7 +175,7 @@ describe('EthLightwalletSubprovider', () => {
params: [nonHexMessage, '0x0000000000000000000000000000000000000000'], params: [nonHexMessage, '0x0000000000000000000000000000000000000000'],
id: 1, id: 1,
}; };
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => { const callback = reportCallbackErrors(done)((err: Error, _response: JSONRPCResponsePayload) => {
expect(err).to.not.be.a('null'); expect(err).to.not.be.a('null');
expect(err.message).to.be.equal('Expected data to be of type HexString, encountered: hello world'); expect(err.message).to.be.equal('Expected data to be of type HexString, encountered: hello world');
done(); done();