Skip to content

Commit b0cac94

Browse files
committed
Dashboard: Add block_timestamp_from param to useTokenTransfers (#8121)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## 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}` <!-- end pr-codex --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1a19e14 commit b0cac94

File tree

1 file changed

+12
-1
lines changed
  • apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_hooks

1 file changed

+12
-1
lines changed

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/public-pages/erc20/_hooks/useTokenTransfers.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useQuery } from "@tanstack/react-query";
2+
import { getUnixTime, subDays } from "date-fns";
23
import { isProd } from "@/constants/env-utils";
34
import { NEXT_PUBLIC_DASHBOARD_CLIENT_ID } from "@/constants/public-envs";
45

@@ -35,6 +36,11 @@ export function useTokenTransfers(params: {
3536
url.searchParams.set("page", params.page.toString());
3637
url.searchParams.set("limit", params.limit.toString());
3738
url.searchParams.set("clientId", NEXT_PUBLIC_DASHBOARD_CLIENT_ID);
39+
const THIRTY_DAYS_AGO = subDays(new Date(), 30);
40+
url.searchParams.set(
41+
"block_timestamp_from",
42+
getUnixTime(THIRTY_DAYS_AGO).toString(),
43+
);
3844

3945
const res = await fetch(url);
4046
if (!res.ok) {
@@ -46,7 +52,12 @@ export function useTokenTransfers(params: {
4652
return data;
4753
},
4854
queryKey: ["token-transfers", params],
49-
refetchInterval: 5000,
55+
refetchInterval: (data) => {
56+
if (data?.state.error) {
57+
return false;
58+
}
59+
return 5000;
60+
},
5061
refetchOnWindowFocus: false,
5162
retry: false,
5263
retryOnMount: false,

0 commit comments

Comments
 (0)