refactor: extract shared trade card styles to shared.ts
Move duplicate style definitions from trades/page.tsx and admin/trades/page.tsx to a new tradeCardStyles export in shared.ts. Both pages now import and use these shared styles, keeping only page-specific styles locally. This improves maintainability and ensures visual consistency.
This commit is contained in:
parent
2efbd2c665
commit
c9c36971d8
3 changed files with 166 additions and 210 deletions
|
|
@ -16,6 +16,7 @@ import {
|
|||
bannerStyles,
|
||||
badgeStyles,
|
||||
buttonStyles,
|
||||
tradeCardStyles,
|
||||
} from "../styles/shared";
|
||||
|
||||
type ExchangeResponse = components["schemas"]["ExchangeResponse"];
|
||||
|
|
@ -94,9 +95,9 @@ export default function TradesPage() {
|
|||
{error && <div style={bannerStyles.errorBanner}>{error}</div>}
|
||||
|
||||
{isLoadingTrades ? (
|
||||
<div style={styles.emptyState}>Loading trades...</div>
|
||||
<div style={tradeCardStyles.emptyState}>Loading trades...</div>
|
||||
) : trades.length === 0 ? (
|
||||
<div style={styles.emptyState}>
|
||||
<div style={tradeCardStyles.emptyState}>
|
||||
<p>You don't have any trades yet.</p>
|
||||
<a href="/exchange" style={styles.emptyStateLink}>
|
||||
Start trading
|
||||
|
|
@ -108,19 +109,21 @@ export default function TradesPage() {
|
|||
{upcomingTrades.length > 0 && (
|
||||
<div style={styles.section}>
|
||||
<h2 style={styles.sectionTitle}>Upcoming ({upcomingTrades.length})</h2>
|
||||
<div style={styles.tradeList}>
|
||||
<div style={tradeCardStyles.tradeList}>
|
||||
{upcomingTrades.map((trade) => {
|
||||
const status = getTradeStatusDisplay(trade.status);
|
||||
const isBuy = trade.direction === "buy";
|
||||
return (
|
||||
<div key={trade.id} style={styles.tradeCard}>
|
||||
<div style={styles.tradeHeader}>
|
||||
<div style={styles.tradeInfo}>
|
||||
<div style={styles.tradeTime}>{formatDateTime(trade.slot_start)}</div>
|
||||
<div style={styles.tradeDetails}>
|
||||
<div key={trade.id} style={tradeCardStyles.tradeCard}>
|
||||
<div style={tradeCardStyles.tradeHeader}>
|
||||
<div style={tradeCardStyles.tradeInfo}>
|
||||
<div style={tradeCardStyles.tradeTime}>
|
||||
{formatDateTime(trade.slot_start)}
|
||||
</div>
|
||||
<div style={tradeCardStyles.tradeDetails}>
|
||||
<span
|
||||
style={{
|
||||
...styles.directionBadge,
|
||||
...tradeCardStyles.directionBadge,
|
||||
background: isBuy
|
||||
? "rgba(74, 222, 128, 0.15)"
|
||||
: "rgba(248, 113, 113, 0.15)",
|
||||
|
|
@ -129,15 +132,17 @@ export default function TradesPage() {
|
|||
>
|
||||
{isBuy ? "BUY" : "SELL"}
|
||||
</span>
|
||||
<span style={styles.amount}>{formatEur(trade.eur_amount)}</span>
|
||||
<span style={styles.arrow}>↔</span>
|
||||
<span style={styles.satsAmount}>
|
||||
<span style={tradeCardStyles.amount}>
|
||||
{formatEur(trade.eur_amount)}
|
||||
</span>
|
||||
<span style={tradeCardStyles.arrow}>↔</span>
|
||||
<span style={tradeCardStyles.satsAmount}>
|
||||
<SatsDisplay sats={trade.sats_amount} />
|
||||
</span>
|
||||
</div>
|
||||
<div style={styles.rateRow}>
|
||||
<span style={styles.rateLabel}>Rate:</span>
|
||||
<span style={styles.rateValue}>
|
||||
<div style={tradeCardStyles.rateRow}>
|
||||
<span style={tradeCardStyles.rateLabel}>Rate:</span>
|
||||
<span style={tradeCardStyles.rateValue}>
|
||||
€
|
||||
{trade.agreed_price_eur.toLocaleString("de-DE", {
|
||||
maximumFractionDigits: 0,
|
||||
|
|
@ -158,7 +163,7 @@ export default function TradesPage() {
|
|||
</div>
|
||||
|
||||
{trade.status === "booked" && (
|
||||
<div style={styles.buttonGroup}>
|
||||
<div style={tradeCardStyles.buttonGroup}>
|
||||
{confirmCancelId === trade.id ? (
|
||||
<>
|
||||
<button
|
||||
|
|
@ -199,17 +204,22 @@ export default function TradesPage() {
|
|||
<h2 style={typographyStyles.sectionTitleMuted}>
|
||||
History ({pastOrFinalTrades.length})
|
||||
</h2>
|
||||
<div style={styles.tradeList}>
|
||||
<div style={tradeCardStyles.tradeList}>
|
||||
{pastOrFinalTrades.map((trade) => {
|
||||
const status = getTradeStatusDisplay(trade.status);
|
||||
const isBuy = trade.direction === "buy";
|
||||
return (
|
||||
<div key={trade.id} style={{ ...styles.tradeCard, ...styles.tradeCardPast }}>
|
||||
<div style={styles.tradeTime}>{formatDateTime(trade.slot_start)}</div>
|
||||
<div style={styles.tradeDetails}>
|
||||
<div
|
||||
key={trade.id}
|
||||
style={{ ...tradeCardStyles.tradeCard, ...styles.tradeCardPast }}
|
||||
>
|
||||
<div style={tradeCardStyles.tradeTime}>
|
||||
{formatDateTime(trade.slot_start)}
|
||||
</div>
|
||||
<div style={tradeCardStyles.tradeDetails}>
|
||||
<span
|
||||
style={{
|
||||
...styles.directionBadge,
|
||||
...tradeCardStyles.directionBadge,
|
||||
background: isBuy
|
||||
? "rgba(74, 222, 128, 0.1)"
|
||||
: "rgba(248, 113, 113, 0.1)",
|
||||
|
|
@ -218,9 +228,9 @@ export default function TradesPage() {
|
|||
>
|
||||
{isBuy ? "BUY" : "SELL"}
|
||||
</span>
|
||||
<span style={styles.amount}>{formatEur(trade.eur_amount)}</span>
|
||||
<span style={styles.arrow}>↔</span>
|
||||
<span style={styles.satsAmount}>
|
||||
<span style={tradeCardStyles.amount}>{formatEur(trade.eur_amount)}</span>
|
||||
<span style={tradeCardStyles.arrow}>↔</span>
|
||||
<span style={tradeCardStyles.satsAmount}>
|
||||
<SatsDisplay sats={trade.sats_amount} />
|
||||
</span>
|
||||
</div>
|
||||
|
|
@ -247,7 +257,7 @@ export default function TradesPage() {
|
|||
);
|
||||
}
|
||||
|
||||
// Page-specific styles
|
||||
// Page-specific styles (trade card styles are shared via tradeCardStyles)
|
||||
const styles: Record<string, React.CSSProperties> = {
|
||||
content: {
|
||||
flex: 1,
|
||||
|
|
@ -266,89 +276,10 @@ const styles: Record<string, React.CSSProperties> = {
|
|||
color: "#fff",
|
||||
marginBottom: "1rem",
|
||||
},
|
||||
tradeList: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "0.75rem",
|
||||
},
|
||||
tradeCard: {
|
||||
background: "rgba(255, 255, 255, 0.03)",
|
||||
border: "1px solid rgba(255, 255, 255, 0.08)",
|
||||
borderRadius: "12px",
|
||||
padding: "1.25rem",
|
||||
transition: "all 0.2s",
|
||||
},
|
||||
tradeCardPast: {
|
||||
opacity: 0.6,
|
||||
background: "rgba(255, 255, 255, 0.01)",
|
||||
},
|
||||
tradeHeader: {
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "flex-start",
|
||||
gap: "1rem",
|
||||
},
|
||||
tradeInfo: {
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "0.25rem",
|
||||
},
|
||||
tradeTime: {
|
||||
fontFamily: "'DM Sans', system-ui, sans-serif",
|
||||
fontSize: "1rem",
|
||||
fontWeight: 500,
|
||||
color: "#fff",
|
||||
marginBottom: "0.5rem",
|
||||
},
|
||||
tradeDetails: {
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "0.5rem",
|
||||
flexWrap: "wrap",
|
||||
},
|
||||
directionBadge: {
|
||||
fontFamily: "'DM Sans', system-ui, sans-serif",
|
||||
fontSize: "0.7rem",
|
||||
fontWeight: 600,
|
||||
padding: "0.2rem 0.5rem",
|
||||
borderRadius: "4px",
|
||||
textTransform: "uppercase",
|
||||
},
|
||||
amount: {
|
||||
fontFamily: "'DM Mono', monospace",
|
||||
fontSize: "0.95rem",
|
||||
color: "#fff",
|
||||
fontWeight: 500,
|
||||
},
|
||||
arrow: {
|
||||
color: "rgba(255, 255, 255, 0.3)",
|
||||
fontSize: "0.8rem",
|
||||
},
|
||||
satsAmount: {
|
||||
fontFamily: "'DM Mono', monospace",
|
||||
fontSize: "0.9rem",
|
||||
color: "#f7931a", // Bitcoin orange
|
||||
},
|
||||
rateRow: {
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "0.5rem",
|
||||
marginTop: "0.25rem",
|
||||
},
|
||||
rateLabel: {
|
||||
fontFamily: "'DM Sans', system-ui, sans-serif",
|
||||
fontSize: "0.75rem",
|
||||
color: "rgba(255, 255, 255, 0.4)",
|
||||
},
|
||||
rateValue: {
|
||||
fontFamily: "'DM Mono', monospace",
|
||||
fontSize: "0.8rem",
|
||||
color: "rgba(255, 255, 255, 0.7)",
|
||||
},
|
||||
buttonGroup: {
|
||||
display: "flex",
|
||||
gap: "0.5rem",
|
||||
},
|
||||
confirmButton: {
|
||||
fontFamily: "'DM Sans', system-ui, sans-serif",
|
||||
padding: "0.35rem 0.75rem",
|
||||
|
|
@ -360,12 +291,6 @@ const styles: Record<string, React.CSSProperties> = {
|
|||
cursor: "pointer",
|
||||
transition: "all 0.2s",
|
||||
},
|
||||
emptyState: {
|
||||
fontFamily: "'DM Sans', system-ui, sans-serif",
|
||||
color: "rgba(255, 255, 255, 0.4)",
|
||||
textAlign: "center",
|
||||
padding: "3rem",
|
||||
},
|
||||
emptyStateLink: {
|
||||
color: "#a78bfa",
|
||||
textDecoration: "none",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue