From e744e4cd989bd3ae1070c59f7baa8097f18b8b06 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 22 Dec 2017 15:05:32 +0100 Subject: Apply prettier config --- .../src/contract_wrappers/contract_wrapper.ts | 59 +++++++++++++--------- 1 file changed, 36 insertions(+), 23 deletions(-) (limited to 'packages/0x.js/src/contract_wrappers/contract_wrapper.ts') diff --git a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts index 3f07e4e47..eb7e042e7 100644 --- a/packages/0x.js/src/contract_wrappers/contract_wrapper.ts +++ b/packages/0x.js/src/contract_wrappers/contract_wrapper.ts @@ -1,6 +1,6 @@ -import {intervalUtils} from '@0xproject/utils'; -import {Web3Wrapper} from '@0xproject/web3-wrapper'; -import {Block, BlockAndLogStreamer} from 'ethereumjs-blockstream'; +import { intervalUtils } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Block, BlockAndLogStreamer } from 'ethereumjs-blockstream'; import * as _ from 'lodash'; import * as Web3 from 'web3'; @@ -17,11 +17,13 @@ import { RawLog, ZeroExError, } from '../types'; -import {AbiDecoder} from '../utils/abi_decoder'; -import {constants} from '../utils/constants'; -import {filterUtils} from '../utils/filter_utils'; +import { AbiDecoder } from '../utils/abi_decoder'; +import { constants } from '../utils/constants'; +import { filterUtils } from '../utils/filter_utils'; -const CONTRACT_NAME_TO_NOT_FOUND_ERROR: {[contractName: string]: ZeroExError} = { +const CONTRACT_NAME_TO_NOT_FOUND_ERROR: { + [contractName: string]: ZeroExError; +} = { ZRX: ZeroExError.ZRXContractDoesNotExist, EtherToken: ZeroExError.EtherTokenContractDoesNotExist, Token: ZeroExError.TokenContractDoesNotExist, @@ -34,12 +36,14 @@ export class ContractWrapper { protected _web3Wrapper: Web3Wrapper; private _networkId: number; private _abiDecoder?: AbiDecoder; - private _blockAndLogStreamerIfExists: BlockAndLogStreamer|undefined; + private _blockAndLogStreamerIfExists: BlockAndLogStreamer | undefined; private _blockAndLogStreamInterval: NodeJS.Timer; - private _filters: {[filterToken: string]: Web3.FilterObject}; - private _filterCallbacks: {[filterToken: string]: EventCallback}; - private _onLogAddedSubscriptionToken: string|undefined; - private _onLogRemovedSubscriptionToken: string|undefined; + private _filters: { [filterToken: string]: Web3.FilterObject }; + private _filterCallbacks: { + [filterToken: string]: EventCallback; + }; + private _onLogAddedSubscriptionToken: string | undefined; + private _onLogRemovedSubscriptionToken: string | undefined; constructor(web3Wrapper: Web3Wrapper, networkId: number, abiDecoder?: AbiDecoder) { this._web3Wrapper = web3Wrapper; this._networkId = networkId; @@ -71,8 +75,12 @@ export class ContractWrapper { } } protected _subscribe( - address: string, eventName: ContractEvents, indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi, - callback: EventCallback): string { + address: string, + eventName: ContractEvents, + indexFilterValues: IndexedFilterValues, + abi: Web3.ContractAbi, + callback: EventCallback, + ): string { const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi); if (_.isUndefined(this._blockAndLogStreamerIfExists)) { this._startBlockAndLogStream(); @@ -83,15 +91,20 @@ export class ContractWrapper { return filterToken; } protected async _getLogsAsync( - address: string, eventName: ContractEvents, blockRange: BlockRange, - indexFilterValues: IndexedFilterValues, abi: Web3.ContractAbi): Promise>> { + address: string, + eventName: ContractEvents, + blockRange: BlockRange, + indexFilterValues: IndexedFilterValues, + abi: Web3.ContractAbi, + ): Promise>> { const filter = filterUtils.getFilter(address, eventName, indexFilterValues, abi, blockRange); const logs = await this._web3Wrapper.getLogsAsync(filter); const logsWithDecodedArguments = _.map(logs, this._tryToDecodeLogOrNoop.bind(this)); return logsWithDecodedArguments; } protected _tryToDecodeLogOrNoop( - log: Web3.LogEntry): LogWithDecodedArgs|RawLog { + log: Web3.LogEntry, + ): LogWithDecodedArgs | RawLog { if (_.isUndefined(this._abiDecoder)) { throw new Error(InternalZeroExError.NoAbiDecoder); } @@ -99,7 +112,8 @@ export class ContractWrapper { return logWithDecodedArgs; } protected async _instantiateContractIfExistsAsync( - artifact: Artifact, addressIfExists?: string, + artifact: Artifact, + addressIfExists?: string, ): Promise { let contractAddress: string; if (_.isUndefined(addressIfExists)) { @@ -114,9 +128,7 @@ export class ContractWrapper { if (!doesContractExist) { throw new Error(CONTRACT_NAME_TO_NOT_FOUND_ERROR[artifact.contract_name]); } - const contractInstance = this._web3Wrapper.getContractInstance( - artifact.abi, contractAddress, - ); + const contractInstance = this._web3Wrapper.getContractInstance(artifact.abi, contractAddress); return contractInstance; } protected _getContractAddress(artifact: Artifact, addressIfExists?: string): string { @@ -153,7 +165,8 @@ export class ContractWrapper { const catchAllLogFilter = {}; this._blockAndLogStreamerIfExists.addLogFilter(catchAllLogFilter); this._blockAndLogStreamInterval = intervalUtils.setAsyncExcludingInterval( - this._reconcileBlockAsync.bind(this), constants.DEFAULT_BLOCK_POLLING_INTERVAL, + this._reconcileBlockAsync.bind(this), + constants.DEFAULT_BLOCK_POLLING_INTERVAL, ); let isRemoved = false; this._onLogAddedSubscriptionToken = this._blockAndLogStreamerIfExists.subscribeToOnLogAdded( @@ -179,7 +192,7 @@ export class ContractWrapper { // We need to coerce to Block type cause Web3.Block includes types for mempool blocks if (!_.isUndefined(this._blockAndLogStreamerIfExists)) { // If we clear the interval while fetching the block - this._blockAndLogStreamer will be undefined - await this._blockAndLogStreamerIfExists.reconcileNewBlock(latestBlock as any as Block); + await this._blockAndLogStreamerIfExists.reconcileNewBlock((latestBlock as any) as Block); } } catch (err) { const filterTokens = _.keys(this._filterCallbacks); -- cgit v1.2.3