fix(types): remove ad-hoc UI field casts from bounty type - #229
fix(types): remove ad-hoc UI field casts from bounty type#229Ishant5436 wants to merge 2 commits into
Conversation
|
@Ishant5436 is attempting to deploy a commit to the Threadflow Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
More reviews will be available in 39 minutes and 49 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (20)
📝 WalkthroughWalkthroughThis PR extends the ChangesBounty type extension and cast removal
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 2
🤖 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 `@components/bounty-detail/bounty-detail-client.tsx`:
- Line 74: Remove the unsafe cast on "bounty?.applications as Application[]":
instead validate and transform the runtime value before returning it (e.g.,
check Array.isArray(bounty?.applications), and map/filter items with a small
type-guard or validator like isValidApplication to construct Application
objects), returning [] when the check fails; add or reuse a type guard function
named isValidApplication(item): item is Application and use it in
Array.prototype.filter/map so the function returns a properly-typed
Application[] without relying on an unsafe cast.
- Around line 155-157: The current assigned-applicant check is too permissive
and uses user id instead of wallet address; update the logic so a user is
considered assigned only if bounty.assignedContributorId matches the current
user's wallet address and/or the bounty.status is IN_PROGRESS and
assignedContributorId equals that same wallet; also change the submissions check
to compare s.submittedBy to session.user.address (wallet) rather than
session.user.id; locate and update the expression referencing
bounty?.assignedContributorId, bounty.submissions?.some((s) => s.submittedBy ===
session?.user?.id), isCreator, and bounty.status === "IN_PROGRESS" to implement
these stricter checks and keep proper null/undefined guards.
🪄 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: e9d7c626-11c5-4ff6-b7bb-859c676f023a
📒 Files selected for processing (3)
components/bounty-detail/bounty-detail-client.tsxhooks/use-competition-join-state.tstypes/bounty.ts
| (bounty as BountyData & { applications?: Application[] })?.applications ?? | ||
| [] | ||
| ); | ||
| return (bounty?.applications as Application[]) ?? []; |
There was a problem hiding this comment.
Remove the remaining unsafe cast at Line 74.
This cast weakens the type-safety goal of this PR and can mask shape mismatches between API data and Application.
Proposed fix
-const getApplications = (bounty: BountyData): Application[] => {
- return (bounty?.applications as Application[]) ?? [];
-};
+const getApplications = (bounty: BountyData): Application[] => {
+ return bounty?.applications ?? [];
+};🤖 Prompt for 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.
In `@components/bounty-detail/bounty-detail-client.tsx` at line 74, Remove the
unsafe cast on "bounty?.applications as Application[]": instead validate and
transform the runtime value before returning it (e.g., check
Array.isArray(bounty?.applications), and map/filter items with a small
type-guard or validator like isValidApplication to construct Application
objects), returning [] when the check fails; add or reuse a type guard function
named isValidApplication(item): item is Application and use it in
Array.prototype.filter/map so the function returns a properly-typed
Application[] without relying on an unsafe cast.
| bounty?.assignedContributorId === session?.user?.id || | ||
| bounty.submissions?.some((s) => s.submittedBy === session?.user?.id) || | ||
| (!isCreator && bounty.status === "IN_PROGRESS"); |
There was a problem hiding this comment.
Tighten assigned-applicant gating at Line 155.
The (!isCreator && bounty.status === "IN_PROGRESS") branch effectively marks all non-creators as assigned, and Line 156 compares submittedBy to user.id instead of wallet address.
Proposed fix
+ const sessionUserId =
+ (session?.user as { id?: string } | undefined)?.id ?? null;
const isAssignedApplicant =
- bounty?.assignedContributorId === session?.user?.id ||
- bounty.submissions?.some((s) => s.submittedBy === session?.user?.id) ||
- (!isCreator && bounty.status === "IN_PROGRESS");
+ bounty?.assignedContributorId === sessionUserId ||
+ Boolean(
+ walletAddress &&
+ bounty.submissions?.some((s) => s.submittedBy === walletAddress),
+ );🤖 Prompt for 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.
In `@components/bounty-detail/bounty-detail-client.tsx` around lines 155 - 157,
The current assigned-applicant check is too permissive and uses user id instead
of wallet address; update the logic so a user is considered assigned only if
bounty.assignedContributorId matches the current user's wallet address and/or
the bounty.status is IN_PROGRESS and assignedContributorId equals that same
wallet; also change the submissions check to compare s.submittedBy to
session.user.address (wallet) rather than session.user.id; locate and update the
expression referencing bounty?.assignedContributorId,
bounty.submissions?.some((s) => s.submittedBy === session?.user?.id), isCreator,
and bounty.status === "IN_PROGRESS" to implement these stricter checks and keep
proper null/undefined guards.
Migrate legacy mock data files to a unified lib/mock directory structure. Implement factory functions for Bounties, Projects, Leaderboard, and Wallet entities to improve testability. Centralize exports and resolve associated TypeScript type conflicts in consuming components.
Fixes #211 by extending the central
Bountyinterface with optional UI fields (applications,claimCount,maxParticipants,assignedContributorId) and cleaning up all ad-hoc type casts across the detail and dashboard components.Summary by CodeRabbit
Bug Fixes
New Features