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
This commit is contained in:
2025-12-11 22:37:39 +01:00
parent 9febdf8332
commit 0655692c9e
2 changed files with 37 additions and 30 deletions

View File

@ -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 (
<div className="min-h-screen flex items-center justify-center bg-background">
<div className="text-center">
<div className="w-6 h-6 border-2 border-accent border-t-transparent rounded-full animate-spin mx-auto mb-4" />
<p className="text-foreground-muted">Redirecting to TLD Pricing...</p>
</div>
</div>
)
}

View File

@ -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() {
) : (
<div className="divide-y divide-white/5">
{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 (
<div
@ -664,7 +697,7 @@ export default function MarketPage() {
: "text-zinc-400 border-zinc-700 bg-zinc-800/50"
)}>
<Clock className="w-3 h-3" />
{item.time_remaining || 'N/A'}
{displayTime || 'N/A'}
</div>
)}
</div>