forked from LabsCrypt/flowfi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
311 lines (282 loc) · 11.8 KB
/
Copy pathpage.tsx
File metadata and controls
311 lines (282 loc) · 11.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
"use client";
import { useState, useEffect } from "react";
import { Copy, Check, LogOut, Moon, Sun, Bell, Globe } from "lucide-react";
import { useWallet } from "@/context/wallet-context";
import { useRouter } from "next/navigation";
import { shortenPublicKey, formatNetwork } from "@/lib/wallet";
import toast from "react-hot-toast";
type DisplayCurrency = "USD" | "XLM" | "USDC";
type AmountFormat = "full" | "compact";
export default function SettingsPage() {
const router = useRouter();
const { session, disconnect, isHydrated } = useWallet();
const [browserPush, setBrowserPush] = useState(false);
const [theme, setTheme] = useState<"light" | "dark" | "system">(() => {
if (typeof window !== "undefined") {
const saved = localStorage.getItem("flowfi-theme") as
| "light"
| "dark"
| "system"
| null;
if (saved) {
document.documentElement.classList.toggle("dark", saved === "dark");
return saved;
}
}
return "dark";
});
const [displayCurrency, setDisplayCurrency] = useState<DisplayCurrency>(() => {
if (typeof window !== "undefined") {
return (localStorage.getItem("flowfi-currency") as DisplayCurrency) || "USD";
}
return "USD";
});
const [amountFormat, setAmountFormat] = useState<AmountFormat>(() => {
if (typeof window !== "undefined") {
return (localStorage.getItem("flowfi-amount-format") as AmountFormat) || "full";
}
return "full";
});
const [copied, setCopied] = useState(false);
const toggleTheme = (newTheme: "light" | "dark" | "system") => {
setTheme(newTheme);
localStorage.setItem("flowfi-theme", newTheme);
if (newTheme === "system") {
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
document.documentElement.classList.toggle("dark", prefersDark);
} else {
document.documentElement.classList.toggle("dark", newTheme === "dark");
}
};
const copyAddress = async () => {
if (session?.publicKey) {
await navigator.clipboard.writeText(session.publicKey);
setCopied(true);
toast.success("Address copied to clipboard");
setTimeout(() => setCopied(false), 1500);
}
};
const handleDisconnect = () => {
disconnect();
toast.success("Wallet disconnected");
router.push("/");
};
const handleBrowserPushToggle = async () => {
if (!browserPush) {
try {
await Notification.requestPermission();
setBrowserPush(Notification.permission === "granted");
if (Notification.permission === "granted") {
toast.success("Browser notifications enabled");
}
} catch {
toast.error("Failed to enable notifications");
}
} else {
setBrowserPush(false);
toast("Browser notifications disabled");
}
};
if (!isHydrated) {
return (
<div className="relative min-h-screen overflow-hidden bg-gradient-to-br from-zinc-950 via-zinc-900 to-black dark:from-white dark:via-gray-100 dark:to-gray-200 transition-colors flex items-center justify-center">
<div className="text-white dark:text-black">Loading...</div>
</div>
);
}
return (
<div className="relative min-h-screen overflow-hidden bg-gradient-to-br from-zinc-950 via-zinc-900 to-black dark:from-white dark:via-gray-100 dark:to-gray-200 transition-colors">
{/* Background Glow */}
<div className="absolute -top-40 -right-40 w-96 h-96 bg-purple-600/20 blur-3xl rounded-full" />
<div className="absolute -bottom-40 -left-40 w-96 h-96 bg-blue-600/20 blur-3xl rounded-full" />
<div className="relative max-w-xl mx-auto px-6 py-20">
<div className="rounded-3xl border border-white/10 dark:border-black/10 bg-white/5 dark:bg-black/5 backdrop-blur-2xl shadow-2xl p-10 space-y-10">
<div>
<h1 className="text-3xl font-semibold tracking-tight text-white dark:text-black">
Settings
</h1>
<p className="text-sm opacity-60 mt-1">
Manage your FlowFi preferences
</p>
</div>
{/* Browser Push Notifications */}
<div className="flex items-center justify-between group">
<div className="flex items-center gap-3">
<div className="p-2 rounded-lg bg-purple-500/20 text-purple-400">
<Bell size={18} />
</div>
<div>
<p className="font-medium text-white dark:text-black">
Browser Notifications
</p>
<p className="text-sm opacity-60">
Get notified about stream activity
</p>
</div>
</div>
<button
onClick={handleBrowserPushToggle}
className={`relative w-14 h-7 rounded-full transition-all duration-300 ${
browserPush
? "bg-gradient-to-r from-purple-500 to-blue-500"
: "bg-zinc-600"
}`}
>
<span
className={`absolute top-1 left-1 w-5 h-5 bg-white rounded-full shadow-md transform transition duration-300 ${
browserPush
? "translate-x-7"
: "translate-x-0"
}`}
/>
</button>
</div>
{/* Theme Toggle */}
<div className="space-y-4">
<div className="flex items-center gap-3">
<div className="p-2 rounded-lg bg-blue-500/20 text-blue-400">
{theme === "dark" ? <Moon size={18} /> : theme === "light" ? <Sun size={18} /> : <Globe size={18} />}
</div>
<div>
<p className="font-medium text-white dark:text-black">
Appearance
</p>
<p className="text-sm opacity-60">
Choose your theme preference
</p>
</div>
</div>
<div className="flex gap-2">
{(["light", "dark", "system"] as const).map((t) => (
<button
key={t}
onClick={() => toggleTheme(t)}
className={`px-4 py-2 text-sm rounded-xl border transition-all ${
theme === t
? "border-purple-500 bg-purple-500/20 text-white"
: "border-white/10 dark:border-black/10 text-white/60 dark:text-black/60 hover:border-white/20"
}`}
>
{t.charAt(0).toUpperCase() + t.slice(1)}
</button>
))}
</div>
</div>
{/* Display Preferences */}
<div className="space-y-4">
<div className="flex items-center gap-3">
<div className="p-2 rounded-lg bg-green-500/20 text-green-400">
<Globe size={18} />
</div>
<div>
<p className="font-medium text-white dark:text-black">
Display Preferences
</p>
<p className="text-sm opacity-60">
Customize how amounts are displayed
</p>
</div>
</div>
<div className="space-y-3 pl-12">
<div>
<label className="text-sm text-white/60 dark:text-black/60">Default Token</label>
<select
value={displayCurrency}
onChange={(e) => {
const val = e.target.value as DisplayCurrency;
setDisplayCurrency(val);
localStorage.setItem("flowfi-currency", val);
}}
className="mt-1 block w-full px-3 py-2 rounded-lg bg-black/40 dark:bg-white/40 border border-white/10 dark:border-black/10 text-white dark:text-black text-sm"
>
<option value="USD">USD</option>
<option value="XLM">XLM</option>
<option value="USDC">USDC</option>
</select>
</div>
<div>
<label className="text-sm text-white/60 dark:text-black/60">Amount Format</label>
<div className="flex gap-2 mt-1">
{(["full", "compact"] as const).map((fmt) => (
<button
key={fmt}
onClick={() => {
setAmountFormat(fmt);
localStorage.setItem("flowfi-amount-format", fmt);
}}
className={`px-3 py-1.5 text-xs rounded-lg border transition-all ${
amountFormat === fmt
? "border-blue-500 bg-blue-500/20 text-white"
: "border-white/10 text-white/60 hover:border-white/20"
}`}
>
{fmt === "full" ? "Full (1.0000000)" : "Compact (1.0)"}
</button>
))}
</div>
</div>
</div>
</div>
{/* Wallet Section */}
{session ? (
<div className="space-y-3">
<div className="flex items-center justify-between">
<p className="font-medium text-white dark:text-black">
Connected Wallet
</p>
<div className="flex items-center gap-2">
<span className="inline-flex items-center px-3 py-1 rounded-full text-xs font-semibold bg-purple-500/20 text-purple-400 border border-purple-500/30">
{formatNetwork(session.network)}
</span>
<span className="inline-flex items-center px-3 py-1 rounded-full text-xs font-semibold bg-blue-500/20 text-blue-400 border border-blue-500/30">
{session.walletName}
</span>
</div>
</div>
<div className="relative flex items-center justify-between bg-black/40 dark:bg-white/40 px-5 py-4 rounded-xl font-mono text-sm break-all text-white dark:text-black border border-white/10 dark:border-black/10">
<span className="pr-4">{session.publicKey}</span>
<button
onClick={copyAddress}
className="ml-3 opacity-70 hover:opacity-100 transition flex-shrink-0"
>
{copied ? (
<Check size={18} className="text-green-400" />
) : (
<Copy size={18} />
)}
</button>
{copied && (
<span className="absolute -top-8 right-2 text-xs bg-black text-white dark:bg-white dark:text-black px-2 py-1 rounded-md shadow">
Copied
</span>
)}
</div>
</div>
) : (
<div className="space-y-3">
<p className="font-medium text-white dark:text-black">
Wallet Status
</p>
<div className="flex items-center justify-between bg-black/40 dark:bg-white/40 px-5 py-4 rounded-xl text-white dark:text-black border border-white/10 dark:border-black/10">
<span>Not connected</span>
<a href="/" className="text-accent hover:opacity-80 transition font-semibold">
Connect Wallet
</a>
</div>
</div>
)}
{/* Disconnect */}
{session && (
<button
onClick={handleDisconnect}
className="w-full flex items-center justify-center gap-2 bg-red-600/90 hover:bg-red-600 transition px-4 py-3 rounded-xl text-white font-medium shadow-lg hover:shadow-red-500/30"
>
<LogOut size={18} />
Disconnect Wallet
</button>
)}
</div>
</div>
</div>
);
}