-
Notifications
You must be signed in to change notification settings - Fork 19
feat-Implement Bounty Status Logic & Anti-Squatting #55
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
Merged
0xdevcollins
merged 6 commits into
boundlessfi:main
from
Dprof-in-tech:feat-Implement-Bounty-Status-Logic-&-Anti-Squatting
Jan 29, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c296a51
feat-Implement Bounty Status Logic & Anti-Squatting
Dprof-in-tech 5db20cc
feat: Standardize date fields to ISO 8601 strings across bounty and p…
Dprof-in-tech 20cf8b4
refactor: Refine type definitions for `claimingModel` and simplify da…
Dprof-in-tech 2efd38c
Remove `CLAIM_DURATION_DAYS` constant from bounty logic.
Dprof-in-tech c0a08a4
refactor: Standardize bounty status logic with `StatusAwareBounty` in…
Dprof-in-tech 058387f
fix: Reset `lastActivityAt` when a bounty claim is cleared or expires.
Dprof-in-tech 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
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
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 |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { differenceInDays, isPast, parseISO, isValid } from 'date-fns'; | ||
|
|
||
|
|
||
| /** | ||
| * Interface defining the minimal fields required for status logic. | ||
| * Compatible with both `types/bounty.ts` and `lib/types.ts`. | ||
| */ | ||
| export interface StatusAwareBounty { | ||
| status: string; | ||
| claimingModel: string; | ||
| claimExpiresAt?: string; | ||
| lastActivityAt?: string; | ||
| claimedBy?: string; | ||
| claimedAt?: string; | ||
| } | ||
|
|
||
| export class BountyLogic { | ||
| /** | ||
| * Configuration for inactivity thresholds (in days) | ||
| */ | ||
| static readonly INACTIVITY_THRESHOLD_DAYS = 7; | ||
|
|
||
| /** | ||
| * Processes the bounty status based on its model and timestamps. | ||
| * - Checks for inactivity auto-release for single-claim. | ||
| * - Checks for expired claims. | ||
| * - Returns the potentially modified bounty (this simulates the backend update). | ||
| */ | ||
| static processBountyStatus<T extends StatusAwareBounty>(bounty: T): T { | ||
| if (bounty.status !== 'claimed' && bounty.status !== 'open') return bounty; | ||
|
|
||
| const now = new Date(); | ||
| // Shallow copy works for pure property updates | ||
| const newBounty = { ...bounty }; | ||
|
|
||
| // Anti-squatting: Check inactivity for single-claim | ||
| if ( | ||
| bounty.claimingModel === 'single-claim' && | ||
| bounty.status === 'claimed' | ||
| ) { | ||
| // Helper to get Date object safely | ||
| const getDate = (val?: string) => { | ||
| if (!val) return null; | ||
| const date = parseISO(val); | ||
| return isValid(date) ? date : null; | ||
| }; | ||
|
|
||
| const expiresAt = getDate(bounty.claimExpiresAt); | ||
|
|
||
| // If claim expired | ||
| if (expiresAt && isPast(expiresAt)) { | ||
| // Auto-release | ||
| newBounty.status = 'open'; | ||
| newBounty.claimedBy = undefined; | ||
| newBounty.claimedAt = undefined; | ||
| newBounty.claimExpiresAt = undefined; | ||
| newBounty.lastActivityAt = undefined; | ||
| } | ||
|
|
||
| // If inactive for too long | ||
| const lastActive = getDate(bounty.lastActivityAt) || getDate(bounty.claimedAt); | ||
| if (lastActive) { | ||
| const daysInactive = differenceInDays(now, lastActive); | ||
| if (daysInactive > this.INACTIVITY_THRESHOLD_DAYS) { | ||
| // Auto-release due to inactivity | ||
| newBounty.status = 'open'; | ||
| newBounty.claimedBy = undefined; | ||
| newBounty.claimedAt = undefined; | ||
| newBounty.claimExpiresAt = undefined; | ||
| newBounty.lastActivityAt = undefined; | ||
| } | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return newBounty; | ||
| } | ||
|
|
||
| /** | ||
| * Returns metadata about the claim status suitable for UI display. | ||
| */ | ||
| static getClaimStatusDisplay(bounty: StatusAwareBounty) { | ||
| if (bounty.status === 'open') return { label: 'Available', color: 'green' }; | ||
|
|
||
| if (bounty.status === 'claimed') { | ||
| if (bounty.claimingModel === 'single-claim') { | ||
| return { | ||
| label: 'Claimed', | ||
| color: 'orange', | ||
| details: bounty.claimExpiresAt ? `Expires ${BountyLogic.formatDate(bounty.claimExpiresAt)}` : 'In Progress' | ||
| }; | ||
| } | ||
| if (bounty.claimingModel === 'application') { | ||
| return { label: 'Applications Open', color: 'blue' }; | ||
| } | ||
| } | ||
|
|
||
| return { label: bounty.status, color: 'gray' }; | ||
| } | ||
|
|
||
| private static formatDate(dateStr: string) { | ||
| const date = parseISO(dateStr); | ||
| if (!isValid(date)) return 'Invalid Date'; | ||
| return date.toLocaleDateString(); | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.