aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/src
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-08-15 05:59:53 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-08-15 07:06:09 +0800
commit5c40c466f6e9f690afa86f23dd5ba240691dceb8 (patch)
treec7eda62370f6dff4f4fd253dc1484705ea6f3cb9 /packages/connect/src
parentce88086e080e05ed71c1ef4e31f2d0ce530af67f (diff)
downloaddexon-sol-tools-5c40c466f6e9f690afa86f23dd5ba240691dceb8.tar
dexon-sol-tools-5c40c466f6e9f690afa86f23dd5ba240691dceb8.tar.gz
dexon-sol-tools-5c40c466f6e9f690afa86f23dd5ba240691dceb8.tar.bz2
dexon-sol-tools-5c40c466f6e9f690afa86f23dd5ba240691dceb8.tar.lz
dexon-sol-tools-5c40c466f6e9f690afa86f23dd5ba240691dceb8.tar.xz
dexon-sol-tools-5c40c466f6e9f690afa86f23dd5ba240691dceb8.tar.zst
dexon-sol-tools-5c40c466f6e9f690afa86f23dd5ba240691dceb8.zip
Update json-schemas, update HTTPClient types
Diffstat (limited to 'packages/connect/src')
-rw-r--r--packages/connect/src/http_client.ts36
-rw-r--r--packages/connect/src/index.ts2
-rw-r--r--packages/connect/src/types.ts6
-rw-r--r--packages/connect/src/utils/orderbook_channel_message_parser.ts10
-rw-r--r--packages/connect/src/utils/relayer_response_json_parsers.ts8
-rw-r--r--packages/connect/src/ws_orderbook_channel.ts8
6 files changed, 29 insertions, 41 deletions
diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts
index b2e15775e..20a2f9cc0 100644
--- a/packages/connect/src/http_client.ts
+++ b/packages/connect/src/http_client.ts
@@ -7,17 +7,19 @@ import * as queryString from 'query-string';
import { schemas as clientSchemas } from './schemas/schemas';
import {
+ APIOrder,
+ AssetPairsItem,
AssetPairsRequestOpts,
Client,
- OrderConfigRequest,
- OrderConfigResponse,
HttpRequestOptions,
HttpRequestType,
OrderbookRequest,
OrderbookResponse,
+ OrderConfigRequest,
+ OrderConfigResponse,
OrdersRequestOpts,
PagedRequestOpts,
- TokenPairsItem,
+ PaginatedCollection,
} from './types';
import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers';
@@ -26,12 +28,6 @@ const DEFAULT_PAGED_REQUEST_OPTS: PagedRequestOpts = {
page: 1,
perPage: 100,
};
-/**
- * This mapping defines how an option property name gets converted into an HTTP request query field
- */
-const OPTS_TO_QUERY_FIELD_MAP = {
- perPage: 'per_page',
-};
/**
* This class includes all the functionality related to interacting with a set of HTTP endpoints
@@ -47,12 +43,8 @@ export class HttpClient implements Client {
if (_.isUndefined(params) || _.isEmpty(params)) {
return '';
}
- // format params into a form the api expects
- const formattedParams = _.mapKeys(params, (_value: any, key: string) => {
- return _.get(OPTS_TO_QUERY_FIELD_MAP, key, key);
- });
// stringify the formatted object
- const stringifiedParams = queryString.stringify(formattedParams);
+ const stringifiedParams = queryString.stringify(params);
return `?${stringifiedParams}`;
}
/**
@@ -67,9 +59,9 @@ export class HttpClient implements Client {
/**
* Retrieve assetData pair info from the API
* @param requestOpts Options specifying assetData information to retrieve and page information, defaults to { page: 1, perPage: 100 }
- * @return The resulting TokenPairsItems that match the request
+ * @return The resulting AssetPairsItems that match the request
*/
- public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise<TokenPairsItem[]> {
+ public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise<PaginatedCollection<AssetPairsItem>> {
if (!_.isUndefined(requestOpts)) {
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.AssetPairsRequestOptsSchema);
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema);
@@ -78,7 +70,7 @@ export class HttpClient implements Client {
params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS),
};
const responseJson = await this._requestAsync('/assetData_pairs', HttpRequestType.Get, httpRequestOpts);
- const assetDataPairs = relayerResponseJsonParsers.parseTokenPairsJson(responseJson);
+ const assetDataPairs = relayerResponseJsonParsers.parseAssetDataPairsJson(responseJson);
return assetDataPairs;
}
/**
@@ -86,7 +78,7 @@ export class HttpClient implements Client {
* @param requestOpts Options specifying orders to retrieve and page information, defaults to { page: 1, perPage: 100 }
* @return The resulting SignedOrders that match the request
*/
- public async getOrdersAsync(requestOpts?: OrdersRequestOpts & PagedRequestOpts): Promise<SignedOrder[]> {
+ public async getOrdersAsync(requestOpts?: OrdersRequestOpts & PagedRequestOpts): Promise<PaginatedCollection<APIOrder>> {
if (!_.isUndefined(requestOpts)) {
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.ordersRequestOptsSchema);
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema);
@@ -103,7 +95,7 @@ export class HttpClient implements Client {
* @param orderHash An orderHash generated from the desired order
* @return The SignedOrder that matches the supplied orderHash
*/
- public async getOrderAsync(orderHash: string): Promise<SignedOrder> {
+ public async getOrderAsync(orderHash: string): Promise<APIOrder> {
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get);
const order = relayerResponseJsonParsers.parseOrderJson(responseJson);
@@ -144,6 +136,12 @@ export class HttpClient implements Client {
const fees = relayerResponseJsonParsers.parseOrderConfigResponseJson(responseJson);
return fees;
}
+
+ public async getFeeRecipientsAsync(): Promise<PaginatedCollection<string>> {
+ // TODO
+ return;
+ }
+
/**
* Submit a signed order to the API
* @param signedOrder A SignedOrder instance to submit
diff --git a/packages/connect/src/index.ts b/packages/connect/src/index.ts
index e57967714..e0c4293d9 100644
--- a/packages/connect/src/index.ts
+++ b/packages/connect/src/index.ts
@@ -11,7 +11,7 @@ export {
OrderbookResponse,
OrdersRequestOpts,
PagedRequestOpts,
- TokenPairsItem,
+ AssetPairsItem,
AssetPairsRequestOpts,
Asset,
} from './types';
diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts
index 0f2242329..fb51dca98 100644
--- a/packages/connect/src/types.ts
+++ b/packages/connect/src/types.ts
@@ -2,12 +2,12 @@ import { SignedOrder } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
export interface Client {
- getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise<PaginatedCollection<TokenPairsItem>>;
+ getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise<PaginatedCollection<AssetPairsItem>>;
getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise<PaginatedCollection<APIOrder>>;
getOrderAsync: (orderHash: string) => Promise<APIOrder>;
getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise<OrderbookResponse>;
getOrderConfigAsync: (request: OrderConfigRequest) => Promise<OrderConfigResponse>;
- getFeeRecipients: () => Promise<PaginatedCollection<string>>;
+ getFeeRecipientsAsync: () => Promise<PaginatedCollection<string>>;
submitOrderAsync: (signedOrder: SignedOrder) => Promise<void>;
}
@@ -81,7 +81,7 @@ export interface AssetPairsRequestOpts {
assetDataB?: string;
}
-export interface TokenPairsItem {
+export interface AssetPairsItem {
assetDataA: Asset;
assetDataB: Asset;
}
diff --git a/packages/connect/src/utils/orderbook_channel_message_parser.ts b/packages/connect/src/utils/orderbook_channel_message_parser.ts
index ca739e587..986209c54 100644
--- a/packages/connect/src/utils/orderbook_channel_message_parser.ts
+++ b/packages/connect/src/utils/orderbook_channel_message_parser.ts
@@ -6,7 +6,7 @@ import { OrdersChannelMessage, OrdersChannelMessageTypes } from '../types';
import { relayerResponseJsonParsers } from './relayer_response_json_parsers';
-export const orderbookChannelMessageParser = {
+export const ordersChannelMessageParser = {
parse(utf8Data: string): OrdersChannelMessage {
// parse the message
const messageObj = JSON.parse(utf8Data);
@@ -19,14 +19,8 @@ export const orderbookChannelMessageParser = {
assert.assert(!_.isUndefined(requestId), `Message is missing a requestId parameter: ${utf8Data}`);
assert.isNumber('requestId', requestId);
switch (type) {
- case OrdersChannelMessageTypes.Snapshot: {
- assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelSnapshotSchema);
- const orderbookJson = messageObj.payload;
- const orderbook = relayerResponseJsonParsers.parseOrderbookResponseJson(orderbookJson);
- return _.assign(messageObj, { payload: orderbook });
- }
case OrdersChannelMessageTypes.Update: {
- assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrderbookChannelUpdateSchema);
+ assert.doesConformToSchema('message', messageObj, schemas.relayerApiOrdersChannelUpdateSchema);
const orderJson = messageObj.payload;
const order = relayerResponseJsonParsers.parseOrderJson(orderJson);
return _.assign(messageObj, { payload: order });
diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts
index 55f787820..6463aefb0 100644
--- a/packages/connect/src/utils/relayer_response_json_parsers.ts
+++ b/packages/connect/src/utils/relayer_response_json_parsers.ts
@@ -2,13 +2,13 @@ import { assert } from '@0xproject/assert';
import { schemas } from '@0xproject/json-schemas';
import { SignedOrder } from '@0xproject/types';
-import { OrderConfigResponse, OrderbookResponse, TokenPairsItem } from '../types';
+import { AssetPairsItem, OrderbookResponse, OrderConfigResponse } from '../types';
import { typeConverters } from './type_converters';
export const relayerResponseJsonParsers = {
- parseTokenPairsJson(json: any): TokenPairsItem[] {
- assert.doesConformToSchema('assetDataPairs', json, schemas.relayerApiTokenPairsResponseSchema);
+ parseAssetDataPairsJson(json: any): AssetPairsItem[] {
+ assert.doesConformToSchema('assetDataPairs', json, schemas.relayerApiAssetDataPairsResponseSchema);
return json.map((assetDataPair: any) => {
return typeConverters.convertStringsFieldsToBigNumbers(assetDataPair, [
'assetDataA.minAmount',
@@ -27,7 +27,7 @@ export const relayerResponseJsonParsers = {
return typeConverters.convertOrderStringFieldsToBigNumber(json);
},
parseOrderbookResponseJson(json: any): OrderbookResponse {
- assert.doesConformToSchema('orderBook', json, schemas.relayerApiOrderBookResponseSchema);
+ assert.doesConformToSchema('orderBook', json, schemas.relayerApiOrdersResponseSchema);
return typeConverters.convertOrderbookStringFieldsToBigNumber(json);
},
parseOrderConfigResponseJson(json: any): OrderConfigResponse {
diff --git a/packages/connect/src/ws_orderbook_channel.ts b/packages/connect/src/ws_orderbook_channel.ts
index d09fd375d..3d9230792 100644
--- a/packages/connect/src/ws_orderbook_channel.ts
+++ b/packages/connect/src/ws_orderbook_channel.ts
@@ -8,7 +8,7 @@ import {
OrdersChannelMessageTypes,
} from './types';
import { assert } from './utils/assert';
-import { orderbookChannelMessageParser } from './utils/orderbook_channel_message_parser';
+import { ordersChannelMessageParser } from './utils/orderbook_channel_message_parser';
/**
* This class includes all the functionality related to interacting with a websocket endpoint
@@ -72,7 +72,7 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
}
try {
const data = message.data;
- const parserResult = orderbookChannelMessageParser.parse(data);
+ const parserResult = ordersChannelMessageParser.parse(data);
const subscriptionOpts = this._subscriptionOptsList[parserResult.requestId];
if (_.isUndefined(subscriptionOpts)) {
this._handler.onError(
@@ -82,10 +82,6 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
return;
}
switch (parserResult.type) {
- case OrdersChannelMessageTypes.Snapshot: {
- this._handler.onSnapshot(this, subscriptionOpts, parserResult.payload);
- break;
- }
case OrdersChannelMessageTypes.Update: {
this._handler.onUpdate(this, subscriptionOpts, parserResult.payload);
break;