import { useState, lazy, Suspense } from 'react'; import { Megaphone, MessageCircle, Gift, Wallet, Loader2, ArrowLeftRight } from 'lucide-react'; import { cn } from '@/lib/utils'; import { UpdateNotification } from '@/components/UpdateNotification'; import { useTranslation } from '@/i18n'; // Lazy load sections for code splitting const AnnouncementsSection = lazy(() => import('@/sections/Announcements').then((m) => ({ default: m.AnnouncementsSection })) ); const ForumSection = lazy(() => import('@/sections/Forum').then((m) => ({ default: m.ForumSection })) ); const RewardsSection = lazy(() => import('@/sections/Rewards').then((m) => ({ default: m.RewardsSection })) ); const WalletSection = lazy(() => import('@/sections/Wallet').then((m) => ({ default: m.WalletSection })) ); const P2PSection = lazy(() => import('@/sections/P2P').then((m) => ({ default: m.P2PSection }))); const CitizenPage = lazy(() => import('@/pages/CitizenPage').then((m) => ({ default: m.CitizenPage })) ); const ExplorerPage = lazy(() => import('@/pages/ExplorerPage').then((m) => ({ default: m.ExplorerPage })) ); // Loading fallback component function SectionLoader() { return (
); } type Section = 'announcements' | 'forum' | 'rewards' | 'p2p' | 'wallet'; interface NavItem { id: Section; icon: typeof Megaphone; labelKey: string; } const NAV_ITEMS: NavItem[] = [ { id: 'announcements', icon: Megaphone, labelKey: 'nav.announcements' }, { id: 'forum', icon: MessageCircle, labelKey: 'nav.forum' }, { id: 'rewards', icon: Gift, labelKey: 'nav.rewards' }, { id: 'p2p', icon: ArrowLeftRight, labelKey: 'nav.p2p' }, { id: 'wallet', icon: Wallet, labelKey: 'nav.wallet' }, ]; // Check for standalone pages via URL query params or path (evaluated once at module level) const PAGE_PARAM = new URLSearchParams(window.location.search).get('page'); const TELEGRAM_START_PARAM = window.Telegram?.WebApp?.initDataUnsafe?.start_param; // SS58 address for prefix 42 starts with "5" and is 48 chars of base58 const IS_CITIZENSHIP_REFERRAL = !!TELEGRAM_START_PARAM && /^5[1-9A-HJ-NP-Za-km-z]{46,47}$/.test(TELEGRAM_START_PARAM); const IS_CITIZEN_PAGE = PAGE_PARAM === 'citizen' || window.location.pathname === '/citizens' || IS_CITIZENSHIP_REFERRAL; const IS_EXPLORER_PAGE = window.location.pathname.replace(/\/$/, '') === '/explorer'; export default function App() { if (IS_CITIZEN_PAGE) { return ( }> ); } if (IS_EXPLORER_PAGE) { return ( }> ); } return ; } function MainApp() { const [activeSection, setActiveSection] = useState
('announcements'); const { t } = useTranslation(); const handleNavClick = (item: NavItem) => { window.Telegram?.WebApp.HapticFeedback.selectionChanged(); setActiveSection(item.id); }; return (
{/* Content Area */}
}> {activeSection === 'announcements' && } {activeSection === 'forum' && } {activeSection === 'rewards' && } {activeSection === 'p2p' && } {activeSection === 'wallet' && }
{/* Update Notification */} {/* Bottom Navigation */}
); }