Skip to content

Commit

Permalink
core: actions, query: expose limit param for getOrderHistory & getTas…
Browse files Browse the repository at this point in the history
…kHistory
  • Loading branch information
akirillo committed Jan 6, 2025
1 parent dea5932 commit 236530c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 29 deletions.
22 changes: 17 additions & 5 deletions packages/core/src/actions/getTaskHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, TaskHistoryItem>

export type GetTaskHistoryErrorType = BaseErrorType

export async function getTaskHistory(
config: RenegadeConfig,
parameters: GetTaskHistoryParameters = {},
): Promise<GetTaskHistoryReturnType> {
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')
}
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/exports/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export {
export {
type GetTaskHistoryErrorType,
type GetTaskHistoryReturnType,
type GetTaskHistoryParameters,
getTaskHistory,
} from '../actions/getTaskHistory.js'

Expand Down
1 change: 1 addition & 0 deletions packages/core/src/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export {
export {
type GetTaskHistoryErrorType,
type GetTaskHistoryReturnType,
type GetTaskHistoryParameters,
getTaskHistory,
} from '../actions/getTaskHistory.js'

Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/query/getOrderHistory.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import type { QueryOptions } from '@tanstack/query-core'
import {
type GetOrderHistoryErrorType,
type GetOrderHistoryParameters,
type GetOrderHistoryReturnType,
getOrderHistory,
} from '../actions/getOrderHistory.js'
import type { Config } from '../createConfig.js'
import type { Evaluate } from '../types/utils.js'
import { type ScopeKeyParameter, filterQueryOptions } from './utils.js'

export type GetOrderHistoryOptions = Evaluate<ScopeKeyParameter>
export type GetOrderHistoryOptions = Evaluate<
GetOrderHistoryParameters & ScopeKeyParameter
>

export function getOrderHistoryQueryOptions(
config: Config,
options: GetOrderHistoryOptions = {},
) {
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({
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/query/getTaskHistory.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import type { QueryOptions } from '@tanstack/query-core'
import {
type GetTaskHistoryErrorType,
type GetTaskHistoryParameters,
type GetTaskHistoryReturnType,
getTaskHistory,
} from '../actions/getTaskHistory.js'
import type { Config } from '../createConfig.js'
import type { Evaluate } from '../types/utils.js'
import { type ScopeKeyParameter, filterQueryOptions } from './utils.js'

export type GetTaskHistoryOptions = Evaluate<ScopeKeyParameter>
export type GetTaskHistoryOptions = Evaluate<
GetTaskHistoryParameters & ScopeKeyParameter
>

export function getTaskHistoryQueryOptions(
config: Config,
options: GetTaskHistoryOptions = {},
) {
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({
Expand Down
36 changes: 18 additions & 18 deletions packages/core/src/utils.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {Function} sign_message
* @returns {Promise<any>}
*/
export function generate_wallet_secrets(sign_message: Function): Promise<any>;
/**
* @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}
*/
Expand Down Expand Up @@ -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<any>;
/**
* @param {Function} sign_message
* @returns {Promise<any>}
*/
export function generate_wallet_secrets(sign_message: Function): Promise<any>;
/**
* @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
Expand Down

0 comments on commit 236530c

Please sign in to comment.