forked from StellarSend/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDashboard.tsx
More file actions
222 lines (205 loc) · 7.48 KB
/
Copy pathDashboard.tsx
File metadata and controls
222 lines (205 loc) · 7.48 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import React from 'react'
import { Link } from 'react-router-dom'
import { Send, History, Settings, ArrowRight } from 'lucide-react'
import { Button } from '@/components/ui/Button'
import { Card } from '@/components/ui/Card'
import { BalanceCard } from '@/components/dashboard/BalanceCard'
import { QuickStats } from '@/components/dashboard/QuickStats'
import { RecentTransactions } from '@/components/dashboard/RecentTransactions'
import { ConnectWalletScreen } from '@/components/wallet/ConnectWallet'
import { useWallet } from '@/hooks/useWallet'
import {
AreaChart,
Area,
XAxis,
YAxis,
CartesianGrid,
Tooltip,
ResponsiveContainer,
} from 'recharts'
import { useRecentTransactions } from '@/hooks/useTransactions'
// ─── Activity chart ───────────────────────────────────────────────────────────
function ActivityChart() {
const { data } = useRecentTransactions(50)
const transactions = data?.transactions ?? []
// Group by day (last 7 days)
const days: Record<string, { sent: number; received: number }> = {}
const now = Date.now()
for (let i = 6; i >= 0; i--) {
const d = new Date(now - i * 86_400_000)
const key = d.toLocaleDateString('en-US', { month: 'short', day: 'numeric' })
days[key] = { sent: 0, received: 0 }
}
transactions.forEach((tx) => {
const key = new Date(tx.createdAt).toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
})
if (days[key]) {
if (tx.direction === 'sent') days[key].sent += parseFloat(tx.amount || '0')
else days[key].received += parseFloat(tx.amount || '0')
}
})
const chartData = Object.entries(days).map(([date, vals]) => ({
date,
sent: parseFloat(vals.sent.toFixed(4)),
received: parseFloat(vals.received.toFixed(4)),
}))
return (
<Card>
<div className="flex items-center justify-between mb-4">
<div>
<h3 className="text-sm font-semibold text-white">Activity (7 days)</h3>
<p className="text-xs text-slate-500 mt-0.5">XLM sent and received</p>
</div>
<div className="flex items-center gap-4 text-xs">
<div className="flex items-center gap-1.5">
<span className="w-2.5 h-2.5 rounded-full bg-danger-400 inline-block" />
<span className="text-slate-400">Sent</span>
</div>
<div className="flex items-center gap-1.5">
<span className="w-2.5 h-2.5 rounded-full bg-success-400 inline-block" />
<span className="text-slate-400">Received</span>
</div>
</div>
</div>
<div className="h-48">
<ResponsiveContainer width="100%" height="100%">
<AreaChart data={chartData} margin={{ top: 4, right: 4, left: -20, bottom: 0 }}>
<defs>
<linearGradient id="colorSent" x1="0" y1="0" x2="0" y2="1">
<stop offset="5%" stopColor="#f87171" stopOpacity={0.3} />
<stop offset="95%" stopColor="#f87171" stopOpacity={0} />
</linearGradient>
<linearGradient id="colorReceived" x1="0" y1="0" x2="0" y2="1">
<stop offset="5%" stopColor="#34d399" stopOpacity={0.3} />
<stop offset="95%" stopColor="#34d399" stopOpacity={0} />
</linearGradient>
</defs>
<CartesianGrid strokeDasharray="3 3" stroke="rgba(255,255,255,0.05)" />
<XAxis
dataKey="date"
tick={{ fontSize: 11, fill: '#64748b' }}
axisLine={false}
tickLine={false}
/>
<YAxis
tick={{ fontSize: 11, fill: '#64748b' }}
axisLine={false}
tickLine={false}
/>
<Tooltip
contentStyle={{
backgroundColor: '#0e1a3a',
border: '1px solid rgba(45,106,255,0.2)',
borderRadius: 12,
color: '#f1f5f9',
fontSize: 12,
}}
cursor={{ stroke: 'rgba(45,106,255,0.3)', strokeWidth: 1 }}
/>
<Area
type="monotone"
dataKey="sent"
stroke="#f87171"
strokeWidth={2}
fill="url(#colorSent)"
dot={false}
/>
<Area
type="monotone"
dataKey="received"
stroke="#34d399"
strokeWidth={2}
fill="url(#colorReceived)"
dot={false}
/>
</AreaChart>
</ResponsiveContainer>
</div>
</Card>
)
}
// ─── Quick actions ────────────────────────────────────────────────────────────
function QuickActions() {
// "Send Money" lives once, in the page header above — not duplicated here.
const actions = [
{ label: 'History', to: '/history', icon: <History size={18} />, color: 'bg-navy-700' },
{ label: 'Settings', to: '/settings', icon: <Settings size={18} />, color: 'bg-navy-700' },
]
return (
<div className="flex gap-3">
{actions.map((a) => (
<Link key={a.to} to={a.to} className="flex-1">
<button
className={`w-full flex flex-col items-center gap-2 p-4 rounded-xl border border-navy-600/40 text-white hover:border-stellar-500/30 transition-all ${a.color} hover:brightness-110`}
>
{a.icon}
<span className="text-xs font-medium">{a.label}</span>
</button>
</Link>
))}
</div>
)
}
// ─── Page ─────────────────────────────────────────────────────────────────────
export default function Dashboard() {
const { isConnected } = useWallet()
if (!isConnected) {
return (
<div className="max-w-md mx-auto mt-8">
<Card>
<ConnectWalletScreen />
</Card>
</div>
)
}
return (
<div className="space-y-6 animate-fade-in">
{/* Page header */}
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold text-white">Dashboard</h1>
<p className="text-sm text-slate-400 mt-0.5">
Overview of your Stellar account
</p>
</div>
<Link to="/send" className="group">
<Button
size="lg"
icon={<Send size={16} />}
iconRight={
<ArrowRight
size={15}
className="transition-transform duration-200 group-hover:translate-x-0.5"
/>
}
className="shadow-lg shadow-stellar-500/20"
>
Send Money
</Button>
</Link>
</div>
{/* Balance + Quick actions */}
<div className="grid grid-cols-1 lg:grid-cols-3 gap-5">
<div className="lg:col-span-2">
<BalanceCard />
</div>
<div className="flex flex-col gap-4">
<QuickActions />
</div>
</div>
{/* Stats */}
<QuickStats />
{/* Activity chart + Recent transactions */}
<div className="grid grid-cols-1 lg:grid-cols-3 gap-5">
<div className="lg:col-span-2">
<ActivityChart />
</div>
<div>
<RecentTransactions />
</div>
</div>
</div>
)
}