|
| 1 | +"use client"; |
| 2 | + |
| 3 | +// Demo mode for the auction card on /base. The live AuctionPanel can be an |
| 4 | +// awkward salesman — a fresh auction reads "0.000 ETH" until the first bid. |
| 5 | +// This panel REPLAYS real settled auctions instead: real Gnars, real final |
| 6 | +// bids, real winners, cycling with a count-up and a crew quip. Everything |
| 7 | +// on-screen happened; the only cosmetic layer is the commentary, and the DEMO |
| 8 | +// chip says exactly what the card is. The footer states the real cumulative |
| 9 | +// auction revenue (same figure the treasury page reports). |
| 10 | +import { useEffect, useMemo, useState } from "react"; |
| 11 | +import { useTranslations } from "next-intl"; |
| 12 | +import { AnimatePresence, motion } from "framer-motion"; |
| 13 | +import { CHARACTERS } from "@/components/stake/CharacterSelector"; |
| 14 | +import { CountUp } from "@/components/ui/count-up"; |
| 15 | +import { Link } from "@/i18n/navigation"; |
| 16 | +import { cn } from "@/lib/utils"; |
| 17 | +import type { PastAuction } from "@/services/auctions"; |
| 18 | + |
| 19 | +const GOLD = "linear-gradient(135deg,#f7c948,#f5851f)"; |
| 20 | +const ROTATE_MS = 6000; |
| 21 | +const QUIPS = ["q1", "q2", "q3", "q4", "q5"] as const; |
| 22 | +// Quip narrators cycle through the same crew that fronts /morpheus. |
| 23 | +const NARRATORS = ["vlad", "r4to", "yan", "pamtech"] as const; |
| 24 | + |
| 25 | +export function AuctionDemoPanel({ |
| 26 | + items, |
| 27 | + totalSalesEth, |
| 28 | +}: { |
| 29 | + items: PastAuction[]; |
| 30 | + totalSalesEth: number; |
| 31 | +}) { |
| 32 | + const t = useTranslations("base.demo"); |
| 33 | + const [index, setIndex] = useState(0); |
| 34 | + |
| 35 | + const usable = useMemo(() => items.filter((a) => a.imageUrl && Number(a.finalBid) > 0), [items]); |
| 36 | + |
| 37 | + useEffect(() => { |
| 38 | + if (usable.length < 2) return; |
| 39 | + const id = setInterval(() => setIndex((i) => (i + 1) % usable.length), ROTATE_MS); |
| 40 | + return () => clearInterval(id); |
| 41 | + }, [usable.length]); |
| 42 | + |
| 43 | + if (usable.length === 0) return null; |
| 44 | + const a = usable[index % usable.length]; |
| 45 | + const narrator = CHARACTERS.find((c) => c.id === NARRATORS[index % NARRATORS.length]); |
| 46 | + |
| 47 | + return ( |
| 48 | + <div className="flex h-full flex-col gap-4 rounded-2xl border border-[#f7c948]/25 bg-card p-5"> |
| 49 | + <div className="flex items-center justify-between gap-3"> |
| 50 | + <span |
| 51 | + className="inline-flex items-center gap-[7px] rounded-full px-3 py-1 text-[11px] font-extrabold uppercase tracking-[0.08em]" |
| 52 | + style={{ backgroundImage: GOLD, color: "#1a1205" }} |
| 53 | + > |
| 54 | + {t("chip")} |
| 55 | + </span> |
| 56 | + </div> |
| 57 | + |
| 58 | + <AnimatePresence mode="wait"> |
| 59 | + <motion.div |
| 60 | + key={a.id} |
| 61 | + initial={{ opacity: 0, x: 24 }} |
| 62 | + animate={{ opacity: 1, x: 0 }} |
| 63 | + exit={{ opacity: 0, x: -24 }} |
| 64 | + transition={{ duration: 0.35 }} |
| 65 | + className="flex flex-1 flex-col gap-4" |
| 66 | + > |
| 67 | + <div className="relative aspect-square w-full overflow-hidden rounded-xl border border-border/60"> |
| 68 | + {a.imageUrl ? ( |
| 69 | + // IPFS gateway art, unknown dimensions; plain img matches PastAuctions. |
| 70 | + // eslint-disable-next-line @next/next/no-img-element |
| 71 | + <img |
| 72 | + src={a.imageUrl} |
| 73 | + alt={t("gnarNo", { id: a.tokenId })} |
| 74 | + className="h-full w-full object-cover" |
| 75 | + /> |
| 76 | + ) : null} |
| 77 | + <span className="absolute left-3 top-3 rounded-full bg-black/70 px-2.5 py-1 font-mono text-xs font-bold text-white"> |
| 78 | + {t("gnarNo", { id: a.tokenId })} |
| 79 | + </span> |
| 80 | + <span |
| 81 | + className="absolute right-3 top-3 rounded-full px-2.5 py-1 text-[11px] font-extrabold uppercase tracking-wider" |
| 82 | + style={{ backgroundImage: GOLD, color: "#1a1205" }} |
| 83 | + > |
| 84 | + {t("sold")} |
| 85 | + </span> |
| 86 | + </div> |
| 87 | + |
| 88 | + <div className="flex items-baseline justify-between gap-3"> |
| 89 | + <span className="font-mono text-2xl font-black tabular-nums"> |
| 90 | + <CountUp value={Number(a.finalBid)} decimals={3} durationMs={900} /> ETH |
| 91 | + </span> |
| 92 | + <span className="truncate text-xs text-muted-foreground"> |
| 93 | + {t("wonBy")}{" "} |
| 94 | + <Link |
| 95 | + href={`/members/${a.winner}`} |
| 96 | + className="font-mono font-semibold text-foreground hover:underline" |
| 97 | + > |
| 98 | + {a.winner.slice(0, 6)}…{a.winner.slice(-4)} |
| 99 | + </Link> |
| 100 | + </span> |
| 101 | + </div> |
| 102 | + |
| 103 | + {narrator ? ( |
| 104 | + <div className="flex items-center gap-2.5"> |
| 105 | + <div |
| 106 | + aria-hidden |
| 107 | + className="h-10 w-10 shrink-0" |
| 108 | + style={{ |
| 109 | + backgroundImage: `url("${narrator.image}")`, |
| 110 | + backgroundSize: narrator.face.size, |
| 111 | + backgroundPosition: narrator.face.pos, |
| 112 | + backgroundRepeat: "no-repeat", |
| 113 | + maskImage: "linear-gradient(to bottom, black 72%, transparent 98%)", |
| 114 | + WebkitMaskImage: "linear-gradient(to bottom, black 72%, transparent 98%)", |
| 115 | + }} |
| 116 | + /> |
| 117 | + <motion.p |
| 118 | + key={`${a.id}-quip`} |
| 119 | + initial={{ opacity: 0, y: 4 }} |
| 120 | + animate={{ opacity: 1, y: 0 }} |
| 121 | + transition={{ delay: 0.4 }} |
| 122 | + className="rounded-2xl border border-border/60 bg-background/40 px-3 py-2 text-xs leading-relaxed text-muted-foreground" |
| 123 | + > |
| 124 | + {t(`quips.${QUIPS[index % QUIPS.length]}`)} |
| 125 | + </motion.p> |
| 126 | + </div> |
| 127 | + ) : null} |
| 128 | + </motion.div> |
| 129 | + </AnimatePresence> |
| 130 | + |
| 131 | + {/* Rotation dots — real state, one per replayed auction. */} |
| 132 | + <div className="flex items-center justify-center gap-1.5"> |
| 133 | + {usable.map((x, i) => ( |
| 134 | + <button |
| 135 | + key={x.id} |
| 136 | + type="button" |
| 137 | + aria-label={t("gnarNo", { id: x.tokenId })} |
| 138 | + onClick={() => setIndex(i)} |
| 139 | + className={cn( |
| 140 | + "h-1.5 rounded-full transition-all", |
| 141 | + i === index % usable.length ? "w-5 bg-foreground/80" : "w-1.5 bg-foreground/25", |
| 142 | + )} |
| 143 | + /> |
| 144 | + ))} |
| 145 | + </div> |
| 146 | + |
| 147 | + <p className="border-t border-border/60 pt-3 text-center text-xs font-semibold"> |
| 148 | + {t("totalRaised", { n: Math.round(totalSalesEth) })} |
| 149 | + </p> |
| 150 | + </div> |
| 151 | + ); |
| 152 | +} |
0 commit comments