Skip to content

Commit

Permalink
fix: use replace revalidate tag with router refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
RyukTheCoder committed Dec 23, 2024
1 parent 06aea3c commit 7b60896
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/app/(home)/_components/Timer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
'use client';

import refreshLatestSwaps from 'src/app/actions';
import RefreshButton from 'src/components/common/RefreshButton';
import { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';

const REFRESH_TIME = 30;

export const Timer = () => {
const [second, setSecond] = useState(REFRESH_TIME);
const [isRefreshInProgress, setIsRefreshInProgress] = useState(false);

const router = useRouter();

useEffect(() => {
const interval = setInterval(async () => {
if (second > 0) {
Expand All @@ -25,7 +27,7 @@ export const Timer = () => {

const handleRefresh = () => {
setIsRefreshInProgress(true);
refreshLatestSwaps();
router.refresh();
setSecond(REFRESH_TIME);
};

Expand Down
8 changes: 0 additions & 8 deletions src/app/actions.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import {
SECONDS_PER_MINUTE,
} from '../constant';

export const GET_LAST_SWAPS_TAG = 'getLastSwaps';
export const getLastSwaps = async () =>
await fetch(
`${API_URL}/scanner/tx/latest?count=20&apiKey=${process.env.NEXT_PUBLIC_API_KEY}`,
{ next: { tags: [GET_LAST_SWAPS_TAG], revalidate: 30 } },
{ next: { revalidate: 30 } },
)
.then(async (res) => await res.json())
.then((data) => data?.transactions || data);
Expand Down

0 comments on commit 7b60896

Please sign in to comment.