From 82a01ef0200571d7e9079647d6b70d2d25e6ce05 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Wed, 29 Aug 2018 14:33:55 -0700 Subject: Initial changes for v2 portal --- packages/website/ts/utils/order_parser.ts | 35 +++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'packages/website/ts/utils/order_parser.ts') diff --git a/packages/website/ts/utils/order_parser.ts b/packages/website/ts/utils/order_parser.ts index be08da80e..e542bb484 100644 --- a/packages/website/ts/utils/order_parser.ts +++ b/packages/website/ts/utils/order_parser.ts @@ -1,12 +1,12 @@ -import { logUtils } from '@0xproject/utils'; +import { BigNumber, logUtils } from '@0xproject/utils'; import * as _ from 'lodash'; import { portalOrderSchema } from 'ts/schemas/portal_order_schema'; import { validator } from 'ts/schemas/validator'; -import { Order } from 'ts/types'; +import { PortalOrder } from 'ts/types'; export const orderParser = { - parse(queryString: string): Order | undefined { + parse(queryString: string): PortalOrder | undefined { if (queryString.length === 0) { return undefined; } @@ -28,6 +28,33 @@ export const orderParser = { logUtils.log(`Invalid shared order: ${validationResult.errors}`); return undefined; } - return order; + const result = convertOrderStringFieldsToBigNumber(order); + 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; +} -- cgit v1.2.3