import "./index.css"; import "@szhsin/react-menu/dist/index.css"; import "public/manifest.json"; import { StrictMode } from "react"; import * as ReactDOM from "react-dom/client"; import { Provider } from "react-redux"; import { createBrowserRouter, RouterProvider } from "react-router-dom"; import { EventPublisher, NostrSystem, ProfileLoaderService } from "@snort/system"; import * as serviceWorkerRegistration from "serviceWorkerRegistration"; import { IntlProvider } from "IntlProvider"; import { unwrap } from "SnortUtils"; import Store from "State/Store"; import Layout from "Pages/Layout"; import LoginPage from "Pages/LoginPage"; import ProfilePage from "Pages/ProfilePage"; import { RootRoutes } from "Pages/Root"; import NotificationsPage from "Pages/Notifications"; import SettingsPage, { SettingsRoutes } from "Pages/SettingsPage"; import ErrorPage from "Pages/ErrorPage"; import VerificationPage from "Pages/Verification"; import MessagesPage from "Pages/MessagesPage"; import ChatPage from "Pages/ChatPage"; import DonatePage from "Pages/DonatePage"; import HashTagsPage from "Pages/HashTagsPage"; import SearchPage from "Pages/SearchPage"; import HelpPage from "Pages/HelpPage"; import { NewUserRoutes } from "Pages/new"; import { WalletRoutes } from "Pages/WalletPage"; import NostrLinkHandler from "Pages/NostrLinkHandler"; import Thread from "Element/Thread"; import { SubscribeRoutes } from "Pages/subscribe"; import ZapPoolPage from "Pages/ZapPool"; import DebugPage from "Pages/Debug"; import { db } from "Db"; import { preload, RelayMetrics, UserCache, UserRelays } from "cache"; import { LoginStore } from "Login"; import { LivePage } from "Pages/LivePage"; /** * Singleton nostr system */ export const System = new NostrSystem({ relayCache: UserRelays, profileCache: UserCache, relayMetrics: RelayMetrics, authHandler: async (c, r) => { const { publicKey, privateKey } = LoginStore.snapshot(); if (publicKey) { const pub = new EventPublisher(publicKey, privateKey); return await pub.nip42Auth(c, r); } }, }); /** * Singleton user profile loader */ export const ProfileLoader = new ProfileLoaderService(System, UserCache); // @ts-expect-error Setting webpack nonce window.__webpack_nonce__ = "ZmlhdGphZiBzYWlkIHNub3J0LnNvY2lhbCBpcyBwcmV0dHkgZ29vZCwgd2UgbWFkZSBpdCE="; serviceWorkerRegistration.register(); export const router = createBrowserRouter([ { element: , errorElement: , loader: async () => { const login = LoginStore.takeSnapshot(); db.ready = await db.isAvailable(); if (db.ready) { await preload(login.follows.item); } for (const [k, v] of Object.entries(login.relays.item)) { System.ConnectToRelay(k, v); } try { if ("registerProtocolHandler" in window.navigator) { window.navigator.registerProtocolHandler( "web+nostr", `${window.location.protocol}//${window.location.host}/%s` ); console.info("Registered protocol handler for 'web+nostr'"); } } catch (e) { console.error("Failed to register protocol handler", e); } return null; }, children: [ ...RootRoutes, { path: "/login", element: , }, { path: "/help", element: , }, { path: "/e/:id", element: , }, { path: "/p/:id", element: , }, { path: "/notifications", element: , }, { path: "/settings", element: , children: SettingsRoutes, }, { path: "/verification", element: , }, { path: "/messages", element: , }, { path: "/messages/:id", element: , }, { path: "/donate", element: , }, { path: "/t/:tag", element: , }, { path: "/search/:keyword?", element: , }, { path: "/zap-pool", element: , }, { path: "/live/:id", element: , }, ...NewUserRoutes, ...WalletRoutes, ...SubscribeRoutes, { path: "/debug", element: , }, { path: "/*", element: , }, ], }, ]); const root = ReactDOM.createRoot(unwrap(document.getElementById("root"))); root.render( );