diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-08-30 05:33:55 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-08-31 04:24:24 +0800 |
commit | 82a01ef0200571d7e9079647d6b70d2d25e6ce05 (patch) | |
tree | 99401fa4bd6f5cf23b9a4be8d09fdab79bf10b06 /packages/website/ts/utils/order_parser.ts | |
parent | 81ba2a8411abc84ab052a65e1c674af44b8cf746 (diff) | |
download | dexon-0x-contracts-82a01ef0200571d7e9079647d6b70d2d25e6ce05.tar dexon-0x-contracts-82a01ef0200571d7e9079647d6b70d2d25e6ce05.tar.gz dexon-0x-contracts-82a01ef0200571d7e9079647d6b70d2d25e6ce05.tar.bz2 dexon-0x-contracts-82a01ef0200571d7e9079647d6b70d2d25e6ce05.tar.lz dexon-0x-contracts-82a01ef0200571d7e9079647d6b70d2d25e6ce05.tar.xz dexon-0x-contracts-82a01ef0200571d7e9079647d6b70d2d25e6ce05.tar.zst dexon-0x-contracts-82a01ef0200571d7e9079647d6b70d2d25e6ce05.zip |
Initial changes for v2 portal
Diffstat (limited to 'packages/website/ts/utils/order_parser.ts')
-rw-r--r-- | packages/website/ts/utils/order_parser.ts | 35 |
1 files changed, 31 insertions, 4 deletions
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; +} |