feat: add zombie warning for auto-liquidation risk based on inactivity
This commit is contained in:
@@ -6,10 +6,13 @@ import { formatCurrency, formatNumber } from '@/lib/utils'
|
||||
import { PriceChart } from '@/components/PriceChart'
|
||||
import { TradePanel } from './TradePanel'
|
||||
import { ResearchPanel } from './ResearchPanel'
|
||||
import { Hash, Clock, Link as LinkIcon } from 'lucide-react'
|
||||
import { Hash, Clock, Link as LinkIcon, AlertTriangle } from 'lucide-react'
|
||||
import { formatDistanceToNow } from 'date-fns'
|
||||
import Link from 'next/link'
|
||||
|
||||
const ZOMBIE_ZERO_COUNT = parseInt(process.env.ZOMBIE_ZERO_COUNT ?? '1000', 10)
|
||||
const PRICE_UPDATE_INTERVAL_MINUTES = parseInt(process.env.PRICE_UPDATE_INTERVAL_MINUTES ?? '60', 10)
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
interface Props {
|
||||
@@ -150,6 +153,30 @@ export default async function HashtagPage({ params, searchParams }: Props) {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Zombie warning — only shown when signed in, holding a position, and threshold reached */}
|
||||
{session && (activeLong || activeShort) && hashtag.zeroCount >= ZOMBIE_ZERO_COUNT * 0.9 && (() => {
|
||||
const zombieSince = formatDistanceToNow(
|
||||
new Date(Date.now() - hashtag.zeroCount * PRICE_UPDATE_INTERVAL_MINUTES * 60 * 1000),
|
||||
)
|
||||
const zombieEta = formatDistanceToNow(
|
||||
new Date(Date.now() + (ZOMBIE_ZERO_COUNT - hashtag.zeroCount) * PRICE_UPDATE_INTERVAL_MINUTES * 60 * 1000),
|
||||
{ addSuffix: true },
|
||||
)
|
||||
return (
|
||||
<div className="bg-amber-500/5 border border-amber-500/25 rounded-xl p-4 flex items-start gap-3">
|
||||
<AlertTriangle className="h-5 w-5 text-amber-400 shrink-0 mt-0.5" />
|
||||
<div>
|
||||
<p className="text-sm font-medium text-amber-400">Auto-liquidation risk</p>
|
||||
<p className="text-sm text-slate-400 mt-0.5">
|
||||
No activity detected for <span className="text-slate-200">{zombieSince}</span>.
|
||||
If this continues, your position will be force-closed{' '}
|
||||
<span className="text-slate-200">{zombieEta}</span>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})()}
|
||||
|
||||
{/* Trade panel or sign-in prompt */}
|
||||
{session ? (
|
||||
<TradePanel
|
||||
|
||||
Reference in New Issue
Block a user