From b0cac940bddc4f0e6b07fd99866bc8c5c1968fc6 Mon Sep 17 00:00:00 2001 From: MananTank Date: Mon, 13 Oct 2025 20:20:30 +0000 Subject: [PATCH] Dashboard: Add block_timestamp_from param to useTokenTransfers (#8121) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR enhances the `useTokenTransfers` functionality by adding a time filter for token transfers and improving the refetching logic based on error states. ### Detailed summary - Introduced a constant `THIRTY_DAYS_AGO` to represent the timestamp 30 days prior. - Added a search parameter `block_timestamp_from` to the `url` with the calculated timestamp. - Changed `refetchInterval` to conditionally return `false` if there's an error in the data. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit * **New Features** * Token transfer history now defaults to the last 30 days for more relevant results. * **Bug Fixes** * Auto-refresh pauses when an error occurs, preventing repeated failures and unnecessary requests. * Auto-refresh resumes normal operation once the error clears, keeping data up to date without manual refresh. --- .../public-pages/erc20/_hooks/useTokenTransfers.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_hooks/useTokenTransfers.ts b/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_hooks/useTokenTransfers.ts index fa09266874b..41eb1fae6b4 100644 --- a/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_hooks/useTokenTransfers.ts +++ b/apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_hooks/useTokenTransfers.ts @@ -1,4 +1,5 @@ import { useQuery } from "@tanstack/react-query"; +import { getUnixTime, subDays } from "date-fns"; import { isProd } from "@/constants/env-utils"; import { NEXT_PUBLIC_DASHBOARD_CLIENT_ID } from "@/constants/public-envs"; @@ -35,6 +36,11 @@ export function useTokenTransfers(params: { url.searchParams.set("page", params.page.toString()); url.searchParams.set("limit", params.limit.toString()); url.searchParams.set("clientId", NEXT_PUBLIC_DASHBOARD_CLIENT_ID); + const THIRTY_DAYS_AGO = subDays(new Date(), 30); + url.searchParams.set( + "block_timestamp_from", + getUnixTime(THIRTY_DAYS_AGO).toString(), + ); const res = await fetch(url); if (!res.ok) { @@ -46,7 +52,12 @@ export function useTokenTransfers(params: { return data; }, queryKey: ["token-transfers", params], - refetchInterval: 5000, + refetchInterval: (data) => { + if (data?.state.error) { + return false; + } + return 5000; + }, refetchOnWindowFocus: false, retry: false, retryOnMount: false,