-
Notifications
You must be signed in to change notification settings - Fork 95
feat: add cancel/refund flow with contributor-first escrow refund #656
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
Open
BWM0223
wants to merge
1
commit into
boundlessfi:main
Choose a base branch
from
BWM0223:feat/cancel-refund-flow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
|
|
||
| "use client"; | ||
| import { useState } from "react"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; | ||
| import { AlertTriangle, XCircle } from "lucide-react"; | ||
|
|
||
| interface CancelRefundFlowProps { | ||
| bountyId: string; | ||
| bountyTitle: string; | ||
| escrowBalance: number; | ||
| contributorCount: number; | ||
| onCancel: (bountyId: string) => Promise<void>; | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| export function CancelRefundFlow({ | ||
| bountyId, bountyTitle, escrowBalance, contributorCount, onCancel, onClose | ||
| }: CancelRefundFlowProps) { | ||
| const [step, setStep] = useState<"confirm" | "processing" | "done">("confirm"); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| const handleCancel = async () => { | ||
| setStep("processing"); | ||
| setError(null); | ||
| try { | ||
| await onCancel(bountyId); | ||
| setStep("done"); | ||
| } catch (e: any) { | ||
| setError(e.message ?? "Cancellation failed"); | ||
| setStep("confirm"); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Card className="border-destructive"> | ||
| <CardHeader> | ||
| <CardTitle className="flex items-center gap-2 text-destructive"> | ||
| <XCircle className="h-5 w-5" /> | ||
| {step === "done" ? "Bounty Cancelled" : "Cancel Bounty"} | ||
| </CardTitle> | ||
| <CardDescription>{bountyTitle}</CardDescription> | ||
| </CardHeader> | ||
| <CardContent className="space-y-4"> | ||
| {step === "confirm" && ( | ||
| <> | ||
| <div className="bg-muted rounded-md p-3 space-y-2 text-sm"> | ||
| <div className="flex items-start gap-2"> | ||
| <AlertTriangle className="h-4 w-4 text-yellow-500 mt-0.5 shrink-0" /> | ||
| <div> | ||
| <p className="font-medium">Refund order</p> | ||
| <ol className="list-decimal ml-4 mt-1 space-y-1 text-muted-foreground"> | ||
| <li>Contributors refunded first ({contributorCount} contributor{contributorCount !== 1 ? "s" : ""})</li> | ||
| <li>Remaining escrow balance returned to you</li> | ||
| </ol> | ||
| </div> | ||
| </div> | ||
| <p className="text-muted-foreground"> | ||
| Escrow balance: <strong>{escrowBalance} USDC</strong> | ||
| </p> | ||
| </div> | ||
| {error && <p className="text-destructive text-sm">{error}</p>} | ||
| <div className="flex gap-2"> | ||
| <Button variant="destructive" onClick={handleCancel}>Confirm Cancellation</Button> | ||
| <Button variant="outline" onClick={onClose}>Keep Bounty</Button> | ||
| </div> | ||
| </> | ||
| )} | ||
| {step === "processing" && ( | ||
| <p className="text-sm text-muted-foreground animate-pulse">Processing cancellation and refunds...</p> | ||
| )} | ||
| {step === "done" && ( | ||
| <div className="space-y-3"> | ||
| <p className="text-sm text-green-600">Bounty cancelled. Refunds are being processed.</p> | ||
| <Button variant="outline" onClick={onClose}>Close</Button> | ||
| </div> | ||
| )} | ||
| </CardContent> | ||
| </Card> | ||
| ); | ||
| } | ||
|
|
||
| export default CancelRefundFlow; | ||
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.
📐 Maintainability & Code Quality | 🟠 Major
Replace
anywithunknownin error handling.Line 29 uses
any, which violates the type safety guidelines. Update the catch clause to acceptunknownand use type narrowing before accessing properties.Suggested fix
const handleCancel = async () => { setStep("processing"); setError(null); try { await onCancel(bountyId); setStep("done"); - } catch (e: any) { - setError(e.message ?? "Cancellation failed"); + } catch (error: unknown) { + const message = error instanceof Error ? error.message : "Cancellation failed"; + setError(message); setStep("confirm"); } };📝 Committable suggestion
🤖 Prompt for AI Agents