forked from SmartDropLabs/smartdrop-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
253 lines (241 loc) · 6.8 KB
/
Copy pathpage.tsx
File metadata and controls
253 lines (241 loc) · 6.8 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
"use client";
import { useEffect } from "react";
import {
Flex,
HStack,
Text,
Spinner,
Box,
Skeleton,
useToast,
Alert,
AlertIcon,
} from "@chakra-ui/react";
import { motion } from "framer-motion";
import { useStellarWallet } from "@/context/StellarWalletContext";
import {
usePlatformStats,
useTotalUserCredits,
} from "@/hooks/useSorobanQuery";
import { sorobanRpcUrl, stellarNetwork } from "@/config";
import OnboardingOverlay from "@/components/OnboardingOverlay/OnboardingOverlay";
const MotionBox = motion.create(Box);
const fadeInUp = {
hidden: { opacity: 0, y: 16 },
visible: (delay = 0) => ({
opacity: 1,
y: 0,
transition: { duration: 0.5, ease: "easeOut", delay },
}),
};
function StatCard({
label,
value,
accent = "app.accent",
delay = 0,
isLoading = false,
}: {
label: string;
value: string | number;
accent?: string;
delay?: number;
isLoading?: boolean;
}) {
return (
<MotionBox
variants={fadeInUp}
initial="hidden"
animate="visible"
custom={delay}
w={["100%", "48%", "23%"]}
position="relative"
overflow="hidden"
border="1px solid"
borderColor="app.border"
borderRadius="card"
p={6}
bg="app.surface"
boxShadow="card"
sx={{ transition: "border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease" }}
_hover={{
borderColor: "app.borderHover",
boxShadow: "cardHover",
transform: "translateY(-2px)",
}}
>
<Box
position="absolute"
top={0}
left={0}
right={0}
h="3px"
bgGradient={`linear(to-r, ${accent}, transparent)`}
/>
<Text color="app.muted" fontSize="sm" mb={2} fontWeight="medium">
{label}
</Text>
<Skeleton isLoaded={!isLoading} startColor="app.border" endColor="app.surfaceHover">
<Text fontSize="3xl" fontWeight="extrabold" color={accent}>
{isLoading ? "—" : value}
</Text>
</Skeleton>
</MotionBox>
);
}
export default function Home() {
const toast = useToast();
const { publicKey, isConnected } = useStellarWallet();
const {
data: stats,
isLoading: statsLoading,
isError: statsError,
error: statsErrorObj,
} = usePlatformStats();
const {
data: totalCredits,
isLoading: creditsLoading,
isError: creditsError,
error: creditsErrorObj,
} = useTotalUserCredits();
useEffect(() => {
if (statsError && statsErrorObj) {
toast({
title: "Unable to load platform data",
description:
statsErrorObj instanceof Error
? statsErrorObj.message
: "Failed to fetch dashboard data",
status: "error",
duration: 8000,
isClosable: true,
});
}
}, [statsError, statsErrorObj, toast]);
useEffect(() => {
if (creditsError && creditsErrorObj) {
toast({
title: "Unable to load credits",
description:
creditsErrorObj instanceof Error
? creditsErrorObj.message
: "Failed to fetch user credits",
status: "error",
duration: 8000,
isClosable: true,
});
}
}, [creditsError, creditsErrorObj, toast]);
const formatNumber = (value: number | undefined | null, fallback = "Not tracked") =>
value || value === 0 ? value.toLocaleString() : fallback;
return (
<Flex direction="column" px={{ base: 6, md: 16 }} py={10} align="center" gap={10}>
<MotionBox variants={fadeInUp} initial="hidden" animate="visible" w="100%" maxW="1200px">
<HStack
spacing={2}
mb={5}
display="inline-flex"
borderRadius="full"
border="1px solid"
borderColor="app.border"
bg="app.surface"
backdropFilter="blur(12px)"
px={3}
py={1.5}
>
<Box
w="6px"
h="6px"
borderRadius="full"
bg="app.accent"
boxShadow="0 0 8px var(--chakra-colors-app-accent)"
className="animate-pulse"
/>
<Text fontSize="xs" fontWeight="semibold" letterSpacing="wide" color="app.muted" textTransform="uppercase">
Live on {stellarNetwork}
</Text>
</HStack>
<Text
fontSize={{ base: "4xl", md: "5xl" }}
fontWeight="extrabold"
letterSpacing="tight"
mb={4}
bgGradient="linear(to-r, app.text, app.accent)"
bgClip="text"
>
SmartDrop Dashboard
</Text>
<Text color="app.muted" mb={4} fontSize="lg" maxW="640px">
Live Soroban RPC data with contract-driven TVL, pool counts, and user
metrics.
</Text>
<Text fontSize="sm" color="app.muted" mb={2} fontFamily="mono">
RPC: {sorobanRpcUrl.replace(/^https?:\/\//, "")}
{publicKey ? ` · Wallet ${publicKey.slice(0, 6)}…` : ""}
</Text>
</MotionBox>
<Flex direction="row" w="100%" maxW="1200px" flexWrap="wrap" gap={4}>
<StatCard
label="Total Value Locked"
value={stats?.totalValueLocked ?? "Not available"}
delay={0.05}
isLoading={statsLoading}
/>
<StatCard
label="Active Pools"
value={stats?.totalPools ?? "No pools found"}
accent="app.accent2"
delay={0.1}
isLoading={statsLoading}
/>
<StatCard
label="Total Users"
value={formatNumber(stats?.totalUsers)}
delay={0.15}
isLoading={statsLoading}
/>
<StatCard
label="Users Online"
value={formatNumber(stats?.onlineUsers)}
accent="app.accent2"
delay={0.2}
isLoading={statsLoading}
/>
</Flex>
<MotionBox
variants={fadeInUp}
initial="hidden"
animate="visible"
custom={0.25}
w="100%"
maxW="1200px"
border="1px solid"
borderColor="app.border"
borderRadius="card"
p={8}
bg="app.surface"
boxShadow="card"
>
<Text fontSize="2xl" fontWeight="bold" mb={3}>
Your credits
</Text>
<Text color="app.muted" mb={4}>
Credits are calculated from your on-chain positions across all pools.
</Text>
{isConnected ? (
creditsLoading ? (
<Spinner size="lg" color="app.accent" />
) : (
<Text fontSize="4xl" fontWeight="extrabold" color="app.accent">
{totalCredits ?? "0"} Credits
</Text>
)
) : (
<Alert status="info" borderRadius="xl" bg="app.surfaceHover">
<AlertIcon /> Connect your Freighter wallet to fetch your user credits and positions.
</Alert>
)}
</MotionBox>
<OnboardingOverlay />
</Flex>
);
}