forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
84 lines (71 loc) · 2.88 KB
/
Copy pathApp.tsx
File metadata and controls
84 lines (71 loc) · 2.88 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
import { lazy, Suspense, useState } from "react";
import { Outlet, Route, Routes, Navigate } from "react-router-dom";
import Home from "./pages/Home";
import { useKeyboardShortcuts } from "./hooks/useKeyboardShortcuts";
import { KeyboardShortcutsModal } from "./components/KeyboardShortcutsModal";
// Code Splitting / Lazy Loading Router Configurations
const BrowsePage = lazy(() => import("./pages/browse/page.tsx"));
const SellPage = lazy(() => import("./pages/sell/page.tsx"));
const ChatHome = lazy(() => import("./pages/chat/page.tsx"));
const ProfilePage = lazy(() => import("./pages/profile/page.tsx"));
const PromptDetailPage = lazy(() => import("./pages/prompts/PromptDetailPage.tsx"));
// Lazy load your new administrative layout entry block
const AdminDashboard = lazy(() => import("./pages/admin/Dashboard.tsx"));
// 1. Define your allowed Stellar admin wallet addresses
const ALLOWED_ADMINS = [
"GBADMINWALLETADDRESSEXAMPLE124567890YOURREALADDRESS", // Replace with your test Stellar address
].map((addr) => addr.toUpperCase());
// 2. Create your wrapper guard component
function AdminGuard({ children }: { children: React.ReactNode }) {
const connectedWallet = (window as any).stellarWalletAddress?.toUpperCase();
// DEVELOPMENT MODE BYPASS: If no wallet window mock is injected yet,
// we let you see the page so you can test the "Ban User" buttons.
if (!connectedWallet) {
return <>{children}</>;
}
// Once a wallet IS mock-injected, strict validation takes over:
if (!ALLOWED_ADMINS.includes(connectedWallet)) {
return <Navigate to="/" replace />;
}
return <>{children}</>;
}
const AppLayout = () => (
<main className="min-h-screen bg-background text-foreground">
<Outlet />
</main>
);
function App() {
const [showShortcutsModal, setShowShortcutsModal] = useState(false);
useKeyboardShortcuts({ onShowShortcuts: () => setShowShortcutsModal(true) });
return (
<Suspense
fallback={
<div className="flex items-center justify-center min-h-screen bg-background">
<div className="text-foreground text-lg">Loading...</div>
</div>
}
>
<Routes>
<Route element={<AppLayout />}>
<Route path="/" element={<Home />} />
<Route path="/browse" element={<BrowsePage />} />
<Route path="/sell" element={<SellPage />} />
<Route path="/chat" element={<ChatHome />} />
<Route path="/profile" element={<ProfilePage />} />
<Route path="/prompts/:id" element={<PromptDetailPage />} />
{/* Admin Dashboard Route with Active Authentication Guard */}
<Route
path="/admin"
element={
<AdminGuard>
<AdminDashboard />
</AdminGuard>
}
/>
<Route path="*" element={<Home />} />
</Route>
</Routes>
</Suspense>
);
}
export default App;