From 0655692c9eaad12b35d46af5df00a5276ca6bd43 Mon Sep 17 00:00:00 2001 From: Yves Gugger Date: Thu, 11 Dec 2025 22:37:39 +0100 Subject: [PATCH] fix(market): live time calculation + cleanup dead /intelligence redirect - Calculate time_remaining live from end_time ISO string (UTC) instead of using static backend string. This ensures time is always accurate even if page stays open for hours. - Remove /intelligence redirect page (was only a redirect to /tld-pricing) - Add getSecondsUntilEnd() and calcTimeRemaining() helpers --- frontend/src/app/intelligence/page.tsx | 26 -------------- frontend/src/app/terminal/market/page.tsx | 41 ++++++++++++++++++++--- 2 files changed, 37 insertions(+), 30 deletions(-) delete mode 100644 frontend/src/app/intelligence/page.tsx diff --git a/frontend/src/app/intelligence/page.tsx b/frontend/src/app/intelligence/page.tsx deleted file mode 100644 index 88cf19b..0000000 --- a/frontend/src/app/intelligence/page.tsx +++ /dev/null @@ -1,26 +0,0 @@ -'use client' - -import { useEffect } from 'react' -import { useRouter } from 'next/navigation' - -/** - * Redirect /intelligence to /tld-pricing - * This page is kept for backwards compatibility - */ -export default function IntelligenceRedirect() { - const router = useRouter() - - useEffect(() => { - router.replace('/tld-pricing') - }, [router]) - - return ( -
-
-
-

Redirecting to TLD Pricing...

-
-
- ) -} - diff --git a/frontend/src/app/terminal/market/page.tsx b/frontend/src/app/terminal/market/page.tsx index 3bfbf4e..8ad547c 100644 --- a/frontend/src/app/terminal/market/page.tsx +++ b/frontend/src/app/terminal/market/page.tsx @@ -84,6 +84,38 @@ function parseTimeToSeconds(timeStr?: string): number { return seconds || Infinity } +/** + * Calculate time remaining from end_time ISO string (UTC). + * Returns human-readable string like "2h 15m" or "Ended". + */ +function calcTimeRemaining(endTimeIso?: string): string { + if (!endTimeIso) return 'N/A' + const end = new Date(endTimeIso).getTime() + const now = Date.now() + const diff = end - now + + if (diff <= 0) return 'Ended' + + const seconds = Math.floor(diff / 1000) + const days = Math.floor(seconds / 86400) + const hours = Math.floor((seconds % 86400) / 3600) + const mins = Math.floor((seconds % 3600) / 60) + + if (days > 0) return `${days}d ${hours}h` + if (hours > 0) return `${hours}h ${mins}m` + if (mins > 0) return `${mins}m` + return '< 1m' +} + +/** + * Get seconds until end from ISO string (for sorting/urgency). + */ +function getSecondsUntilEnd(endTimeIso?: string): number { + if (!endTimeIso) return Infinity + const diff = new Date(endTimeIso).getTime() - Date.now() + return diff > 0 ? diff / 1000 : -1 +} + function formatPrice(price: number, currency = 'USD'): string { return new Intl.NumberFormat('en-US', { style: 'currency', @@ -396,7 +428,7 @@ export default function MarketPage() { case 'domain': return mult * a.domain.localeCompare(b.domain) case 'score': return mult * (a.pounce_score - b.pounce_score) case 'price': return mult * (a.price - b.price) - case 'time': return mult * (parseTimeToSeconds(a.time_remaining) - parseTimeToSeconds(b.time_remaining)) + case 'time': return mult * (getSecondsUntilEnd(a.end_time) - getSecondsUntilEnd(b.end_time)) case 'source': return mult * a.source.localeCompare(b.source) default: return 0 } @@ -584,9 +616,10 @@ export default function MarketPage() { ) : (
{filteredItems.map((item) => { - const timeLeftSec = parseTimeToSeconds(item.time_remaining) - const isUrgent = timeLeftSec < 3600 + const timeLeftSec = getSecondsUntilEnd(item.end_time) + const isUrgent = timeLeftSec > 0 && timeLeftSec < 3600 const isPounce = item.is_pounce + const displayTime = item.status === 'auction' ? calcTimeRemaining(item.end_time) : null return (
- {item.time_remaining || 'N/A'} + {displayTime || 'N/A'}
)}