Update exchange form error handling to show link to existing trade

This commit is contained in:
counterweight 2025-12-23 15:53:27 +01:00
parent a499019294
commit cdda5ec2d5
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -68,6 +68,7 @@ export default function ExchangePage() {
// UI state
const [error, setError] = useState<string | null>(null);
const [existingTradeId, setExistingTradeId] = useState<number | null>(null);
const [isBooking, setIsBooking] = useState(false);
// Compute dates
@ -266,7 +267,17 @@ export default function ExchangePage() {
// Redirect to trades page after successful booking
router.push("/trades");
} catch (err) {
setError(err instanceof Error ? err.message : "Failed to book trade");
const errorMessage = err instanceof Error ? err.message : "Failed to book trade";
setError(errorMessage);
// Check if it's a "same day" error and extract trade ID
const tradeIdMatch = errorMessage.match(/Trade ID: (\d+)/);
if (tradeIdMatch) {
setExistingTradeId(parseInt(tradeIdMatch[1], 10));
} else {
setExistingTradeId(null);
}
setIsBooking(false);
}
};
@ -297,7 +308,18 @@ export default function ExchangePage() {
<h1 style={typographyStyles.pageTitle}>Exchange Bitcoin</h1>
<p style={typographyStyles.pageSubtitle}>Buy or sell Bitcoin with a 5% premium</p>
{error && <div style={bannerStyles.errorBanner}>{error}</div>}
{error && (
<div style={bannerStyles.errorBanner}>
{error}
{existingTradeId && (
<div style={styles.errorLink}>
<a href={`/trades/${existingTradeId}`} style={styles.errorLinkAnchor}>
View your existing trade
</a>
</div>
)}
</div>
)}
{/* Price Display */}
<div style={styles.priceCard}>
@ -998,6 +1020,18 @@ const styles: Record<string, CSSProperties> = {
borderRadius: "6px",
border: "1px solid rgba(251, 146, 60, 0.2)",
},
errorLink: {
marginTop: "0.75rem",
paddingTop: "0.75rem",
borderTop: "1px solid rgba(255, 255, 255, 0.1)",
},
errorLinkAnchor: {
fontFamily: "'DM Sans', system-ui, sans-serif",
color: "#a78bfa",
textDecoration: "none",
fontWeight: 500,
fontSize: "0.9rem",
},
section: {
marginBottom: "2rem",
},