Update exchange form error handling to show link to existing trade
This commit is contained in:
parent
a499019294
commit
cdda5ec2d5
1 changed files with 36 additions and 2 deletions
|
|
@ -68,6 +68,7 @@ export default function ExchangePage() {
|
||||||
|
|
||||||
// UI state
|
// UI state
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
const [existingTradeId, setExistingTradeId] = useState<number | null>(null);
|
||||||
const [isBooking, setIsBooking] = useState(false);
|
const [isBooking, setIsBooking] = useState(false);
|
||||||
|
|
||||||
// Compute dates
|
// Compute dates
|
||||||
|
|
@ -266,7 +267,17 @@ export default function ExchangePage() {
|
||||||
// Redirect to trades page after successful booking
|
// Redirect to trades page after successful booking
|
||||||
router.push("/trades");
|
router.push("/trades");
|
||||||
} catch (err) {
|
} 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);
|
setIsBooking(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -297,7 +308,18 @@ export default function ExchangePage() {
|
||||||
<h1 style={typographyStyles.pageTitle}>Exchange Bitcoin</h1>
|
<h1 style={typographyStyles.pageTitle}>Exchange Bitcoin</h1>
|
||||||
<p style={typographyStyles.pageSubtitle}>Buy or sell Bitcoin with a 5% premium</p>
|
<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 */}
|
{/* Price Display */}
|
||||||
<div style={styles.priceCard}>
|
<div style={styles.priceCard}>
|
||||||
|
|
@ -998,6 +1020,18 @@ const styles: Record<string, CSSProperties> = {
|
||||||
borderRadius: "6px",
|
borderRadius: "6px",
|
||||||
border: "1px solid rgba(251, 146, 60, 0.2)",
|
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: {
|
section: {
|
||||||
marginBottom: "2rem",
|
marginBottom: "2rem",
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue