forked from StellarSend/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickStats.tsx
More file actions
96 lines (89 loc) · 2.79 KB
/
Copy pathQuickStats.tsx
File metadata and controls
96 lines (89 loc) · 2.79 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
import React from 'react'
import { TrendingUp, ArrowUpRight, Activity, Zap } from 'lucide-react'
import { Card } from '@/components/ui/Card'
import { Skeleton } from '@/components/ui/Spinner'
import { formatAmount } from '@/lib/stellar'
import { useRecentTransactions } from '@/hooks/useTransactions'
export function QuickStats() {
const { data, isLoading } = useRecentTransactions(50)
const transactions = data?.transactions ?? []
const sent = transactions.filter((t) => t.direction === 'sent')
const received = transactions.filter((t) => t.direction === 'received')
const totalSent = sent
.reduce((sum, t) => sum + parseFloat(t.amount || '0'), 0)
.toFixed(4)
const totalReceived = received
.reduce((sum, t) => sum + parseFloat(t.amount || '0'), 0)
.toFixed(4)
const avgFee = transactions.length
? (
transactions.reduce((s, t) => s + parseFloat(t.fee || '0'), 0) /
transactions.length /
10_000_000
).toFixed(7)
: '0'
const stats = [
{
label: 'Total Sent',
value: formatAmount(totalSent, 4),
unit: 'XLM',
icon: <ArrowUpRight size={18} />,
color: 'text-danger-400',
bg: 'bg-danger-500/10 border-danger-500/20',
},
{
label: 'Total Received',
value: formatAmount(totalReceived, 4),
unit: 'XLM',
icon: <TrendingUp size={18} />,
color: 'text-success-400',
bg: 'bg-success-500/10 border-success-500/20',
},
{
label: 'Transactions',
value: String(transactions.length),
unit: 'total',
icon: <Activity size={18} />,
color: 'text-stellar-400',
bg: 'bg-stellar-500/10 border-stellar-500/20',
},
{
label: 'Average Fee',
value: avgFee,
unit: 'XLM',
icon: <Zap size={18} />,
color: 'text-warning-400',
bg: 'bg-warning-500/10 border-warning-500/20',
},
]
return (
<div className="grid grid-cols-2 lg:grid-cols-4 gap-4">
{stats.map((stat) => (
<Card key={stat.label} padding="sm">
<div className="flex items-start justify-between mb-3">
<div
className={`w-9 h-9 rounded-xl border flex items-center justify-center ${stat.bg} ${stat.color}`}
>
{stat.icon}
</div>
</div>
{isLoading ? (
<>
<Skeleton className="h-6 w-24 mb-1" />
<Skeleton className="h-3 w-16" />
</>
) : (
<>
<p className={`text-xl font-bold tabular-nums ${stat.color}`}>
{stat.value}
</p>
<p className="text-xs text-slate-500 mt-0.5">
{stat.label} <span className="text-slate-600">({stat.unit})</span>
</p>
</>
)}
</Card>
))}
</div>
)
}