diff options
Diffstat (limited to 'packages/connect')
-rw-r--r-- | packages/connect/src/http_client.ts | 8 | ||||
-rw-r--r-- | packages/connect/src/index.ts | 2 | ||||
-rw-r--r-- | packages/connect/src/schemas/schemas.ts | 4 | ||||
-rw-r--r-- | packages/connect/src/schemas/token_pairs_request_opts_schema.ts | 4 | ||||
-rw-r--r-- | packages/connect/src/types.ts | 13 | ||||
-rw-r--r-- | packages/connect/test/http_client_test.ts | 18 |
6 files changed, 28 insertions, 21 deletions
diff --git a/packages/connect/src/http_client.ts b/packages/connect/src/http_client.ts index 03cc590e4..1b51ee429 100644 --- a/packages/connect/src/http_client.ts +++ b/packages/connect/src/http_client.ts @@ -7,6 +7,7 @@ import * as queryString from 'query-string'; import { schemas as clientSchemas } from './schemas/schemas'; import { + AssetPairsRequestOpts, Client, FeesRequest, FeesResponse, @@ -17,7 +18,6 @@ import { OrdersRequestOpts, PagedRequestOpts, TokenPairsItem, - TokenPairsRequestOpts, } from './types'; import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers'; @@ -69,9 +69,9 @@ export class HttpClient implements Client { * @param requestOpts Options specifying token information to retrieve and page information, defaults to { page: 1, perPage: 100 } * @return The resulting TokenPairsItems that match the request */ - public async getTokenPairsAsync(requestOpts?: TokenPairsRequestOpts & PagedRequestOpts): Promise<TokenPairsItem[]> { + public async getAssetPairsAsync(requestOpts?: AssetPairsRequestOpts & PagedRequestOpts): Promise<TokenPairsItem[]> { if (!_.isUndefined(requestOpts)) { - assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.tokenPairsRequestOptsSchema); + assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.AssetPairsRequestOptsSchema); assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema); } const httpRequestOpts = { @@ -135,7 +135,7 @@ export class HttpClient implements Client { * @param request A FeesRequest instance describing the specific fees to retrieve * @return The resulting FeesResponse that matches the request */ - public async getFeesAsync(request: FeesRequest): Promise<FeesResponse> { + public async getOrderConfigAsync(request: FeesRequest): Promise<FeesResponse> { assert.doesConformToSchema('request', request, clientSchemas.feesRequestSchema); const httpRequestOpts = { payload: request, diff --git a/packages/connect/src/index.ts b/packages/connect/src/index.ts index 7f5eb8ed3..a4fc39425 100644 --- a/packages/connect/src/index.ts +++ b/packages/connect/src/index.ts @@ -12,7 +12,7 @@ export { OrdersRequestOpts, PagedRequestOpts, TokenPairsItem, - TokenPairsRequestOpts, + AssetPairsRequestOpts, TokenTradeInfo, } from './types'; diff --git a/packages/connect/src/schemas/schemas.ts b/packages/connect/src/schemas/schemas.ts index 0b8b798a9..e6ca010ae 100644 --- a/packages/connect/src/schemas/schemas.ts +++ b/packages/connect/src/schemas/schemas.ts @@ -2,12 +2,12 @@ import { feesRequestSchema } from './fees_request_schema'; import { orderBookRequestSchema } from './orderbook_request_schema'; import { ordersRequestOptsSchema } from './orders_request_opts_schema'; import { pagedRequestOptsSchema } from './paged_request_opts_schema'; -import { tokenPairsRequestOptsSchema } from './token_pairs_request_opts_schema'; +import { AssetPairsRequestOptsSchema } from './token_pairs_request_opts_schema'; export const schemas = { feesRequestSchema, orderBookRequestSchema, ordersRequestOptsSchema, pagedRequestOptsSchema, - tokenPairsRequestOptsSchema, + AssetPairsRequestOptsSchema, }; diff --git a/packages/connect/src/schemas/token_pairs_request_opts_schema.ts b/packages/connect/src/schemas/token_pairs_request_opts_schema.ts index 9b73a917b..dffd063d0 100644 --- a/packages/connect/src/schemas/token_pairs_request_opts_schema.ts +++ b/packages/connect/src/schemas/token_pairs_request_opts_schema.ts @@ -1,5 +1,5 @@ -export const tokenPairsRequestOptsSchema = { - id: '/TokenPairsRequestOpts', +export const AssetPairsRequestOptsSchema = { + id: '/AssetPairsRequestOpts', type: 'object', properties: { tokenA: { $ref: '/Address' }, diff --git a/packages/connect/src/types.ts b/packages/connect/src/types.ts index fc7a4b24d..ca56d251b 100644 --- a/packages/connect/src/types.ts +++ b/packages/connect/src/types.ts @@ -2,11 +2,11 @@ import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; export interface Client { - getTokenPairsAsync: (requestOpts?: TokenPairsRequestOpts & PagedRequestOpts) => Promise<TokenPairsItem[]>; + getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise<TokenPairsItem[]>; getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise<SignedOrder[]>; getOrderAsync: (orderHash: string) => Promise<SignedOrder>; getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise<OrderbookResponse>; - getFeesAsync: (request: FeesRequest) => Promise<FeesResponse>; + getOrderConfigAsync: (request: FeesRequest) => Promise<FeesResponse>; submitOrderAsync: (signedOrder: SignedOrder) => Promise<void>; } @@ -83,7 +83,7 @@ export enum WebsocketClientEventType { ConnectFailed = 'connectFailed', } -export interface TokenPairsRequestOpts { +export interface AssetPairsRequestOpts { tokenA?: string; tokenB?: string; } @@ -121,6 +121,13 @@ export interface OrderbookResponse { asks: SignedOrder[]; } +export interface PaginatedCollectionResponse<T> { + total: number; + page: number; + perPage: number; + records: T[]; +} + export interface FeesRequest { exchangeContractAddress: string; maker: string; diff --git a/packages/connect/test/http_client_test.ts b/packages/connect/test/http_client_test.ts index 311dc96e6..38327b090 100644 --- a/packages/connect/test/http_client_test.ts +++ b/packages/connect/test/http_client_test.ts @@ -38,29 +38,29 @@ describe('HttpClient', () => { expect(sanitizedUrl).to.be.deep.equal(urlWithoutTrailingSlash); }); }); - describe('#getTokenPairsAsync', () => { + describe('#getAssetPairsAsync', () => { const url = `${relayUrl}/token_pairs`; it('gets token pairs with default options when none are provided', async () => { const urlWithQuery = `${url}?page=1&per_page=100`; fetchMock.get(urlWithQuery, tokenPairsResponseJSON); - const tokenPairs = await relayerClient.getTokenPairsAsync(); + const tokenPairs = await relayerClient.getAssetPairsAsync(); expect(tokenPairs).to.be.deep.equal(tokenPairsResponse); }); it('gets token pairs with specified request options', async () => { const tokenAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d'; - const tokenPairsRequestOpts = { + const AssetPairsRequestOpts = { tokenA: tokenAddress, page: 3, perPage: 50, }; const urlWithQuery = `${url}?page=3&per_page=50&tokenA=${tokenAddress}`; fetchMock.get(urlWithQuery, tokenPairsResponseJSON); - const tokenPairs = await relayerClient.getTokenPairsAsync(tokenPairsRequestOpts); + const tokenPairs = await relayerClient.getAssetPairsAsync(AssetPairsRequestOpts); expect(tokenPairs).to.be.deep.equal(tokenPairsResponse); }); it('throws an error for invalid JSON response', async () => { fetchMock.get(url, { test: 'dummy' }); - expect(relayerClient.getTokenPairsAsync()).to.be.rejected(); + expect(relayerClient.getAssetPairsAsync()).to.be.rejected(); }); }); describe('#getOrdersAsync', () => { @@ -132,7 +132,7 @@ describe('HttpClient', () => { expect(relayerClient.getOrderbookAsync(request)).to.be.rejected(); }); }); - describe('#getFeesAsync', () => { + describe('#getOrderConfigAsync', () => { const request = { exchangeContractAddress: '0x12459c951127e0c374ff9105dda097662a027093', maker: '0x9e56625509c2f60af937f23b7b532600390e8c8b', @@ -147,7 +147,7 @@ describe('HttpClient', () => { const url = `${relayUrl}/fees`; it('gets fees', async () => { fetchMock.post(url, feesResponseJSON); - const fees = await relayerClient.getFeesAsync(request); + const fees = await relayerClient.getOrderConfigAsync(request); expect(fees).to.be.deep.equal(feesResponse); }); it('does not mutate input', async () => { @@ -156,7 +156,7 @@ describe('HttpClient', () => { const takerTokenAmountBefore = new BigNumber(request.takerTokenAmount); const saltBefore = new BigNumber(request.salt); const expirationUnixTimestampSecBefore = new BigNumber(request.expirationUnixTimestampSec); - await relayerClient.getFeesAsync(request); + await relayerClient.getOrderConfigAsync(request); expect(makerTokenAmountBefore).to.be.deep.equal(request.makerTokenAmount); expect(takerTokenAmountBefore).to.be.deep.equal(request.takerTokenAmount); expect(saltBefore).to.be.deep.equal(request.salt); @@ -164,7 +164,7 @@ describe('HttpClient', () => { }); it('throws an error for invalid JSON response', async () => { fetchMock.post(url, { test: 'dummy' }); - expect(relayerClient.getFeesAsync(request)).to.be.rejected(); + expect(relayerClient.getOrderConfigAsync(request)).to.be.rejected(); }); }); }); |