Skip to content

Commit dc169ef

Browse files
committed
refactor(profile): update refreshData method in unclaimed hypercert buttons
- Refactors the refreshData method to improve path invalidation and refresh logic. - Implements a 5-second delay before refreshing the router and navigating to the hypercerts-claimable tab. - includes {path: "/", type: "layout"} to revalidate root layout.
1 parent bcc1280 commit dc169ef

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

components/profile/unclaimed-hypercert-batchClaim-button.tsx

+15-6
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default function UnclaimedHypercertBatchClaimButton({
5151
const selectedChain = selectedChainId
5252
? ChainFactory.getChain(selectedChainId)
5353
: null;
54-
const query = useOwnedHypercerts(getAddress(account.address!));
54+
// const query = useOwnedHypercerts(getAddress(account.address!));
5555

5656
const refreshData = async (address: string) => {
5757
const hypercertIds = allowListRecords.map((record) => record.hypercert_id);
@@ -61,12 +61,21 @@ export default function UnclaimedHypercertBatchClaimButton({
6161
});
6262

6363
await revalidatePathServerAction([
64-
`/profile/${address}?tab=hypercerts-claimable`,
65-
`/profile/${address}?tab=hypercerts-owned`,
64+
{ path: `/profile/${address}?tab`, type: "page" },
65+
{ path: `/profile/${address}?tab=hypercerts-claimable`, type: "page" },
66+
{ path: `/profile/${address}?tab=hypercerts-owned`, type: "page" },
6667
...hypercertViewInvalidationPaths,
67-
]);
68-
await query.refetch();
69-
router.refresh();
68+
{ path: "/", type: "layout" },
69+
]).then(async () => {
70+
setTimeout(() => {
71+
// refresh after 5 seconds
72+
router.refresh();
73+
74+
// push to the profile page with the hypercerts-claimable tab
75+
// because revalidatePath will revalidate on the next page visit.
76+
router.push(`/profile/${address}?tab=hypercerts-claimable`);
77+
}, 5000);
78+
});
7079
};
7180

7281
const claimHypercert = async () => {

components/profile/unclaimed-hypercert-claim-button.tsx

+18-12
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { useStepProcessDialogContext } from "../global/step-process-dialog";
1111
import { createExtraContent } from "../global/extra-content";
1212
import { revalidatePathServerAction } from "@/app/actions/revalidatePathServerAction";
1313
import { useState } from "react";
14-
import { useQueryClient } from "@tanstack/react-query";
14+
// import { useQueryClient } from "@tanstack/react-query";
1515
import { getAddress } from "viem";
16-
import { useOwnedHypercerts } from "@/hooks/useOwnedHypercerts";
16+
// import { useOwnedHypercerts } from "@/hooks/useOwnedHypercerts";
1717

1818
interface UnclaimedHypercertClaimButtonProps {
1919
allowListRecord: Row<AllowListRecord>;
@@ -31,19 +31,28 @@ export default function UnclaimedHypercertClaimButton({
3131
useStepProcessDialogContext();
3232
const { switchChain } = useSwitchChain();
3333
const router = useRouter();
34-
const query = useOwnedHypercerts(getAddress(account.address!));
34+
// const query = useOwnedHypercerts(getAddress(account.address!));
3535

3636
const selectedHypercert = allowListRecord.original;
3737
const hypercertChainId = selectedHypercert?.hypercert_id?.split("-")[0];
3838

3939
const refreshData = async (address: string) => {
4040
await revalidatePathServerAction([
41-
`/profile/${address}?tab=hypercerts-claimable`,
42-
`/profile/${address}?tab=hypercerts-owned`,
43-
`/hypercerts/${selectedHypercert?.hypercert_id}`,
44-
]);
45-
await query.refetch();
46-
router.refresh();
41+
{ path: `/profile/${address}?tab`, type: "page" },
42+
{ path: `/profile/${address}?tab=hypercerts-claimable`, type: "page" },
43+
{ path: `/profile/${address}?tab=hypercerts-owned`, type: "page" },
44+
{ path: `/hypercerts/${selectedHypercert?.hypercert_id}`, type: "page" },
45+
{ path: "/", type: "layout" },
46+
]).then(async () => {
47+
setTimeout(() => {
48+
// refresh after 5 seconds
49+
router.refresh();
50+
51+
// push to the profile page with the hypercerts-claimable tab
52+
// because revalidatePath will revalidate on the next page visit.
53+
router.push(`/profile/${address}?tab=hypercerts-claimable`);
54+
}, 5000);
55+
});
4756
};
4857

4958
const claimHypercert = async () => {
@@ -111,9 +120,6 @@ export default function UnclaimedHypercertClaimButton({
111120
} else if (receipt.status == "reverted") {
112121
await setDialogStep("confirming", "error", "Transaction reverted");
113122
}
114-
setTimeout(() => {
115-
refresh();
116-
}, 5000);
117123
} catch (error) {
118124
console.error(error);
119125
} finally {

0 commit comments

Comments
 (0)