Spaces:
Running

File size: 3,071 Bytes
c0016d7
ae22a48
4c0d5d3
 
 
8dce17f
 
 
4c0d5d3
 
 
 
c0016d7
 
ae22a48
c0016d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae22a48
 
 
 
 
 
 
 
c0016d7
 
ae22a48
 
c0016d7
ae22a48
 
 
c0016d7
ae22a48
 
4c0d5d3
ae22a48
 
c0016d7
ae22a48
 
4c0d5d3
ae22a48
 
 
 
c0016d7
ae22a48
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { AreaChart, Area, XAxis, YAxis, Tooltip, ResponsiveContainer } from 'recharts'

export default function MarketChart({ data, symbol }) {
  if (!data || data.length === 0) {
    return (
      <div className="card h-80 p-4 flex items-center justify-center flex-col space-y-2">
        <div className="text-danger text-sm font-medium">Waiting for valid data stream...</div>
        <div className="text-dark-500 text-xs">Ensure connection is active</div>
      </div>
    )
  }

  const isUp = data[data.length-1].price >= data[0].price

  return (
    <div className="card h-80 p-6 flex flex-col relative">
      <div className="absolute top-6 right-6 flex items-center space-x-2">
        <span className="w-2 h-2 rounded-full bg-success animate-pulse"></span>
        <span className="text-xs font-medium text-success">Live Market</span>
      </div>
      
      <div className="mb-6">
        <h3 className="text-sm font-medium text-dark-400 uppercase tracking-wider">{symbol} Price Action</h3>
        <div className="flex items-baseline space-x-2 mt-1">
          <span className="text-2xl font-bold text-white">
            ${data[data.length-1].price.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}
          </span>
          <span className={`text-sm font-medium ${isUp ? 'text-success' : 'text-danger'}`}>
            {isUp ? '+' : ''}{((data[data.length-1].price - data[0].price) / data[0].price * 100).toFixed(2)}%
          </span>
        </div>
      </div>
      
      <div className="flex-1 w-full min-h-0">
        <ResponsiveContainer width="100%" height="100%">
          <AreaChart data={data}>
            <defs>
              <linearGradient id="colorPrice" x1="0" y1="0" x2="0" y2="1">
                <stop offset="5%" stopColor={isUp ? "#10b981" : "#ef4444"} stopOpacity={0.3}/>
                <stop offset="95%" stopColor={isUp ? "#10b981" : "#ef4444"} stopOpacity={0}/>
              </linearGradient>
            </defs>
            <XAxis dataKey="time" hide={true} />
            <YAxis 
              domain={['auto', 'auto']} 
              orientation="right"
              tick={{fontSize: 10, fill: '#64748b'}}
              axisLine={false}
              tickLine={false}
              tickFormatter={(value) => `$${value.toLocaleString()}`}
            />
            <Tooltip 
              contentStyle={{ backgroundColor: '#0f172a', border: '1px solid #334155', borderRadius: '8px', boxShadow: '0 4px 6px -1px rgba(0, 0, 0, 0.1)' }}
              itemStyle={{ color: '#fff' }}
              labelStyle={{ display: 'none' }}
              formatter={(value) => [`$${value.toLocaleString()}`, 'Price']}
            />
            <Area 
              type="monotone" 
              dataKey="price" 
              stroke={isUp ? "#10b981" : "#ef4444"} 
              strokeWidth={2}
              fillOpacity={1} 
              fill="url(#colorPrice)" 
              isAnimationActive={false}
            />
          </AreaChart>
        </ResponsiveContainer>
      </div>
    </div>
  )
}