Skip to content

Commit 5100184

Browse files
committed
Update page.tsx
1 parent 4ea378a commit 5100184

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

src/app/balance/page.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { useState, useEffect, Suspense } from "react";
3+
import { useState, useEffect, useCallback, Suspense } from "react";
44
import {
55
Typography, Box, Paper, Grid, Chip, Table, TableBody, TableCell,
66
TableContainer, TableHead, TableRow, TextField, Button, Alert,
@@ -67,8 +67,8 @@ function MemberProgramRow({ memberID, programId }: { memberID: string; programId
6767

6868
/* -- Claim Member Section -- */
6969

70-
function ClaimMemberSection({ memberID, programCount, initialProgramId, initialEditCode }: {
71-
memberID: string; programCount: number; initialProgramId?: string; initialEditCode?: string;
70+
function ClaimMemberSection({ memberID, programCount, initialProgramId, initialEditCode, onClaimed }: {
71+
memberID: string; programCount: number; initialProgramId?: string; initialEditCode?: string; onClaimed?: (programId: number) => void;
7272
}) {
7373
const { address, isConnected } = useAccount();
7474
const { claimMember, isPending, isConfirming, isSuccess, error } = useClaimMember();
@@ -80,8 +80,9 @@ function ClaimMemberSection({ memberID, programCount, initialProgramId, initialE
8080
if (isSuccess) {
8181
setEditCode("");
8282
setDisclaimer(false);
83+
onClaimed?.(parseInt(claimProgramId) || 1);
8384
}
84-
}, [isSuccess]);
85+
}, [isSuccess]); // eslint-disable-line react-hooks/exhaustive-deps
8586

8687
if (!isConnected) {
8788
return (
@@ -132,11 +133,11 @@ function ClaimMemberSection({ memberID, programCount, initialProgramId, initialE
132133

133134
/* -- Actions panel (only for wallet owner) -- */
134135

135-
function OwnerActions({ memberWallet }: { memberWallet: string }) {
136+
function OwnerActions({ memberWallet, initialProgramId }: { memberWallet: string; initialProgramId?: number }) {
136137
const { address } = useAccount();
137138
const isOwner = address?.toLowerCase() === memberWallet.toLowerCase();
138139

139-
const [actionProgramId, setActionProgramId] = useState("1");
140+
const [actionProgramId, setActionProgramId] = useState(String(initialProgramId || 1));
140141
const pid = parseInt(actionProgramId) || 0;
141142

142143
// Transfer to Parent
@@ -271,11 +272,18 @@ function BalanceContent() {
271272
args: [memberIDBytes, i + 1] as const,
272273
}));
273274

274-
const { data: multicallResults } = useReadContracts({
275+
const { data: multicallResults, refetch: refetchMulticall } = useReadContracts({
275276
contracts: contracts.length > 0 ? contracts : undefined,
276277
query: { enabled: !!searchID && count > 0 },
277278
});
278279

280+
// After claim, refetch so OwnerActions appears without manual refresh
281+
const [claimedProgramId, setClaimedProgramId] = useState<number | null>(null);
282+
const handleClaimed = useCallback((programId: number) => {
283+
setClaimedProgramId(programId);
284+
refetchMulticall();
285+
}, [refetchMulticall]);
286+
279287
// Find the first result that has a valid wallet
280288
let memberWallet = "";
281289
if (multicallResults) {
@@ -348,7 +356,7 @@ function BalanceContent() {
348356
<>
349357
<Alert severity="info" sx={{ mb: 2 }}>Member &quot;{searchID}&quot; exists but has no linked wallet (walletless member).</Alert>
350358
<ClaimMemberSection memberID={searchID} programCount={count}
351-
initialProgramId={claimParam} initialEditCode={codeParam} />
359+
initialProgramId={claimParam} initialEditCode={codeParam} onClaimed={handleClaimed} />
352360
</>
353361
)}
354362

@@ -384,7 +392,7 @@ function BalanceContent() {
384392
</TableContainer>
385393
</Paper>
386394

387-
{memberWallet && <OwnerActions memberWallet={memberWallet} />}
395+
{memberWallet && <OwnerActions memberWallet={memberWallet} initialProgramId={claimedProgramId ?? undefined} />}
388396
</>
389397
)}
390398
</>

0 commit comments

Comments
 (0)