The following pattern is duplicated across five files:
(session?.user as { walletAddress?: string; address?: string } | undefined)?.walletAddress ||
(session?.user as { walletAddress?: string; address?: string } | undefined)?.address ||
null
Files with the cast:
components/bounty/fcfs-approval-panel.tsx
components/bounty/fcfs-claim-button.tsx
components/bounty/competition-submission.tsx
components/bounty/competition-judging.tsx
hooks/use-competition-join-state.ts
The cast drifts in shape across files and the fallback to address is easy to miss when adding a new caller.
What to do
Add hooks/use-wallet-address.ts:
import { authClient } from "@/lib/auth-client";
/**
* Returns the connected wallet address from the current session, or null
* if the user is not signed in or has no wallet attached.
*/
export function useWalletAddress(): string | null {
const { data: session } = authClient.useSession();
const user = session?.user as
| { walletAddress?: string; address?: string }
| undefined;
return user?.walletAddress || user?.address || null;
}
Replace the duplicated casts in the five files above with const walletAddress = useWalletAddress();.
Acceptance criteria
- New hook lives at
hooks/use-wallet-address.ts
- All five files import and use it
- No
(session?.user as { walletAddress?: string; address?: string ...}) casts remain anywhere in components/ or hooks/
- No behavior change
Files
hooks/use-wallet-address.ts (new)
components/bounty/fcfs-approval-panel.tsx
components/bounty/fcfs-claim-button.tsx
components/bounty/competition-submission.tsx
components/bounty/competition-judging.tsx
hooks/use-competition-join-state.ts
The following pattern is duplicated across five files:
Files with the cast:
components/bounty/fcfs-approval-panel.tsxcomponents/bounty/fcfs-claim-button.tsxcomponents/bounty/competition-submission.tsxcomponents/bounty/competition-judging.tsxhooks/use-competition-join-state.tsThe cast drifts in shape across files and the fallback to
addressis easy to miss when adding a new caller.What to do
Add
hooks/use-wallet-address.ts:Replace the duplicated casts in the five files above with
const walletAddress = useWalletAddress();.Acceptance criteria
hooks/use-wallet-address.ts(session?.user as { walletAddress?: string; address?: string ...})casts remain anywhere incomponents/orhooks/Files
hooks/use-wallet-address.ts(new)components/bounty/fcfs-approval-panel.tsxcomponents/bounty/fcfs-claim-button.tsxcomponents/bounty/competition-submission.tsxcomponents/bounty/competition-judging.tsxhooks/use-competition-join-state.ts