refactor: extract useWalletAddress() hook to deduplicate session casts - #288
Conversation
Replace duplicated (session?.user as { walletAddress?: string; address?: string })
wallet address extraction across 5 files with a single shared hook.
New hook at hooks/use-wallet-address.ts:
- Returns walletAddress, falls back to address, then null
- Marked 'use client' for client component usage
- Includes 5 unit tests
Files updated:
- hooks/use-competition-join-state.ts
- components/bounty/competition-submission.tsx
- components/bounty/competition-judging.tsx
- components/bounty/fcfs-approval-panel.tsx
- components/bounty/fcfs-claim-button.tsx
Closes boundlessfi#275
|
@shogun444 is attempting to deploy a commit to the Threadflow Team on Vercel. A member of the Team first needs to authorize it. |
|
@shogun444 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA new ChangesWallet Address Hook Extraction
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@hooks/__tests__/use-wallet-address.test.ts`:
- Line 10: The test file is using a CommonJS require for the mocked auth module,
which violates the lint rule and breaks CI. Replace the require of
`@/lib/auth-client` with a standard ESM import in
hooks/__tests__/use-wallet-address.test.ts, and update the mock setup in the
useSession-related test code to use a separately named mocked reference such as
mockUseSession instead of authClient.useSession.mockReturnValue(...). Keep the
rest of the test behavior unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f52ccc27-a80c-4bc1-aeca-299eed48af86
📒 Files selected for processing (7)
components/bounty/competition-judging.tsxcomponents/bounty/competition-submission.tsxcomponents/bounty/fcfs-approval-panel.tsxcomponents/bounty/fcfs-claim-button.tsxhooks/__tests__/use-wallet-address.test.tshooks/use-competition-join-state.tshooks/use-wallet-address.ts
Benjtalkshow
left a comment
There was a problem hiding this comment.
Great work, all 5 target files are migrated cleanly and the test suite
passes. Two things before merge: pnpm tsc --noEmit fails on the test file
because authClient.useSession.mockReturnValue needs (authClient.useSession as jest.Mock).mockReturnValue(...) so TS recognizes the Jest mock API —
runtime is fine but CI will block. Also, components/bounty-detail/ bounty-detail-client.tsx:150 has the same (session?.user as { walletAddress ?: string })?.walletAddress pattern; please migrate it to
const walletAddress = useWalletAddress() ?? "" so the hook fully replaces
the duplicated cast. A screenshot of one wallet-gated button (Claim or Join
Competition) in the connected state would also help confirm no regression
from the refactor.
…detail-client to useWalletAddress()
|
@Benjtalkshow Addressed both review items:
All wallet-address session casts are now removed from components/ and hooks/. Re: screenshot - the backend GraphQL API (/api/graphql) is returning 404 on both production and local environments, so I can't render bounties to capture the wallet-gated button. the screenshot can be captured once the API is back online. |
Summary
Closes #275
This PR extracts the duplicated wallet address lookup logic into a dedicated
useWalletAddress()hook and updates all existing consumers to use it. The wallet resolution behavior remains unchanged (walletAddress → address → null), while removing repeated session casts and keeping the fallback logic centralized.Changes
Added
hooks/use-wallet-address.tsReplaced duplicated wallet address session casts in:
hooks/use-competition-join-state.tscomponents/bounty/competition-submission.tsxcomponents/bounty/competition-judging.tsxcomponents/bounty/fcfs-approval-panel.tsxcomponents/bounty/fcfs-claim-button.tsxPreserved the existing
walletAddress → address → nullfallback behaviorAdded unit tests covering the hook's behavior across all expected session states
Removed the duplicated wallet-address casts from the targeted components and hooks
Testing
pnpm tsc --noEmitcomponents/andhooks/Notes
session.idcasts infcfs-approval-panel.tsxandfcfs-claim-button.tsxwere intentionally left unchanged because they are unrelated to this issue.bounty-detail-client.tsxwas not modified since it uses a different access pattern and is outside the scope of this issue.Summary by CodeRabbit