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 (#149)

* core: actions, query: expose limit param for getOrderHistory & getTaskHistory

* chore: version packages
  • Loading branch information
akirillo authored Jan 9, 2025
1 parent dea5932 commit 4b52216
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 33 deletions.
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @renegade-fi/core

## 0.4.15

### Patch Changes

- expose history length params & useQuery util

## 0.4.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@renegade-fi/core",
"description": "VanillaJS library for Renegade",
"version": "0.4.14",
"version": "0.4.15",
"repository": {
"type": "git",
"url": "https://github.com/renegade-fi/typescript-sdk.git",
Expand Down
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
7 changes: 7 additions & 0 deletions packages/node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @renegade-fi/node

## 0.4.15

### Patch Changes

- Updated dependencies
- @renegade-fi/core@0.4.15

## 0.4.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/node/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@renegade-fi/node",
"description": "Node.js library for Renegade",
"version": "0.4.14",
"version": "0.4.15",
"repository": {
"type": "git",
"url": "https://github.com/renegade-fi/typescript-sdk.git",
Expand Down
8 changes: 8 additions & 0 deletions packages/react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @renegade-fi/react

## 0.4.16

### Patch Changes

- expose history length params & useQuery util
- Updated dependencies
- @renegade-fi/core@0.4.15

## 0.4.15

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@renegade-fi/react",
"description": "React library for Renegade",
"version": "0.4.15",
"version": "0.4.16",
"repository": {
"type": "git",
"url": "https://github.com/renegade-fi/typescript-sdk.git",
Expand Down
6 changes: 6 additions & 0 deletions packages/react/src/exports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ export {
type UseWithdrawReturnType,
} from '../hooks/useWithdraw.js'

////////////////////////////////////////////////////////////////////////////////
// Utils
////////////////////////////////////////////////////////////////////////////////

export { useQuery } from '../utils/query.js'

////////////////////////////////////////////////////////////////////////////////
// @renegade/core
////////////////////////////////////////////////////////////////////////////////
Expand Down
7 changes: 7 additions & 0 deletions packages/test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @renegade-fi/test

## 0.3.14

### Patch Changes

- Updated dependencies
- @renegade-fi/core@0.4.15

## 0.3.13

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@renegade-fi/test",
"version": "0.3.13",
"version": "0.3.14",
"description": "Testing helpers for Renegade",
"private": true,
"files": [
Expand Down

0 comments on commit 4b52216

Please sign in to comment.