diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-08-24 01:52:09 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-08-24 01:52:09 +0800 |
commit | 7ad1a18a4aaa3da23fc013c55babea286a505f9d (patch) | |
tree | ae0e8267091b45dcdf661ec8cd76ce7699a82364 /packages/connect/src/utils/type_converters.ts | |
parent | 572ad4615a3a0fa5649549cbd65eb912ea7a0e92 (diff) | |
parent | b013cf2e145825a9e250c61bc77825384b2af69e (diff) | |
download | dexon-sol-tools-7ad1a18a4aaa3da23fc013c55babea286a505f9d.tar dexon-sol-tools-7ad1a18a4aaa3da23fc013c55babea286a505f9d.tar.gz dexon-sol-tools-7ad1a18a4aaa3da23fc013c55babea286a505f9d.tar.bz2 dexon-sol-tools-7ad1a18a4aaa3da23fc013c55babea286a505f9d.tar.lz dexon-sol-tools-7ad1a18a4aaa3da23fc013c55babea286a505f9d.tar.xz dexon-sol-tools-7ad1a18a4aaa3da23fc013c55babea286a505f9d.tar.zst dexon-sol-tools-7ad1a18a4aaa3da23fc013c55babea286a505f9d.zip |
Merge branch 'development' into feature/forwarder-helper/init
* development: (31 commits)
Update CI config to check development instead of v2-prototype branch
fix: Make non-interactive npm login for publish tests more robust
Run prettier
Remove comment in updates json-schemas doc
Add documentation for json-schemas
Fix typo
Remove artifacts
Update variable names, make release candidate
Update more names in docs
Improve documentation
Pin sra-report to 0xproject/connect v1.0.4
Run prettier
lint everything
Update websocket for SRA v2
Remove default query parameters
Add networkId request param option
Rename websocket files and types
Use uuid as string for requestId
Update changelogs
Add fee recipients test
...
Diffstat (limited to 'packages/connect/src/utils/type_converters.ts')
-rw-r--r-- | packages/connect/src/utils/type_converters.ts | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/packages/connect/src/utils/type_converters.ts b/packages/connect/src/utils/type_converters.ts index 210d452b9..4b211a0b2 100644 --- a/packages/connect/src/utils/type_converters.ts +++ b/packages/connect/src/utils/type_converters.ts @@ -1,29 +1,47 @@ import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; +import { APIOrder } from '../types'; + export const typeConverters = { convertOrderbookStringFieldsToBigNumber(orderbook: any): any { const bids = _.get(orderbook, 'bids', []); const asks = _.get(orderbook, 'asks', []); + const convertedBids = { + ...bids, + records: bids.records.map((order: any) => typeConverters.convertAPIOrderStringFieldsToBigNumber(order)), + }; + const convertedAsks = { + ...asks, + records: asks.records.map((order: any) => typeConverters.convertAPIOrderStringFieldsToBigNumber(order)), + }; return { - bids: bids.map((order: any) => typeConverters.convertOrderStringFieldsToBigNumber(order)), - asks: asks.map((order: any) => typeConverters.convertOrderStringFieldsToBigNumber(order)), + bids: convertedBids, + asks: convertedAsks, }; }, + convertAPIOrderStringFieldsToBigNumber(apiOrder: any): APIOrder { + return { ...apiOrder, order: typeConverters.convertOrderStringFieldsToBigNumber(apiOrder.order) }; + }, convertOrderStringFieldsToBigNumber(order: any): any { return typeConverters.convertStringsFieldsToBigNumbers(order, [ - 'makerTokenAmount', - 'takerTokenAmount', + 'makerAssetAmount', + 'takerAssetAmount', 'makerFee', 'takerFee', - 'expirationUnixTimestampSec', + 'expirationTimeSeconds', 'salt', ]); }, convertStringsFieldsToBigNumbers(obj: any, fields: string[]): any { const result = _.assign({}, obj); _.each(fields, field => { - _.update(result, field, (value: string) => new BigNumber(value)); + _.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; }, |