UNPKG

@reservoir0x/relay-kit-hooks

Version:

Relay is the Fastest and Cheapest Way to Bridge and Transact Across Chains.

33 lines 1.3 kB
import { MAINNET_RELAY_API, setParams } from '@reservoir0x/relay-sdk'; import { useMemo } from 'react'; import { useInfiniteQuery } from '@tanstack/react-query'; import fetcher from '../fetcher.js'; export const queryRequests = function (baseApiUrl = MAINNET_RELAY_API, options, pageParam, headers) { const baseUrl = typeof window !== 'undefined' ? window.location.origin : undefined; const url = new URL(`${baseApiUrl}/requests/v2`, baseUrl); let query = { ...options }; if (pageParam) { query.continuation = pageParam; } setParams(url, query); return fetcher(url.href, headers); }; export default function (options, baseApiUrl, queryOptions) { const response = useInfiniteQuery({ queryKey: ['useUserTransactions', options], enabled: options !== undefined, queryFn: (data) => queryRequests(baseApiUrl, options, data.pageParam), getNextPageParam: (data) => { return data.continuation; }, initialPageParam: null, retry: false, ...queryOptions }); const transactions = useMemo(() => response.data?.pages?.flatMap((page) => page?.requests || []) ?? [], [response.data]); return { ...response, data: transactions }; } //# sourceMappingURL=useRequests.js.map