aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect/src
diff options
context:
space:
mode:
authorfragosti <francesco.agosti93@gmail.com>2018-08-18 01:43:44 +0800
committerfragosti <francesco.agosti93@gmail.com>2018-08-18 01:43:44 +0800
commit48ec78d3aaa5dcef8544d17f26ef8ea8b31661e5 (patch)
tree3dd5fbeb42e256c553c7f02f81080d2f9d0a8cd1 /packages/connect/src
parent64a85dfb9cc60212dcf1c70ca7be4874936dd332 (diff)
downloaddexon-sol-tools-48ec78d3aaa5dcef8544d17f26ef8ea8b31661e5.tar
dexon-sol-tools-48ec78d3aaa5dcef8544d17f26ef8ea8b31661e5.tar.gz
dexon-sol-tools-48ec78d3aaa5dcef8544d17f26ef8ea8b31661e5.tar.bz2
dexon-sol-tools-48ec78d3aaa5dcef8544d17f26ef8ea8b31661e5.tar.lz
dexon-sol-tools-48ec78d3aaa5dcef8544d17f26ef8ea8b31661e5.tar.xz
dexon-sol-tools-48ec78d3aaa5dcef8544d17f26ef8ea8b31661e5.tar.zst
dexon-sol-tools-48ec78d3aaa5dcef8544d17f26ef8ea8b31661e5.zip
Add networkId request param option
Diffstat (limited to 'packages/connect/src')
-rw-r--r--packages/connect/src/http_client.ts50
-rw-r--r--packages/connect/src/index.ts8
-rw-r--r--packages/connect/src/orders_channel_factory.ts4
-rw-r--r--packages/connect/src/schemas/schemas.ts2
-rw-r--r--packages/connect/src/types.ts4
5 files changed, 48 insertions, 20 deletions
diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts
index 5aeba19dd..8f7825253 100644
--- a/packages/connect/src/http_client.ts
+++ b/packages/connect/src/http_client.ts
@@ -21,6 +21,7 @@ import {
OrdersRequestOpts,
OrdersResponse,
PagedRequestOpts,
+ RequestOpts,
} from './types';
import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers';
@@ -29,6 +30,9 @@ const DEFAULT_PAGED_REQUEST_OPTS: PagedRequestOpts = {
page: 1,
perPage: 100,
};
+const DEFAULT_REQUEST_OPTS: RequestOpts = {
+ networkId: 1,
+};
/**
* This class includes all the functionality related to interacting with a set of HTTP endpoints
@@ -62,13 +66,14 @@ export class HttpClient implements Client {
* @param requestOpts Options specifying assetData information to retrieve and page information, defaults to { page: 1, perPage: 100 }
* @return The resulting AssetPairsItems that match the request
*/
- public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise<AssetPairsResponse> {
+ public async getAssetPairsAsync(requestOpts?: RequestOpts & AssetPairsRequestOpts & PagedRequestOpts): Promise<AssetPairsResponse> {
if (!_.isUndefined(requestOpts)) {
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.assetPairsRequestOptsSchema);
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema);
+ assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema);
}
const httpRequestOpts = {
- params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS),
+ params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS),
};
const responseJson = await this._requestAsync('/asset_pairs', HttpRequestType.Get, httpRequestOpts);
const assetDataPairs = relayerResponseJsonParsers.parseAssetDataPairsJson(responseJson);
@@ -79,13 +84,14 @@ 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<OrdersResponse> {
+ public async getOrdersAsync(requestOpts?: RequestOpts & OrdersRequestOpts & PagedRequestOpts): Promise<OrdersResponse> {
if (!_.isUndefined(requestOpts)) {
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.ordersRequestOptsSchema);
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema);
+ assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema);
}
const httpRequestOpts = {
- params: _.defaults({}, requestOpts, DEFAULT_PAGED_REQUEST_OPTS),
+ params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS),
};
const responseJson = await this._requestAsync(`/orders`, HttpRequestType.Get, httpRequestOpts);
const orders = relayerResponseJsonParsers.parseOrdersJson(responseJson);
@@ -96,9 +102,15 @@ 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<APIOrder> {
+ public async getOrderAsync(orderHash: string, requestOpts?: RequestOpts): Promise<APIOrder> {
+ if (!_.isUndefined(requestOpts)) {
+ assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema);
+ }
assert.doesConformToSchema('orderHash', orderHash, schemas.orderHashSchema);
- const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get);
+ const httpRequestOpts = {
+ params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS),
+ };
+ const responseJson = await this._requestAsync(`/order/${orderHash}`, HttpRequestType.Get, httpRequestOpts);
const order = relayerResponseJsonParsers.parseAPIOrderJson(responseJson);
return order;
}
@@ -110,14 +122,15 @@ export class HttpClient implements Client {
*/
public async getOrderbookAsync(
request: OrderbookRequest,
- requestOpts?: PagedRequestOpts,
+ requestOpts?: RequestOpts & PagedRequestOpts,
): Promise<OrderbookResponse> {
assert.doesConformToSchema('request', request, clientSchemas.orderBookRequestSchema);
if (!_.isUndefined(requestOpts)) {
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema);
+ assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema);
}
const httpRequestOpts = {
- params: _.defaults({}, request, requestOpts, DEFAULT_PAGED_REQUEST_OPTS),
+ params: _.defaults({}, request, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS),
};
const responseJson = await this._requestAsync('/orderbook', HttpRequestType.Get, httpRequestOpts);
const orderbook = relayerResponseJsonParsers.parseOrderbookResponseJson(responseJson);
@@ -128,9 +141,13 @@ export class HttpClient implements Client {
* @param request A OrderConfigRequest instance describing the specific fees to retrieve
* @return The resulting OrderConfigResponse that matches the request
*/
- public async getOrderConfigAsync(request: OrderConfigRequest): Promise<OrderConfigResponse> {
+ public async getOrderConfigAsync(request: OrderConfigRequest, requestOpts?: RequestOpts): Promise<OrderConfigResponse> {
+ if (!_.isUndefined(requestOpts)) {
+ assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema);
+ }
assert.doesConformToSchema('request', request, clientSchemas.orderConfigRequestSchema);
const httpRequestOpts = {
+ params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS),
payload: request,
};
const responseJson = await this._requestAsync('/order_config', HttpRequestType.Post, httpRequestOpts);
@@ -140,11 +157,15 @@ export class HttpClient implements Client {
/**
* Retrieve the list of fee recipient addresses used by
*/
- public async getFeeRecipientsAsync(requestOpts?: PagedRequestOpts): Promise<FeeRecipientsResponse> {
+ public async getFeeRecipientsAsync(requestOpts?: RequestOpts & PagedRequestOpts): Promise<FeeRecipientsResponse> {
if (!_.isUndefined(requestOpts)) {
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema);
+ assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.requestOptsSchema);
}
- const feeRecipients = await this._requestAsync('/fee_recipients', HttpRequestType.Get);
+ const httpRequestOpts = {
+ params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS, DEFAULT_PAGED_REQUEST_OPTS),
+ };
+ const feeRecipients = await this._requestAsync('/fee_recipients', HttpRequestType.Get, httpRequestOpts);
assert.doesConformToSchema('feeRecipients', feeRecipients, schemas.relayerApiFeeRecipientsResponseSchema);
return feeRecipients;
}
@@ -152,12 +173,13 @@ export class HttpClient implements Client {
* Submit a signed order to the API
* @param signedOrder A SignedOrder instance to submit
*/
- public async submitOrderAsync(signedOrder: SignedOrder): Promise<void> {
+ public async submitOrderAsync(signedOrder: SignedOrder, requestOpts?: RequestOpts): Promise<void> {
assert.doesConformToSchema('signedOrder', signedOrder, schemas.signedOrderSchema);
- const requestOpts = {
+ const httpRequestOpts = {
+ params: _.defaults({}, requestOpts, DEFAULT_REQUEST_OPTS),
payload: signedOrder,
};
- await this._requestAsync('/order', HttpRequestType.Post, requestOpts);
+ await this._requestAsync('/order', HttpRequestType.Post, httpRequestOpts);
}
private async _requestAsync(
path: string,
diff --git a/packages/connect/src/index.ts b/packages/connect/src/index.ts
index e0c4293d9..33e1222b0 100644
--- a/packages/connect/src/index.ts
+++ b/packages/connect/src/index.ts
@@ -1,12 +1,12 @@
export { HttpClient } from './http_client';
-export { orderbookChannelFactory } from './orderbook_channel_factory';
+export { ordersChannelFactory } from './orders_channel_factory';
export {
Client,
OrderConfigRequest,
OrderConfigResponse,
- OrderbookChannel,
- OrderbookChannelHandler,
- OrderbookChannelSubscriptionOpts,
+ OrdersChannel,
+ OrdersChannelHandler,
+ OrdersChannelSubscriptionOpts,
OrderbookRequest,
OrderbookResponse,
OrdersRequestOpts,
diff --git a/packages/connect/src/orders_channel_factory.ts b/packages/connect/src/orders_channel_factory.ts
index 4e9b74b2c..fae5cab8c 100644
--- a/packages/connect/src/orders_channel_factory.ts
+++ b/packages/connect/src/orders_channel_factory.ts
@@ -10,14 +10,14 @@ export const ordersChannelFactory = {
* @param url The relayer API base WS url you would like to interact with
* @param handler An OrderbookChannelHandler instance that responds to various
* channel updates
- * @return An OrderbookChannel Promise
+ * @return An OrdersChannel Promise
*/
async createWebSocketOrdersChannelAsync(
url: string,
handler: OrdersChannelHandler,
): Promise<OrdersChannel> {
assert.isUri('url', url);
- assert.isOrderbookChannelHandler('handler', handler);
+ assert.isOrdersChannelHandler('handler', handler);
return new Promise<OrdersChannel>((resolve, reject) => {
const client = new WebSocket.w3cwebsocket(url);
client.onopen = () => {
diff --git a/packages/connect/src/schemas/schemas.ts b/packages/connect/src/schemas/schemas.ts
index a7e968a01..8d101ed6f 100644
--- a/packages/connect/src/schemas/schemas.ts
+++ b/packages/connect/src/schemas/schemas.ts
@@ -3,11 +3,13 @@ import { orderConfigRequestSchema } from './order_config_request_schema';
import { orderBookRequestSchema } from './orderbook_request_schema';
import { ordersRequestOptsSchema } from './orders_request_opts_schema';
import { pagedRequestOptsSchema } from './paged_request_opts_schema';
+import { requestOptsSchema } from './request_opts_schema';
export const schemas = {
orderConfigRequestSchema,
orderBookRequestSchema,
ordersRequestOptsSchema,
pagedRequestOptsSchema,
+ requestOptsSchema,
assetPairsRequestOptsSchema,
};
diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts
index e85a0542c..f90f0808d 100644
--- a/packages/connect/src/types.ts
+++ b/packages/connect/src/types.ts
@@ -147,6 +147,10 @@ export interface OrderConfigResponse {
export type FeeRecipientsResponse = PaginatedCollection<string>;
+export interface RequestOpts {
+ networkId?: number;
+}
+
export interface PagedRequestOpts {
page?: number;
perPage?: number;