From f5237f79716fb9ab5f16a64445fb21ea715d70b8 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 4 Sep 2018 11:55:08 -0700 Subject: Use order parser utils from order utils --- packages/website/ts/utils/order_parser.ts | 33 ++++--------------------------- packages/website/ts/utils/utils.ts | 2 +- 2 files changed, 5 insertions(+), 30 deletions(-) (limited to 'packages/website/ts/utils') diff --git a/packages/website/ts/utils/order_parser.ts b/packages/website/ts/utils/order_parser.ts index 2e1d4d2f2..816200e3b 100644 --- a/packages/website/ts/utils/order_parser.ts +++ b/packages/website/ts/utils/order_parser.ts @@ -1,4 +1,5 @@ -import { BigNumber, logUtils } from '@0xproject/utils'; +import { orderParsingUtils } from '@0xproject/order-utils'; +import { logUtils } from '@0xproject/utils'; import * as _ from 'lodash'; import { portalOrderSchema } from 'ts/schemas/portal_order_schema'; @@ -29,7 +30,7 @@ export const orderParser = { return undefined; } const signedOrder = _.get(order, 'signedOrder'); - const convertedSignedOrder = convertOrderStringFieldsToBigNumber(signedOrder); + const convertedSignedOrder = orderParsingUtils.convertOrderStringFieldsToBigNumber(signedOrder); const result = { ...order, signedOrder: convertedSignedOrder, @@ -39,7 +40,7 @@ export const orderParser = { parseJsonString(orderJson: string): PortalOrder { const order = JSON.parse(orderJson); const signedOrder = _.get(order, 'signedOrder'); - const convertedSignedOrder = convertOrderStringFieldsToBigNumber(signedOrder); + const convertedSignedOrder = orderParsingUtils.convertOrderStringFieldsToBigNumber(signedOrder); const result = { ...order, signedOrder: convertedSignedOrder, @@ -47,29 +48,3 @@ export const orderParser = { return result; }, }; - -// TODO: consolidate this function with that in typeConverters in @0xproject/connect -function convertOrderStringFieldsToBigNumber(order: any): any { - return convertStringsFieldsToBigNumbers(order, [ - 'makerAssetAmount', - 'takerAssetAmount', - 'makerFee', - 'takerFee', - 'expirationTimeSeconds', - 'salt', - ]); -} - -// TODO: consolidate this function with that in typeConverters in @0xproject/connect -function convertStringsFieldsToBigNumbers(obj: any, fields: string[]): any { - const result = _.assign({}, obj); - _.each(fields, field => { - _.update(result, field, (value: string) => { - if (_.isUndefined(value)) { - throw new Error(`Could not find field '${field}' while converting string fields to BigNumber.`); - } - return new BigNumber(value); - }); - }); - return result; -} diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index eda0e513d..027810905 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -1,7 +1,7 @@ import { ContractWrappersError } from '@0xproject/contract-wrappers'; import { assetDataUtils, OrderError } from '@0xproject/order-utils'; import { constants as sharedConstants, Networks } from '@0xproject/react-shared'; -import { ECSignature, ExchangeContractErrs } from '@0xproject/types'; +import { ExchangeContractErrs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as bowser from 'bowser'; -- cgit v1.2.3