Skip to content

Extract a useWalletAddress() hook to remove duplicated session casts #275

Description

@Benjtalkshow

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions