aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/src/utils
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-08-15 10:16:36 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-08-15 10:16:36 +0800
commitbb992f8a49b42a1cd50d5bcc868f6d69fcd1a7ae (patch)
tree0b73d89e588b14dc4169472a4fc4a3527cfeda0d /packages/connect/src/utils
parent3eeb9ddfa6440d9287c0b2e6c6c51847cedf8b96 (diff)
downloaddexon-sol-tools-bb992f8a49b42a1cd50d5bcc868f6d69fcd1a7ae.tar
dexon-sol-tools-bb992f8a49b42a1cd50d5bcc868f6d69fcd1a7ae.tar.gz
dexon-sol-tools-bb992f8a49b42a1cd50d5bcc868f6d69fcd1a7ae.tar.bz2
dexon-sol-tools-bb992f8a49b42a1cd50d5bcc868f6d69fcd1a7ae.tar.lz
dexon-sol-tools-bb992f8a49b42a1cd50d5bcc868f6d69fcd1a7ae.tar.xz
dexon-sol-tools-bb992f8a49b42a1cd50d5bcc868f6d69fcd1a7ae.tar.zst
dexon-sol-tools-bb992f8a49b42a1cd50d5bcc868f6d69fcd1a7ae.zip
Update parsing code
Diffstat (limited to 'packages/connect/src/utils')
-rw-r--r--packages/connect/src/utils/relayer_response_json_parsers.ts22
-rw-r--r--packages/connect/src/utils/type_converters.ts17
2 files changed, 27 insertions, 12 deletions
diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts
index 6463aefb0..9a17b23d3 100644
--- a/packages/connect/src/utils/relayer_response_json_parsers.ts
+++ b/packages/connect/src/utils/relayer_response_json_parsers.ts
@@ -1,14 +1,16 @@
import { assert } from '@0xproject/assert';
import { schemas } from '@0xproject/json-schemas';
-import { SignedOrder } from '@0xproject/types';
-import { AssetPairsItem, OrderbookResponse, OrderConfigResponse } from '../types';
+import { APIOrder, AssetPairsItem, AssetPairsResponse, OrderbookResponse, OrderConfigResponse, OrdersResponse } from '../types';
import { typeConverters } from './type_converters';
export const relayerResponseJsonParsers = {
- parseAssetDataPairsJson(json: any): AssetPairsItem[] {
+ parseAssetDataPairsJson(json: any): AssetPairsResponse {
assert.doesConformToSchema('assetDataPairs', json, schemas.relayerApiAssetDataPairsResponseSchema);
+ return { ...json, records: relayerResponseJsonParsers.parseAssetDataPairsJson(json.records) };
+ },
+ parseAssetPairsItemJson(json: any): AssetPairsItem[] {
return json.map((assetDataPair: any) => {
return typeConverters.convertStringsFieldsToBigNumbers(assetDataPair, [
'assetDataA.minAmount',
@@ -18,20 +20,20 @@ export const relayerResponseJsonParsers = {
]);
});
},
- parseOrdersJson(json: any): SignedOrder[] {
- assert.doesConformToSchema('orders', json, schemas.signedOrdersSchema);
- return json.map((order: object) => typeConverters.convertOrderStringFieldsToBigNumber(order));
+ parseOrdersJson(json: any): OrdersResponse {
+ assert.doesConformToSchema('relayerApiOrdersResponse', json, schemas.relayerApiOrdersResponseSchema);
+ return { ...json, records: json.records.map(relayerResponseJsonParsers.parseAPIOrderJson.bind(relayerResponseJsonParsers)) };
},
- parseOrderJson(json: any): SignedOrder {
- assert.doesConformToSchema('order', json, schemas.signedOrderSchema);
+ parseAPIOrderJson(json: any): APIOrder {
+ assert.doesConformToSchema('relayerApiOrder', json, schemas.relayerApiOrderSchema);
return typeConverters.convertOrderStringFieldsToBigNumber(json);
},
parseOrderbookResponseJson(json: any): OrderbookResponse {
- assert.doesConformToSchema('orderBook', json, schemas.relayerApiOrdersResponseSchema);
+ assert.doesConformToSchema('orderBook', json, schemas.relayerApiOrderbookResponseSchema);
return typeConverters.convertOrderbookStringFieldsToBigNumber(json);
},
parseOrderConfigResponseJson(json: any): OrderConfigResponse {
- assert.doesConformToSchema('fees', json, schemas.relayerApiOrderConfigResponseSchema);
+ assert.doesConformToSchema('orderConfig', json, schemas.relayerApiOrderConfigResponseSchema);
return typeConverters.convertStringsFieldsToBigNumbers(json, ['makerFee', 'takerFee']);
},
};
diff --git a/packages/connect/src/utils/type_converters.ts b/packages/connect/src/utils/type_converters.ts
index 513f9b39f..c28cba0e1 100644
--- a/packages/connect/src/utils/type_converters.ts
+++ b/packages/connect/src/utils/type_converters.ts
@@ -1,15 +1,28 @@
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, [
'makerAssetAmount',