Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to requests api v2 in sdk and client #212

Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions .changeset/thirty-beds-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@reservoir0x/relay-kit-hooks': minor
'@reservoir0x/relay-kit-ui': minor
---

Upgrade /requests api to /requests/v2
6 changes: 3 additions & 3 deletions packages/hooks/src/hooks/useRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
import fetcher from '../fetcher.js'

export type UserTransactionQuery =
paths['/requests']['get']['parameters']['query'] & { id?: string }
paths['/requests/v2']['get']['parameters']['query'] & { id?: string }

export type UserTransactionsResponse =
paths['/requests']['get']['responses']['200']['content']['application/json']
paths['/requests/v2']['get']['responses']['200']['content']['application/json']

type InfiniteQueryType = typeof useInfiniteQuery<
UserTransactionsResponse,
Expand All @@ -33,7 +33,7 @@ export const queryRequests = function (
pageParam?: string | null
): Promise<UserTransactionsResponse> {
const baseUrl = typeof window !== 'undefined' ? window.location.origin : ''
const url = new URL(`${baseApiUrl}/requests`, baseUrl)
const url = new URL(`${baseApiUrl}/requests/v2`, baseUrl)

let query: UserTransactionQuery = { ...options }

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/types/RelayTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { paths } from '@reservoir0x/relay-sdk'

export type UserTransactionsResponse =
paths['/requests']['get']['responses']['200']['content']['application/json']
paths['/requests/v2']['get']['responses']['200']['content']['application/json']

export type RelayTransaction = NonNullable<
NonNullable<UserTransactionsResponse>['requests']
Expand Down
12 changes: 10 additions & 2 deletions packages/ui/src/utils/relayTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export const extractToChain = (
export const calculateFillTime = (transaction?: RelayTransaction | null) => {
let fillTime = '-'
let seconds = 0
if (transaction?.status !== 'pending' && transaction?.status !== 'received') {
if (
transaction?.status !== 'pending' &&
transaction?.status !== 'waiting' &&
transaction?.status !== 'delayed'
) {
const inTxTimestamps =
transaction?.data?.inTxs?.map((tx) => tx.timestamp as number) ?? null
const txStartTimestamp = inTxTimestamps ? Math.min(...inTxTimestamps) : null
Expand Down Expand Up @@ -57,7 +61,11 @@ export const calculateExecutionTime = (
) => {
let fillTime = '-'
let seconds = 0
if (transaction?.status !== 'pending' && transaction?.status !== 'received') {
if (
transaction?.status !== 'pending' &&
transaction?.status !== 'waiting' &&
transaction?.status !== 'delayed'
) {
const inTxTimestamps =
transaction?.data?.inTxs?.map((tx) => tx.timestamp as number) ?? null
const outTxTimestamps =
Expand Down