diff options
author | Brandon Millman <brandon@0xproject.com> | 2018-01-10 06:38:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-10 06:38:33 +0800 |
commit | 40c7ee63557b1795340c315eb9fab1dcfe092bed (patch) | |
tree | 864f5b616e9efb38b0282ab829871f794df0b0cd /packages/connect/src/http_client.ts | |
parent | 7a56e83fa3ca02d796deba3359da480834a9f6ea (diff) | |
parent | eb760aa33f0e158b3d26058aa1e9906a1f400a14 (diff) | |
download | dexon-sol-tools-40c7ee63557b1795340c315eb9fab1dcfe092bed.tar dexon-sol-tools-40c7ee63557b1795340c315eb9fab1dcfe092bed.tar.gz dexon-sol-tools-40c7ee63557b1795340c315eb9fab1dcfe092bed.tar.bz2 dexon-sol-tools-40c7ee63557b1795340c315eb9fab1dcfe092bed.tar.lz dexon-sol-tools-40c7ee63557b1795340c315eb9fab1dcfe092bed.tar.xz dexon-sol-tools-40c7ee63557b1795340c315eb9fab1dcfe092bed.tar.zst dexon-sol-tools-40c7ee63557b1795340c315eb9fab1dcfe092bed.zip |
Merge pull request #311 from 0xProject/fix/httpClientJsonParsing
Merge connect json parsing refactor into development
Diffstat (limited to 'packages/connect/src/http_client.ts')
-rw-r--r-- | packages/connect/src/http_client.ts | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index dcaf5d9a9..5604a9607 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -18,7 +18,7 @@ import { TokenPairsItem, TokenPairsRequest, } from './types'; -import { typeConverters } from './utils/type_converters'; +import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers'; /** * This class includes all the functionality related to interacting with a set of HTTP endpoints @@ -48,16 +48,8 @@ export class HttpClient implements Client { const requestOpts = { params: request, }; - const tokenPairs = await this._requestAsync('/token_pairs', HttpRequestType.Get, requestOpts); - assert.doesConformToSchema('tokenPairs', tokenPairs, schemas.relayerApiTokenPairsResponseSchema); - _.each(tokenPairs, (tokenPair: object) => { - typeConverters.convertStringsFieldsToBigNumbers(tokenPair, [ - 'tokenA.minAmount', - 'tokenA.maxAmount', - 'tokenB.minAmount', - 'tokenB.maxAmount', - ]); - }); + const responseJson = await this._requestAsync('/token_pairs', HttpRequestType.Get, requestOpts); + const tokenPairs = relayerResponseJsonParsers.parseTokenPairsJson(responseJson); return tokenPairs; } /** @@ -72,9 +64,8 @@ export class HttpClient implements Client { const requestOpts = { params: request, }; - const orders = await this._requestAsync(`/orders`, HttpRequestType.Get, requestOpts); - assert.doesConformToSchema('orders', orders, schemas.signedOrdersSchema); - _.each(orders, (order: object) => typeConverters.convertOrderStringFieldsToBigNumber(order)); + const responseJson = await this._requestAsync(`/orders`, HttpRequestType.Get, requestOpts); + const orders = relayerResponseJsonParsers.parseOrdersJson(responseJson); return orders; } /** @@ -84,9 +75,8 @@ export class HttpClient implements Client { */ public async getOrderAsync(orderHash: string): Promise<SignedOrder> { assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema); - const order = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get); - assert.doesConformToSchema('order', order, schemas.signedOrderSchema); - typeConverters.convertOrderStringFieldsToBigNumber(order); + const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get); + const order = relayerResponseJsonParsers.parseOrderJson(responseJson); return order; } /** @@ -99,10 +89,9 @@ export class HttpClient implements Client { const requestOpts = { params: request, }; - const orderBook = await this._requestAsync('/orderbook', HttpRequestType.Get, requestOpts); - assert.doesConformToSchema('orderBook', orderBook, schemas.relayerApiOrderBookResponseSchema); - typeConverters.convertOrderbookStringFieldsToBigNumber(orderBook); - return orderBook; + const responseJson = await this._requestAsync('/orderbook', HttpRequestType.Get, requestOpts); + const orderbook = relayerResponseJsonParsers.parseOrderbookResponseJson(responseJson); + return orderbook; } /** * Retrieve fee information from the API @@ -114,9 +103,8 @@ export class HttpClient implements Client { const requestOpts = { payload: request, }; - const fees = await this._requestAsync('/fees', HttpRequestType.Post, requestOpts); - assert.doesConformToSchema('fees', fees, schemas.relayerApiFeesResponseSchema); - typeConverters.convertStringsFieldsToBigNumbers(fees, ['makerFee', 'takerFee']); + const responseJson = await this._requestAsync('/fees', HttpRequestType.Post, requestOpts); + const fees = relayerResponseJsonParsers.parseFeesResponseJson(responseJson); return fees; } /** |