Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/methods/delta/getDeltaOrders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ import type {
ConstructFetchInput,
RequestParameters,
} from '../../types';
import type { DeltaAuction } from './helpers/types';
import type { DeltaAuction, DeltaAuctionStatus } from './helpers/types';

export type DeltaOrderFromAPI = Omit<DeltaAuction, 'signature'>;

type DeltaOrderFilterByStatus =
| DeltaAuctionStatus
| 'INSUFFICIENT_BALANCE'
| 'INSUFFICIENT_ALLOWANCE'
| 'INVALIDATED'
| 'ACTIVE'
| 'INACTIVE';

type GetDeltaOrderById = (
orderId: string,
requestParams?: RequestParameters
Expand All @@ -27,11 +35,24 @@ type OrdersFilter = {
/** @description Pagination option, limit. Default 100 */
limit?: number;
/** @description Filter by chainId, without this filter, orders from all chains are returned */
chainId?: number; // @TODO currently not working
/** @description Filter by type. MARKET, LIMIT, or ALL. Default is ALL */
type?: 'MARKET' | 'LIMIT' | 'ALL';
chainId?: number[];
/**
* @description
* Filter by any known DeltaAuctionStatus and some custom statuses:
* - **INSUFFICIENT_BALANCE** — returned as SUSPENDED from API
* - **INSUFFICIENT_ALLOWANCE** — returned as SUSPENDED from API
* - **INVALIDATED** — returned as FAILED from API
* - **ACTIVE** — All orders with NOT_STARTED, RUNNING, EXECUTING or SUSPENDED statuses.
* - **INACTIVE** — All orders with EXECUTED, FAILED, EXPIRED, CANCELLED or INVALIDATED statuses.
*/
status?: DeltaOrderFilterByStatus[];
/** @description Filter by type. MARKET, LIMIT. Orders with both types are returned if not specified */
type?: 'MARKET' | 'LIMIT';
};
type OrderFiltersQuery = Omit<OrdersFilter, 'chainId' | 'status'> & {
chainId?: string;
status?: string;
};
type OrderFiltersQuery = OrdersFilter;

type GetDeltaOrders = (
options: OrdersFilter,
Expand Down Expand Up @@ -93,12 +114,18 @@ export const constructGetDeltaOrders = ({
};

const getDeltaOrders: GetDeltaOrders = async (options, requestParams) => {
const chainIdString = options.chainId
? options.chainId.join(',')
: undefined;
const statusString = options.status ? options.status.join(',') : undefined;
Comment on lines +117 to +120
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably do options.chainId?.join()


const search = constructSearchString<OrderFiltersQuery>({
userAddress: options.userAddress,
page: options.page,
limit: options.limit,
chainId: options.chainId,
type: options.type,
chainId: chainIdString,
status: statusString,
});

const fetchURL = `${baseUrl}${search}` as const;
Expand Down
Loading