diff --git a/packages/core/src/actions/getTaskHistory.ts b/packages/core/src/actions/getTaskHistory.ts index 92be6737..0d8659f2 100644 --- a/packages/core/src/actions/getTaskHistory.ts +++ b/packages/core/src/actions/getTaskHistory.ts @@ -2,24 +2,36 @@ import { getWalletId } from './getWalletId.js' import { getRelayerWithAuth } from '../utils/http.js' -import { TASK_HISTORY_ROUTE } from '../constants.js' +import { TASK_HISTORY_LEN_PARAM, TASK_HISTORY_ROUTE } from '../constants.js' import type { RenegadeConfig } from '../createConfig.js' import { BaseError, type BaseErrorType } from '../errors/base.js' import type { Task as TaskHistoryItem } from '../types/task.js' +export type GetTaskHistoryParameters = { + limit?: number +} + export type GetTaskHistoryReturnType = Map export type GetTaskHistoryErrorType = BaseErrorType export async function getTaskHistory( config: RenegadeConfig, + parameters: GetTaskHistoryParameters = {}, ): Promise { const { getBaseUrl } = config + const { limit } = parameters const walletId = getWalletId(config) - const res = await getRelayerWithAuth( - config, - getBaseUrl(TASK_HISTORY_ROUTE(walletId)), - ) + let url = getBaseUrl(TASK_HISTORY_ROUTE(walletId)) + + if (limit !== undefined) { + const searchParams = new URLSearchParams({ + [TASK_HISTORY_LEN_PARAM]: limit.toString(), + }) + url += `?${searchParams.toString()}` + } + const res = await getRelayerWithAuth(config, url) + if (!res.tasks) { throw new BaseError('No tasks found') } diff --git a/packages/core/src/constants.ts b/packages/core/src/constants.ts index 57453691..7fea55f1 100644 --- a/packages/core/src/constants.ts +++ b/packages/core/src/constants.ts @@ -115,6 +115,9 @@ export const GET_TASK_QUEUE_ROUTE = (wallet_id: string) => /// The route to fetch task history for a wallet export const TASK_HISTORY_ROUTE = (wallet_id: string) => `/wallet/${wallet_id}/task-history` +/// The name of the query parameter specifying the length of the task history +/// to return +export const TASK_HISTORY_LEN_PARAM = 'task_history_len' //////////////////////////////////////////////////////////////////////////////// // Health check diff --git a/packages/core/src/exports/actions.ts b/packages/core/src/exports/actions.ts index c608f0f8..e0dbca2b 100644 --- a/packages/core/src/exports/actions.ts +++ b/packages/core/src/exports/actions.ts @@ -150,6 +150,7 @@ export { export { type GetTaskHistoryErrorType, type GetTaskHistoryReturnType, + type GetTaskHistoryParameters, getTaskHistory, } from '../actions/getTaskHistory.js' diff --git a/packages/core/src/exports/index.ts b/packages/core/src/exports/index.ts index f8b9c5c8..939efeb6 100644 --- a/packages/core/src/exports/index.ts +++ b/packages/core/src/exports/index.ts @@ -143,6 +143,7 @@ export { export { type GetTaskHistoryErrorType, type GetTaskHistoryReturnType, + type GetTaskHistoryParameters, getTaskHistory, } from '../actions/getTaskHistory.js' diff --git a/packages/core/src/query/getOrderHistory.ts b/packages/core/src/query/getOrderHistory.ts index ba9797d1..346d8456 100644 --- a/packages/core/src/query/getOrderHistory.ts +++ b/packages/core/src/query/getOrderHistory.ts @@ -1,6 +1,7 @@ import type { QueryOptions } from '@tanstack/query-core' import { type GetOrderHistoryErrorType, + type GetOrderHistoryParameters, type GetOrderHistoryReturnType, getOrderHistory, } from '../actions/getOrderHistory.js' @@ -8,7 +9,9 @@ import type { Config } from '../createConfig.js' import type { Evaluate } from '../types/utils.js' import { type ScopeKeyParameter, filterQueryOptions } from './utils.js' -export type GetOrderHistoryOptions = Evaluate +export type GetOrderHistoryOptions = Evaluate< + GetOrderHistoryParameters & ScopeKeyParameter +> export function getOrderHistoryQueryOptions( config: Config, @@ -16,8 +19,8 @@ export function getOrderHistoryQueryOptions( ) { return { async queryFn({ queryKey }) { - const { scopeKey: _ } = queryKey[1] - const history = await getOrderHistory(config) + const { scopeKey: _, ...parameters } = queryKey[1] + const history = await getOrderHistory(config, parameters) return history ?? null }, queryKey: getOrderHistoryQueryKey({ diff --git a/packages/core/src/query/getTaskHistory.ts b/packages/core/src/query/getTaskHistory.ts index 4ce0ff5f..749d6b61 100644 --- a/packages/core/src/query/getTaskHistory.ts +++ b/packages/core/src/query/getTaskHistory.ts @@ -1,6 +1,7 @@ import type { QueryOptions } from '@tanstack/query-core' import { type GetTaskHistoryErrorType, + type GetTaskHistoryParameters, type GetTaskHistoryReturnType, getTaskHistory, } from '../actions/getTaskHistory.js' @@ -8,7 +9,9 @@ import type { Config } from '../createConfig.js' import type { Evaluate } from '../types/utils.js' import { type ScopeKeyParameter, filterQueryOptions } from './utils.js' -export type GetTaskHistoryOptions = Evaluate +export type GetTaskHistoryOptions = Evaluate< + GetTaskHistoryParameters & ScopeKeyParameter +> export function getTaskHistoryQueryOptions( config: Config, @@ -16,8 +19,8 @@ export function getTaskHistoryQueryOptions( ) { return { async queryFn({ queryKey }) { - const { scopeKey: _ } = queryKey[1] - const history = await getTaskHistory(config) + const { scopeKey: _, ...parameters } = queryKey[1] + const history = await getTaskHistory(config, parameters) return history ?? null }, queryKey: getTaskHistoryQueryKey({ diff --git a/packages/core/src/utils.d.ts b/packages/core/src/utils.d.ts index 5a244851..7c92ea79 100644 --- a/packages/core/src/utils.d.ts +++ b/packages/core/src/utils.d.ts @@ -1,24 +1,6 @@ /* tslint:disable */ /* eslint-disable */ /** -* @param {Function} sign_message -* @returns {Promise} -*/ -export function generate_wallet_secrets(sign_message: Function): Promise; -/** -* @param {string} path -* @param {any} headers -* @param {string} body -* @param {string} key -* @returns {string} -*/ -export function create_request_signature(path: string, headers: any, body: string, key: string): string; -/** -* @param {string} b64_key -* @returns {string} -*/ -export function b64_to_hex_hmac_key(b64_key: string): string; -/** * @param {string} seed * @returns {any} */ @@ -158,6 +140,24 @@ export function assemble_external_match(do_gas_estimation: boolean, updated_orde */ export function create_external_wallet(wallet_id: string, blinder_seed: string, share_seed: string, pk_root: string, sk_match: string, symmetric_key: string): Promise; /** +* @param {Function} sign_message +* @returns {Promise} +*/ +export function generate_wallet_secrets(sign_message: Function): Promise; +/** +* @param {string} path +* @param {any} headers +* @param {string} body +* @param {string} key +* @returns {string} +*/ +export function create_request_signature(path: string, headers: any, body: string, key: string): string; +/** +* @param {string} b64_key +* @returns {string} +*/ +export function b64_to_hex_hmac_key(b64_key: string): string; +/** * @param {string} wallet_id * @param {string} blinder_seed * @param {string} share_seed