-
Notifications
You must be signed in to change notification settings - Fork 0
feat: wire CryptoCheckout 4-step flow into billing page #63
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,10 +6,10 @@ import { useCallback, useEffect, useState } from "react"; | |||||||||||||||||||||||||||
| import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; | ||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||
| type CheckoutResult, | ||||||||||||||||||||||||||||
| type SupportedPaymentMethod, | ||||||||||||||||||||||||||||
| createCheckout, | ||||||||||||||||||||||||||||
| getChargeStatus, | ||||||||||||||||||||||||||||
| getSupportedPaymentMethods, | ||||||||||||||||||||||||||||
| type SupportedPaymentMethod, | ||||||||||||||||||||||||||||
| } from "@/lib/api"; | ||||||||||||||||||||||||||||
| import { AmountSelector } from "./amount-selector"; | ||||||||||||||||||||||||||||
| import { ConfirmationTracker } from "./confirmation-tracker"; | ||||||||||||||||||||||||||||
|
|
@@ -30,7 +30,9 @@ export function CryptoCheckout() { | |||||||||||||||||||||||||||
| const [loading, setLoading] = useState(false); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||
| getSupportedPaymentMethods().then(setMethods).catch(() => {}); | ||||||||||||||||||||||||||||
| getSupportedPaymentMethods() | ||||||||||||||||||||||||||||
| .then(setMethods) | ||||||||||||||||||||||||||||
| .catch(() => {}); | ||||||||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||
|
|
@@ -47,7 +49,10 @@ export function CryptoCheckout() { | |||||||||||||||||||||||||||
| } else if (res.status === "expired" || res.status === "failed") { | ||||||||||||||||||||||||||||
| setStatus(res.status as PaymentStatus); | ||||||||||||||||||||||||||||
| clearInterval(interval); | ||||||||||||||||||||||||||||
| } else if (res.amountReceivedCents > 0 && res.amountReceivedCents >= res.amountExpectedCents) { | ||||||||||||||||||||||||||||
| } else if ( | ||||||||||||||||||||||||||||
| res.amountReceivedCents > 0 && | ||||||||||||||||||||||||||||
| res.amountReceivedCents >= res.amountExpectedCents | ||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||
| setStatus("confirming"); | ||||||||||||||||||||||||||||
| setStep("confirming"); | ||||||||||||||||||||||||||||
| } else if (res.amountReceivedCents > 0) { | ||||||||||||||||||||||||||||
|
Comment on lines
+52
to
58
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.
Once the full amount is received but not yet credited, the condition
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/components/billing/crypto-checkout.tsx
Line: 52-58
Comment:
**Redundant `setStep("confirming")` on every poll**
Once the full amount is received but not yet credited, the condition `amountReceivedCents >= amountExpectedCents` remains true on every subsequent poll tick. This causes `setStep("confirming")` and `setStatus("confirming")` to be called redundantly on every 5-second interval, generating unnecessary re-renders.
```suggestion
} else if (
res.amountReceivedCents > 0 &&
res.amountReceivedCents >= res.amountExpectedCents
) {
setStatus((prev) => (prev !== "confirming" ? "confirming" : prev));
setStep((prev) => (prev !== "confirming" ? "confirming" : prev));
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||||||
|
|
@@ -93,7 +98,11 @@ export function CryptoCheckout() { | |||||||||||||||||||||||||||
| if (methods.length === 0) return null; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||
| <motion.div initial={{ opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} transition={{ duration: 0.3 }}> | ||||||||||||||||||||||||||||
| <motion.div | ||||||||||||||||||||||||||||
| initial={{ opacity: 0, y: 8 }} | ||||||||||||||||||||||||||||
| animate={{ opacity: 1, y: 0 }} | ||||||||||||||||||||||||||||
| transition={{ duration: 0.3 }} | ||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| <Card> | ||||||||||||||||||||||||||||
| <CardHeader> | ||||||||||||||||||||||||||||
| <CardTitle className="flex items-center gap-2"> | ||||||||||||||||||||||||||||
|
|
@@ -122,12 +131,13 @@ export function CryptoCheckout() { | |||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| <PaymentMethodPicker | ||||||||||||||||||||||||||||
| methods={methods} | ||||||||||||||||||||||||||||
| amountUsd={amountUsd} | ||||||||||||||||||||||||||||
| onSelect={handleMethod} | ||||||||||||||||||||||||||||
| onBack={() => setStep("amount")} | ||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||
| {loading && ( | ||||||||||||||||||||||||||||
| <p className="mt-2 text-xs text-muted-foreground animate-pulse">Creating checkout...</p> | ||||||||||||||||||||||||||||
| <p className="mt-2 text-xs text-muted-foreground animate-pulse"> | ||||||||||||||||||||||||||||
| Creating checkout... | ||||||||||||||||||||||||||||
| </p> | ||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||
| </motion.div> | ||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||
|
|
@@ -155,7 +165,11 @@ export function CryptoCheckout() { | |||||||||||||||||||||||||||
| credited={status === "credited"} | ||||||||||||||||||||||||||||
| /> | ||||||||||||||||||||||||||||
| {status === "credited" && ( | ||||||||||||||||||||||||||||
| <button type="button" onClick={handleReset} className="mt-4 text-sm text-primary hover:underline"> | ||||||||||||||||||||||||||||
| <button | ||||||||||||||||||||||||||||
| type="button" | ||||||||||||||||||||||||||||
| onClick={handleReset} | ||||||||||||||||||||||||||||
| className="mt-4 text-sm text-primary hover:underline" | ||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||
| Done — buy more credits | ||||||||||||||||||||||||||||
| </button> | ||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
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.
issue (bug_risk): Swallowing errors in the payment methods fetch makes debugging and UX issues harder to detect.
This empty catch means network or backend failures when loading payment methods are ignored, potentially resulting in an empty UI (
methods.length === 0) with no signal of the underlying issue. Please at least log the error (e.g., Sentry/console) or show a simple fallback state so production issues are detectable.