"use client"; import { CSSProperties } from "react"; import { components } from "../../generated/api"; import { useTranslation } from "../../hooks/useTranslation"; type ExchangePriceResponse = components["schemas"]["ExchangePriceResponse"]; interface PriceDisplayProps { priceData: ExchangePriceResponse | null; isLoading: boolean; error: string | null; lastUpdate: Date | null; direction: "buy" | "sell"; agreedPrice: number; premiumPercent: number; } /** * Format price for display */ function formatPrice(price: number): string { return `€${price.toLocaleString("es-ES", { maximumFractionDigits: 0 })}`; } const styles: Record = { priceCard: { background: "rgba(255, 255, 255, 0.03)", border: "1px solid rgba(255, 255, 255, 0.08)", borderRadius: "12px", padding: "1rem 1.5rem", marginBottom: "1.5rem", }, priceRow: { display: "flex", alignItems: "center", gap: "0.75rem", flexWrap: "wrap", }, priceLabel: { fontFamily: "'DM Sans', system-ui, sans-serif", color: "rgba(255, 255, 255, 0.5)", fontSize: "0.9rem", }, priceValue: { fontFamily: "'DM Mono', monospace", color: "#fff", fontSize: "1.1rem", fontWeight: 500, }, priceDivider: { color: "rgba(255, 255, 255, 0.2)", margin: "0 0.25rem", }, premiumBadge: { fontFamily: "'DM Sans', system-ui, sans-serif", fontSize: "0.75rem", fontWeight: 600, padding: "0.2rem 0.5rem", borderRadius: "4px", marginLeft: "0.25rem", background: "rgba(255, 255, 255, 0.1)", color: "rgba(255, 255, 255, 0.7)", }, priceTimestamp: { fontFamily: "'DM Sans', system-ui, sans-serif", fontSize: "0.75rem", color: "rgba(255, 255, 255, 0.4)", marginTop: "0.5rem", }, staleWarning: { color: "#f87171", fontWeight: 600, }, priceLoading: { fontFamily: "'DM Sans', system-ui, sans-serif", color: "rgba(255, 255, 255, 0.5)", textAlign: "center" as const, }, priceError: { fontFamily: "'DM Sans', system-ui, sans-serif", color: "#f87171", textAlign: "center" as const, }, }; /** * Component that displays exchange price information. * Shows market price, agreed price, premium percentage, and last update time. */ export function PriceDisplay({ priceData, isLoading, error, lastUpdate, direction, agreedPrice, premiumPercent, }: PriceDisplayProps) { const t = useTranslation("exchange"); const marketPrice = priceData?.price?.market_price ?? 0; const isPriceStale = priceData?.price?.is_stale ?? false; return (
{isLoading && !priceData ? (
{t("priceDisplay.loading")}
) : error && !priceData?.price ? (
{error}
) : ( <>
{t("priceDisplay.market")} {formatPrice(marketPrice)} {t("priceDisplay.ourPrice")} {formatPrice(agreedPrice)} {direction === "buy" ? "+" : "-"} {premiumPercent}%
{lastUpdate && (
{t("priceDisplay.updated")} {lastUpdate.toLocaleTimeString("es-ES")} {isPriceStale && {t("priceDisplay.stale")}}
)} )}
); }