|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import React, { useEffect } from "react"; |
| 4 | +import { useRouter } from "next/navigation"; |
| 5 | +import { useWallet } from "@/hooks/useWallet"; |
| 6 | +import { PageContainer } from "@/components/ui/PageContainer"; |
| 7 | +import { BannerPage } from "@/components/ui/BannerPage"; |
| 8 | +import { ConnectWalletModal } from "@/features/wallet/components/ConnectWalletModal"; |
| 9 | +import PoolStateToggle from "./PoolStateToggle"; |
| 10 | +import TreasuryFeesTable from "./TreasuryFeesTable"; |
| 11 | +import CollateralFactorForm from "./CollateralFactorForm"; |
| 12 | +import InterestRateParamsForm from "./InterestRateParamsForm"; |
| 13 | + |
| 14 | +const ADMIN_ADDRESS = process.env.NEXT_PUBLIC_LENDING_ADMIN_ADDRESS ?? ""; |
| 15 | + |
| 16 | +function ConnectWalletPrompt() { |
| 17 | + const [showModal, setShowModal] = React.useState(false); |
| 18 | + return ( |
| 19 | + <div className="flex flex-col items-center justify-center min-h-[400px] gap-4"> |
| 20 | + <p className="text-white/70 text-center"> |
| 21 | + Connect your wallet to access the admin panel. |
| 22 | + </p> |
| 23 | + <button |
| 24 | + onClick={() => setShowModal(true)} |
| 25 | + className="px-6 py-2 rounded-xl bg-[#229EDF] hover:bg-[#1e8bc9] text-white font-medium transition-colors" |
| 26 | + > |
| 27 | + Connect Wallet |
| 28 | + </button> |
| 29 | + <ConnectWalletModal |
| 30 | + isOpen={showModal} |
| 31 | + onClose={() => setShowModal(false)} |
| 32 | + /> |
| 33 | + </div> |
| 34 | + ); |
| 35 | +} |
| 36 | + |
| 37 | +export default function AdminPageClient() { |
| 38 | + const { address } = useWallet(); |
| 39 | + const router = useRouter(); |
| 40 | + |
| 41 | + // Page NOT exposed: redirect immediately if admin not configured or user is not admin |
| 42 | + useEffect(() => { |
| 43 | + if (!ADMIN_ADDRESS) { |
| 44 | + router.replace("/dashboard"); |
| 45 | + return; |
| 46 | + } |
| 47 | + if (address && address !== ADMIN_ADDRESS) { |
| 48 | + router.replace("/dashboard"); |
| 49 | + } |
| 50 | + }, [address, router]); |
| 51 | + |
| 52 | + if (!ADMIN_ADDRESS) return null; |
| 53 | + if (address && address !== ADMIN_ADDRESS) return null; |
| 54 | + |
| 55 | + // Only show Connect prompt when admin not yet connected (so they can connect) |
| 56 | + if (!address) { |
| 57 | + return ( |
| 58 | + <div className="w-full min-w-0 max-w-full min-h-screen overflow-x-hidden"> |
| 59 | + <PageContainer maxWidth="7xl" className="space-y-8 sm:space-y-10"> |
| 60 | + <BannerPage |
| 61 | + title="Admin" |
| 62 | + subtitle="Lending pool administration" |
| 63 | + badge="Restricted" |
| 64 | + /> |
| 65 | + <ConnectWalletPrompt /> |
| 66 | + </PageContainer> |
| 67 | + </div> |
| 68 | + ); |
| 69 | + } |
| 70 | + |
| 71 | + // Admin is connected: show full admin UI |
| 72 | + return ( |
| 73 | + <div className="w-full min-w-0 max-w-full min-h-screen overflow-x-hidden"> |
| 74 | + <PageContainer maxWidth="7xl" className="space-y-8 sm:space-y-10"> |
| 75 | + <BannerPage |
| 76 | + title="Admin" |
| 77 | + subtitle="Pool state, treasury fees, collateral factors, interest rates" |
| 78 | + badge="Admin" |
| 79 | + /> |
| 80 | + <div className="space-y-10"> |
| 81 | + <PoolStateToggle /> |
| 82 | + <TreasuryFeesTable /> |
| 83 | + <CollateralFactorForm /> |
| 84 | + <InterestRateParamsForm /> |
| 85 | + </div> |
| 86 | + </PageContainer> |
| 87 | + </div> |
| 88 | + ); |
| 89 | +} |
0 commit comments