Change names of basic types in Client interface
This commit is contained in:
parent
7eff195d61
commit
c1cc92a46f
@ -7,6 +7,7 @@ import * as queryString from 'query-string';
|
|||||||
|
|
||||||
import { schemas as clientSchemas } from './schemas/schemas';
|
import { schemas as clientSchemas } from './schemas/schemas';
|
||||||
import {
|
import {
|
||||||
|
AssetPairsRequestOpts,
|
||||||
Client,
|
Client,
|
||||||
FeesRequest,
|
FeesRequest,
|
||||||
FeesResponse,
|
FeesResponse,
|
||||||
@ -17,7 +18,6 @@ import {
|
|||||||
OrdersRequestOpts,
|
OrdersRequestOpts,
|
||||||
PagedRequestOpts,
|
PagedRequestOpts,
|
||||||
TokenPairsItem,
|
TokenPairsItem,
|
||||||
TokenPairsRequestOpts,
|
|
||||||
} from './types';
|
} from './types';
|
||||||
import { relayerResponseJsonParsers } from './utils/relayer_response_json_parsers';
|
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 }
|
* @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
|
* @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)) {
|
if (!_.isUndefined(requestOpts)) {
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.tokenPairsRequestOptsSchema);
|
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.AssetPairsRequestOptsSchema);
|
||||||
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema);
|
assert.doesConformToSchema('requestOpts', requestOpts, clientSchemas.pagedRequestOptsSchema);
|
||||||
}
|
}
|
||||||
const httpRequestOpts = {
|
const httpRequestOpts = {
|
||||||
@ -135,7 +135,7 @@ export class HttpClient implements Client {
|
|||||||
* @param request A FeesRequest instance describing the specific fees to retrieve
|
* @param request A FeesRequest instance describing the specific fees to retrieve
|
||||||
* @return The resulting FeesResponse that matches the request
|
* @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);
|
assert.doesConformToSchema('request', request, clientSchemas.feesRequestSchema);
|
||||||
const httpRequestOpts = {
|
const httpRequestOpts = {
|
||||||
payload: request,
|
payload: request,
|
||||||
|
@ -12,7 +12,7 @@ export {
|
|||||||
OrdersRequestOpts,
|
OrdersRequestOpts,
|
||||||
PagedRequestOpts,
|
PagedRequestOpts,
|
||||||
TokenPairsItem,
|
TokenPairsItem,
|
||||||
TokenPairsRequestOpts,
|
AssetPairsRequestOpts,
|
||||||
TokenTradeInfo,
|
TokenTradeInfo,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
|
@ -2,12 +2,12 @@ import { feesRequestSchema } from './fees_request_schema';
|
|||||||
import { orderBookRequestSchema } from './orderbook_request_schema';
|
import { orderBookRequestSchema } from './orderbook_request_schema';
|
||||||
import { ordersRequestOptsSchema } from './orders_request_opts_schema';
|
import { ordersRequestOptsSchema } from './orders_request_opts_schema';
|
||||||
import { pagedRequestOptsSchema } from './paged_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 = {
|
export const schemas = {
|
||||||
feesRequestSchema,
|
feesRequestSchema,
|
||||||
orderBookRequestSchema,
|
orderBookRequestSchema,
|
||||||
ordersRequestOptsSchema,
|
ordersRequestOptsSchema,
|
||||||
pagedRequestOptsSchema,
|
pagedRequestOptsSchema,
|
||||||
tokenPairsRequestOptsSchema,
|
AssetPairsRequestOptsSchema,
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export const tokenPairsRequestOptsSchema = {
|
export const AssetPairsRequestOptsSchema = {
|
||||||
id: '/TokenPairsRequestOpts',
|
id: '/AssetPairsRequestOpts',
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
tokenA: { $ref: '/Address' },
|
tokenA: { $ref: '/Address' },
|
||||||
|
@ -2,11 +2,11 @@ import { SignedOrder } from '@0xproject/types';
|
|||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
|
|
||||||
export interface Client {
|
export interface Client {
|
||||||
getTokenPairsAsync: (requestOpts?: TokenPairsRequestOpts & PagedRequestOpts) => Promise<TokenPairsItem[]>;
|
getAssetPairsAsync: (requestOpts?: AssetPairsRequestOpts & PagedRequestOpts) => Promise<TokenPairsItem[]>;
|
||||||
getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise<SignedOrder[]>;
|
getOrdersAsync: (requestOpts?: OrdersRequestOpts & PagedRequestOpts) => Promise<SignedOrder[]>;
|
||||||
getOrderAsync: (orderHash: string) => Promise<SignedOrder>;
|
getOrderAsync: (orderHash: string) => Promise<SignedOrder>;
|
||||||
getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise<OrderbookResponse>;
|
getOrderbookAsync: (request: OrderbookRequest, requestOpts?: PagedRequestOpts) => Promise<OrderbookResponse>;
|
||||||
getFeesAsync: (request: FeesRequest) => Promise<FeesResponse>;
|
getOrderConfigAsync: (request: FeesRequest) => Promise<FeesResponse>;
|
||||||
submitOrderAsync: (signedOrder: SignedOrder) => Promise<void>;
|
submitOrderAsync: (signedOrder: SignedOrder) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ export enum WebsocketClientEventType {
|
|||||||
ConnectFailed = 'connectFailed',
|
ConnectFailed = 'connectFailed',
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TokenPairsRequestOpts {
|
export interface AssetPairsRequestOpts {
|
||||||
tokenA?: string;
|
tokenA?: string;
|
||||||
tokenB?: string;
|
tokenB?: string;
|
||||||
}
|
}
|
||||||
@ -121,6 +121,13 @@ export interface OrderbookResponse {
|
|||||||
asks: SignedOrder[];
|
asks: SignedOrder[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PaginatedCollectionResponse<T> {
|
||||||
|
total: number;
|
||||||
|
page: number;
|
||||||
|
perPage: number;
|
||||||
|
records: T[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface FeesRequest {
|
export interface FeesRequest {
|
||||||
exchangeContractAddress: string;
|
exchangeContractAddress: string;
|
||||||
maker: string;
|
maker: string;
|
||||||
|
@ -38,29 +38,29 @@ describe('HttpClient', () => {
|
|||||||
expect(sanitizedUrl).to.be.deep.equal(urlWithoutTrailingSlash);
|
expect(sanitizedUrl).to.be.deep.equal(urlWithoutTrailingSlash);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('#getTokenPairsAsync', () => {
|
describe('#getAssetPairsAsync', () => {
|
||||||
const url = `${relayUrl}/token_pairs`;
|
const url = `${relayUrl}/token_pairs`;
|
||||||
it('gets token pairs with default options when none are provided', async () => {
|
it('gets token pairs with default options when none are provided', async () => {
|
||||||
const urlWithQuery = `${url}?page=1&per_page=100`;
|
const urlWithQuery = `${url}?page=1&per_page=100`;
|
||||||
fetchMock.get(urlWithQuery, tokenPairsResponseJSON);
|
fetchMock.get(urlWithQuery, tokenPairsResponseJSON);
|
||||||
const tokenPairs = await relayerClient.getTokenPairsAsync();
|
const tokenPairs = await relayerClient.getAssetPairsAsync();
|
||||||
expect(tokenPairs).to.be.deep.equal(tokenPairsResponse);
|
expect(tokenPairs).to.be.deep.equal(tokenPairsResponse);
|
||||||
});
|
});
|
||||||
it('gets token pairs with specified request options', async () => {
|
it('gets token pairs with specified request options', async () => {
|
||||||
const tokenAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d';
|
const tokenAddress = '0x323b5d4c32345ced77393b3530b1eed0f346429d';
|
||||||
const tokenPairsRequestOpts = {
|
const AssetPairsRequestOpts = {
|
||||||
tokenA: tokenAddress,
|
tokenA: tokenAddress,
|
||||||
page: 3,
|
page: 3,
|
||||||
perPage: 50,
|
perPage: 50,
|
||||||
};
|
};
|
||||||
const urlWithQuery = `${url}?page=3&per_page=50&tokenA=${tokenAddress}`;
|
const urlWithQuery = `${url}?page=3&per_page=50&tokenA=${tokenAddress}`;
|
||||||
fetchMock.get(urlWithQuery, tokenPairsResponseJSON);
|
fetchMock.get(urlWithQuery, tokenPairsResponseJSON);
|
||||||
const tokenPairs = await relayerClient.getTokenPairsAsync(tokenPairsRequestOpts);
|
const tokenPairs = await relayerClient.getAssetPairsAsync(AssetPairsRequestOpts);
|
||||||
expect(tokenPairs).to.be.deep.equal(tokenPairsResponse);
|
expect(tokenPairs).to.be.deep.equal(tokenPairsResponse);
|
||||||
});
|
});
|
||||||
it('throws an error for invalid JSON response', async () => {
|
it('throws an error for invalid JSON response', async () => {
|
||||||
fetchMock.get(url, { test: 'dummy' });
|
fetchMock.get(url, { test: 'dummy' });
|
||||||
expect(relayerClient.getTokenPairsAsync()).to.be.rejected();
|
expect(relayerClient.getAssetPairsAsync()).to.be.rejected();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('#getOrdersAsync', () => {
|
describe('#getOrdersAsync', () => {
|
||||||
@ -132,7 +132,7 @@ describe('HttpClient', () => {
|
|||||||
expect(relayerClient.getOrderbookAsync(request)).to.be.rejected();
|
expect(relayerClient.getOrderbookAsync(request)).to.be.rejected();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('#getFeesAsync', () => {
|
describe('#getOrderConfigAsync', () => {
|
||||||
const request = {
|
const request = {
|
||||||
exchangeContractAddress: '0x12459c951127e0c374ff9105dda097662a027093',
|
exchangeContractAddress: '0x12459c951127e0c374ff9105dda097662a027093',
|
||||||
maker: '0x9e56625509c2f60af937f23b7b532600390e8c8b',
|
maker: '0x9e56625509c2f60af937f23b7b532600390e8c8b',
|
||||||
@ -147,7 +147,7 @@ describe('HttpClient', () => {
|
|||||||
const url = `${relayUrl}/fees`;
|
const url = `${relayUrl}/fees`;
|
||||||
it('gets fees', async () => {
|
it('gets fees', async () => {
|
||||||
fetchMock.post(url, feesResponseJSON);
|
fetchMock.post(url, feesResponseJSON);
|
||||||
const fees = await relayerClient.getFeesAsync(request);
|
const fees = await relayerClient.getOrderConfigAsync(request);
|
||||||
expect(fees).to.be.deep.equal(feesResponse);
|
expect(fees).to.be.deep.equal(feesResponse);
|
||||||
});
|
});
|
||||||
it('does not mutate input', async () => {
|
it('does not mutate input', async () => {
|
||||||
@ -156,7 +156,7 @@ describe('HttpClient', () => {
|
|||||||
const takerTokenAmountBefore = new BigNumber(request.takerTokenAmount);
|
const takerTokenAmountBefore = new BigNumber(request.takerTokenAmount);
|
||||||
const saltBefore = new BigNumber(request.salt);
|
const saltBefore = new BigNumber(request.salt);
|
||||||
const expirationUnixTimestampSecBefore = new BigNumber(request.expirationUnixTimestampSec);
|
const expirationUnixTimestampSecBefore = new BigNumber(request.expirationUnixTimestampSec);
|
||||||
await relayerClient.getFeesAsync(request);
|
await relayerClient.getOrderConfigAsync(request);
|
||||||
expect(makerTokenAmountBefore).to.be.deep.equal(request.makerTokenAmount);
|
expect(makerTokenAmountBefore).to.be.deep.equal(request.makerTokenAmount);
|
||||||
expect(takerTokenAmountBefore).to.be.deep.equal(request.takerTokenAmount);
|
expect(takerTokenAmountBefore).to.be.deep.equal(request.takerTokenAmount);
|
||||||
expect(saltBefore).to.be.deep.equal(request.salt);
|
expect(saltBefore).to.be.deep.equal(request.salt);
|
||||||
@ -164,7 +164,7 @@ describe('HttpClient', () => {
|
|||||||
});
|
});
|
||||||
it('throws an error for invalid JSON response', async () => {
|
it('throws an error for invalid JSON response', async () => {
|
||||||
fetchMock.post(url, { test: 'dummy' });
|
fetchMock.post(url, { test: 'dummy' });
|
||||||
expect(relayerClient.getFeesAsync(request)).to.be.rejected();
|
expect(relayerClient.getOrderConfigAsync(request)).to.be.rejected();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user