-
Notifications
You must be signed in to change notification settings - Fork 96
fix(types): remove ad-hoc UI field casts from bounty type #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Ishant5436
wants to merge
2
commits into
boundlessfi:main
from
Ishant5436:fix/issue-211-bounty-types
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,29 @@ | ||
| import { NextResponse } from 'next/server'; | ||
| import { getMockLeaderboard } from '@/lib/mock-leaderboard'; | ||
| import { LeaderboardResponse, ReputationTier } from '@/types/leaderboard'; | ||
| import { NextResponse } from "next/server"; | ||
| import { getMockLeaderboard } from "@/lib/mock"; | ||
| import { LeaderboardResponse, ReputationTier } from "@/types/leaderboard"; | ||
|
|
||
| export async function GET(request: Request) { | ||
| const { searchParams } = new URL(request.url); | ||
| const page = parseInt(searchParams.get('page') || '1'); | ||
| const limit = parseInt(searchParams.get('limit') || '10'); | ||
| const tier = searchParams.get('tier') as ReputationTier | null; | ||
| const { searchParams } = new URL(request.url); | ||
| const page = parseInt(searchParams.get("page") || "1"); | ||
| const limit = parseInt(searchParams.get("limit") || "10"); | ||
| const tier = searchParams.get("tier") as ReputationTier | null; | ||
|
|
||
| // Simulate network delay | ||
| await new Promise(resolve => setTimeout(resolve, 300)); | ||
| // Simulate network delay | ||
| await new Promise((resolve) => setTimeout(resolve, 300)); | ||
|
|
||
| const { data, total } = getMockLeaderboard(page, limit, tier || undefined); | ||
| const { data, total } = getMockLeaderboard(page, limit, tier || undefined); | ||
|
|
||
| const response: LeaderboardResponse = { | ||
| entries: data.map((contributor, index) => ({ | ||
| rank: (page - 1) * limit + index + 1, | ||
| previousRank: null, // Mock data doesn't track history yet | ||
| rankChange: 0, | ||
| contributor, | ||
| })), | ||
| totalCount: total, | ||
| currentUserRank: null, // Only relevant if user context is provided | ||
| lastUpdatedAt: new Date().toISOString(), | ||
| }; | ||
| const response: LeaderboardResponse = { | ||
| entries: data.map((contributor, index) => ({ | ||
| rank: (page - 1) * limit + index + 1, | ||
| previousRank: null, // Mock data doesn't track history yet | ||
| rankChange: 0, | ||
| contributor, | ||
| })), | ||
| totalCount: total, | ||
| currentUserRank: null, // Only relevant if user context is provided | ||
| lastUpdatedAt: new Date().toISOString(), | ||
| }; | ||
|
|
||
| return NextResponse.json(response); | ||
| return NextResponse.json(response); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,15 @@ | ||
| import { NextResponse } from 'next/server'; | ||
| import { getMockLeaderboard } from '@/lib/mock-leaderboard'; | ||
| import { NextResponse } from "next/server"; | ||
| import { getMockLeaderboard } from "@/lib/mock"; | ||
|
|
||
| export async function GET(request: Request) { | ||
| const { searchParams } = new URL(request.url); | ||
| const count = parseInt(searchParams.get('count') || '5'); | ||
| const { searchParams } = new URL(request.url); | ||
| const count = parseInt(searchParams.get("count") || "5"); | ||
|
|
||
| // Simulate network delay | ||
| await new Promise(resolve => setTimeout(resolve, 200)); | ||
| // Simulate network delay | ||
| await new Promise((resolve) => setTimeout(resolve, 200)); | ||
|
|
||
| // Get top N contributors | ||
| const { data } = getMockLeaderboard(1, count); | ||
| // Get top N contributors | ||
| const { data } = getMockLeaderboard(1, count); | ||
|
|
||
| return NextResponse.json(data); | ||
| return NextResponse.json(data); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,26 @@ | ||
| import { NextResponse } from 'next/server'; | ||
| import { getMockUserRank } from '@/lib/mock-leaderboard'; | ||
| import { NextResponse } from "next/server"; | ||
| import { getMockUserRank } from "@/lib/mock"; | ||
|
|
||
| interface Params { | ||
| params: Promise<{ userId: string }>; | ||
| params: Promise<{ userId: string }>; | ||
| } | ||
|
|
||
| export async function GET(request: Request, { params }: Params) { | ||
| // Await params as per Next.js 15+ requirements if applicable, or good practice for future | ||
| const { userId } = await params; | ||
| // Await params as per Next.js 15+ requirements if applicable, or good practice for future | ||
| const { userId } = await params; | ||
|
|
||
| // Simulate network delay | ||
| await new Promise(resolve => setTimeout(resolve, 200)); | ||
| // Simulate network delay | ||
| await new Promise((resolve) => setTimeout(resolve, 200)); | ||
|
|
||
| const result = getMockUserRank(userId); | ||
| const result = getMockUserRank(userId); | ||
|
|
||
| if (!result) { | ||
| return NextResponse.json({ error: 'User not found' }, { status: 404 }); | ||
| } | ||
| if (!result) { | ||
| return NextResponse.json({ error: "User not found" }, { status: 404 }); | ||
| } | ||
|
|
||
| return NextResponse.json({ | ||
| rank: result.rank, | ||
| contributor: result.contributor, | ||
| paramsUserId: userId | ||
| }); | ||
| return NextResponse.json({ | ||
| rank: result.rank, | ||
| contributor: result.contributor, | ||
| paramsUserId: userId, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,9 @@ | ||
| import { getAllProjects, getAllProjectTags } from "@/lib/mock-project" | ||
| import { ProjectsDiscovery } from "@/components/projects/projects-discovery" | ||
| import { getAllProjects, getAllProjectTags } from "@/lib/mock"; | ||
| import { ProjectsDiscovery } from "@/components/projects/projects-discovery"; | ||
|
|
||
| export default async function ProjectsPage() { | ||
| const projects = getAllProjects() | ||
| const allTags = getAllProjectTags(projects) | ||
| const projects = getAllProjects(); | ||
| const allTags = getAllProjectTags(projects); | ||
|
|
||
| return <ProjectsDiscovery projects={projects} allTags={allTags} /> | ||
| return <ProjectsDiscovery projects={projects} allTags={allTags} />; | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,10 +21,7 @@ import { authClient } from "@/lib/auth-client"; | |
| import { useDeadlinePassed } from "@/hooks/use-deadline-passed"; | ||
| import type { CancellationRecord } from "@/types/escrow"; | ||
| import { MilestoneFunnel } from "@/components/bounty/milestone-funnel"; | ||
| import { | ||
| MOCK_MODEL4_MILESTONES, | ||
| MOCK_MODEL4_CONTRIBUTORS, | ||
| } from "@/lib/mock-model4"; | ||
| import { MOCK_MODEL4_MILESTONES, MOCK_MODEL4_CONTRIBUTORS } from "@/lib/mock"; | ||
| import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; | ||
| import { MilestoneSubmissionCard } from "./milestone-submission-card"; | ||
| import { Model4MaintainerDashboard } from "./model4-maintainer-dashboard"; | ||
|
|
@@ -71,10 +68,7 @@ function getFullMilestoneData(bounty: BountyData): { | |
| // Backend does not currently provide applications in the response. | ||
| // Fall back to empty array until the schema supports it. | ||
| const getApplications = (bounty: BountyData): Application[] => { | ||
| return ( | ||
| (bounty as BountyData & { applications?: Application[] })?.applications ?? | ||
| [] | ||
| ); | ||
| return (bounty?.applications as Application[]) ?? []; | ||
| }; | ||
|
|
||
| export function BountyDetailClient({ bountyId }: { bountyId: string }) { | ||
|
|
@@ -155,17 +149,18 @@ export function BountyDetailClient({ bountyId }: { bountyId: string }) { | |
| // Identify if the current user is the assigned contributor | ||
| // using a fallback check on submissions or assumed backend field. | ||
| const isAssignedApplicant = | ||
| (bounty as BountyData & { assignedContributorId?: string }) | ||
| ?.assignedContributorId === session?.user?.id || | ||
| bounty?.assignedContributorId === session?.user?.id || | ||
| bounty.submissions?.some((s) => s.submittedBy === session?.user?.id) || | ||
| (!isCreator && bounty.status === "IN_PROGRESS"); | ||
|
Comment on lines
+152
to
154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tighten assigned-applicant gating at Line 155. The 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 |
||
|
|
||
| // submissions is present on BountyQuery (single-bounty query) but not on | ||
| // BountyFieldsFragment (list query). The cast is safe here because | ||
| // useBountyDetail returns BountyFieldsFragment & Partial<BountyQuery["bounty"]>. | ||
| const competitionSubmissions = | ||
| (bounty as { submissions?: CompetitionSubmissionEntry[] | null }) | ||
| .submissions ?? []; | ||
| const competitionSubmissions = bounty.submissions ?? []; | ||
|
|
||
| // Use the casted submissions list or fallback to our placeholder | ||
| const userSubmission = competitionSubmissions.find( | ||
| (s) => | ||
| s.submittedBy === | ||
| (session?.user as { walletAddress?: string })?.walletAddress, | ||
| ); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col lg:flex-row gap-10"> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
🤖 Prompt for AI Agents