diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-06-21 21:04:13 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-21 21:04:13 +0800 |
commit | 8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3 (patch) | |
tree | 15b9aa5b849d896248541722b7f2dfed6c458749 /src/contract_wrappers/exchange_wrapper.ts | |
parent | ef96c58b7f7d0ce678e8eb4f662b2f6a31e8799a (diff) | |
parent | a1c363a8af3cbfa2d843aaf7ddd05390db7b8f9b (diff) | |
download | dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar.gz dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar.bz2 dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar.lz dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar.xz dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.tar.zst dexon-sol-tools-8af7d2303ecf9d4d3cdc967a81ef577b9f8739d3.zip |
Merge pull request #71 from 0xProject/lodash-tree-shake
Use different lodash import syntax which allows to include only used functions
Diffstat (limited to 'src/contract_wrappers/exchange_wrapper.ts')
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index e33dd6f6e..6d42dc110 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -1,4 +1,8 @@ -import * as _ from 'lodash'; +import map = require('lodash/map'); +import isEmpty = require('lodash/isEmpty'); +import find = require('lodash/find'); +import isUndefined = require('lodash/isUndefined'); +import unzip = require('lodash/unzip'); import * as BigNumber from 'bignumber.js'; import promisify = require('es6-promisify'); import {Web3Wrapper} from '../web3_wrapper'; @@ -198,7 +202,7 @@ export class ExchangeWrapper extends ContractWrapper { @decorators.contractCallErrorHandler public async fillOrdersUpToAsync(signedOrders: SignedOrder[], takerTokenFillAmount: BigNumber.BigNumber, shouldCheckTransfer: boolean, takerAddress: string): Promise<void> { - const takerTokenAddresses = _.map(signedOrders, signedOrder => signedOrder.takerTokenAddress); + const takerTokenAddresses = map(signedOrders, signedOrder => signedOrder.takerTokenAddress); assert.hasAtMostOneUniqueValue(takerTokenAddresses, ExchangeContractErrs.MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO_DISALLOWED); assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount); @@ -209,11 +213,11 @@ export class ExchangeWrapper extends ContractWrapper { await this._validateFillOrderAndThrowIfInvalidAsync( signedOrder, takerTokenFillAmount, takerAddress); } - if (_.isEmpty(signedOrders)) { + if (isEmpty(signedOrders)) { return; // no-op } - const orderAddressesValuesAndSignatureArray = _.map(signedOrders, signedOrder => { + const orderAddressesValuesAndSignatureArray = map(signedOrders, signedOrder => { return [ ...ExchangeWrapper._getOrderAddressesAndValues(signedOrder), signedOrder.ecSignature.v, @@ -221,8 +225,8 @@ export class ExchangeWrapper extends ContractWrapper { signedOrder.ecSignature.s, ]; }); - // We use _.unzip<any> because _.unzip doesn't type check if values have different types :'( - const [orderAddressesArray, orderValuesArray, vArray, rArray, sArray] = _.unzip<any>( + // We use unzip<any> because unzip doesn't type check if values have different types :'( + const [orderAddressesArray, orderValuesArray, vArray, rArray, sArray] = unzip<any>( orderAddressesValuesAndSignatureArray, ); @@ -277,11 +281,11 @@ export class ExchangeWrapper extends ContractWrapper { await this._validateFillOrderAndThrowIfInvalidAsync( orderFillRequest.signedOrder, orderFillRequest.takerTokenFillAmount, takerAddress); } - if (_.isEmpty(orderFillRequests)) { + if (isEmpty(orderFillRequests)) { return; // no-op } - const orderAddressesValuesAmountsAndSignatureArray = _.map(orderFillRequests, orderFillRequest => { + const orderAddressesValuesAmountsAndSignatureArray = map(orderFillRequests, orderFillRequest => { return [ ...ExchangeWrapper._getOrderAddressesAndValues(orderFillRequest.signedOrder), orderFillRequest.takerTokenFillAmount, @@ -290,8 +294,8 @@ export class ExchangeWrapper extends ContractWrapper { orderFillRequest.signedOrder.ecSignature.s, ]; }); - // We use _.unzip<any> because _.unzip doesn't type check if values have different types :'( - const [orderAddressesArray, orderValuesArray, takerTokenFillAmountArray, vArray, rArray, sArray] = _.unzip<any>( + // We use unzip<any> because unzip doesn't type check if values have different types :'( + const [orderAddressesArray, orderValuesArray, takerTokenFillAmountArray, vArray, rArray, sArray] = unzip<any>( orderAddressesValuesAmountsAndSignatureArray, ); @@ -390,7 +394,7 @@ export class ExchangeWrapper extends ContractWrapper { request.fillTakerAmount); } - const orderAddressesValuesAndTakerTokenFillAmounts = _.map(orderFillOrKillRequests, request => { + const orderAddressesValuesAndTakerTokenFillAmounts = map(orderFillOrKillRequests, request => { return [ ...ExchangeWrapper._getOrderAddressesAndValues(request.signedOrder), request.fillTakerAmount, @@ -400,9 +404,9 @@ export class ExchangeWrapper extends ContractWrapper { ]; }); - // We use _.unzip<any> because _.unzip doesn't type check if values have different types :'( + // We use unzip<any> because unzip doesn't type check if values have different types :'( const [orderAddresses, orderValues, fillTakerAmounts, vParams, rParams, sParams] = - _.unzip<any>(orderAddressesValuesAndTakerTokenFillAmounts); + unzip<any>(orderAddressesValuesAndTakerTokenFillAmounts); const gas = await exchangeInstance.batchFillOrKill.estimateGas( orderAddresses, @@ -473,7 +477,7 @@ export class ExchangeWrapper extends ContractWrapper { */ @decorators.contractCallErrorHandler public async batchCancelOrderAsync(orderCancellationRequests: OrderCancellationRequest[]): Promise<void> { - const makers = _.map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker); + const makers = map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker); assert.hasAtMostOneUniqueValue(makers, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH_DISALLOWED); const maker = makers[0]; await assert.isSenderAddressAsync('maker', maker, this._web3Wrapper); @@ -484,19 +488,19 @@ export class ExchangeWrapper extends ContractWrapper { cancellationRequest.order, cancellationRequest.takerTokenCancelAmount, ); } - if (_.isEmpty(orderCancellationRequests)) { + if (isEmpty(orderCancellationRequests)) { return; // no-op } const exchangeInstance = await this._getExchangeContractAsync(); - const orderAddressesValuesAndTakerTokenCancelAmounts = _.map(orderCancellationRequests, cancellationRequest => { + const orderAddressesValuesAndTakerTokenCancelAmounts = map(orderCancellationRequests, cancellationRequest => { return [ ...ExchangeWrapper._getOrderAddressesAndValues(cancellationRequest.order), cancellationRequest.takerTokenCancelAmount, ]; }); - // We use _.unzip<any> because _.unzip doesn't type check if values have different types :'( + // We use unzip<any> because unzip doesn't type check if values have different types :'( const [orderAddresses, orderValues, takerTokenCancelAmounts] = - _.unzip<any>(orderAddressesValuesAndTakerTokenCancelAmounts); + unzip<any>(orderAddressesValuesAndTakerTokenCancelAmounts); const gas = await exchangeInstance.batchCancel.estimateGas( orderAddresses, orderValues, @@ -561,7 +565,7 @@ export class ExchangeWrapper extends ContractWrapper { * Stops watching for all exchange events */ public async stopWatchingAllEventsAsync(): Promise<void> { - const stopWatchingPromises = _.map(this._exchangeLogEventEmitters, + const stopWatchingPromises = map(this._exchangeLogEventEmitters, logEventObj => logEventObj.stopWatchingAsync()); await Promise.all(stopWatchingPromises); this._exchangeLogEventEmitters = []; @@ -715,8 +719,8 @@ export class ExchangeWrapper extends ContractWrapper { } } private _throwErrorLogsAsErrors(logs: ContractEvent[]): void { - const errEvent = _.find(logs, {event: 'LogError'}); - if (!_.isUndefined(errEvent)) { + const errEvent = find(logs, {event: 'LogError'}); + if (!isUndefined(errEvent)) { const errCode = (errEvent.args as LogErrorContractEventArgs).errorId.toNumber(); const errMessage = this._exchangeContractErrCodesToMsg[errCode]; throw new Error(errMessage); @@ -733,7 +737,7 @@ export class ExchangeWrapper extends ContractWrapper { return isRoundingError; } private async _getExchangeContractAsync(): Promise<ExchangeContract> { - if (!_.isUndefined(this._exchangeContractIfExists)) { + if (!isUndefined(this._exchangeContractIfExists)) { return this._exchangeContractIfExists; } const contractInstance = await this._instantiateContractIfExistsAsync((ExchangeArtifacts as any)); |