otterscan/src/App.tsx

70 lines
2.6 KiB
TypeScript
Raw Normal View History

2021-11-25 09:28:45 +00:00
import React, { Suspense } from "react";
2022-10-25 21:54:28 +00:00
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import WarningHeader from "./WarningHeader";
2021-07-01 18:21:40 +00:00
import Home from "./Home";
2021-11-25 09:28:45 +00:00
import Main from "./Main";
import ConnectionErrorPanel from "./ConnectionErrorPanel";
2021-07-10 06:17:07 +00:00
import Footer from "./Footer";
import { ConnectionStatus } from "./types";
2021-07-09 05:07:20 +00:00
import { RuntimeContext, useRuntime } from "./useRuntime";
import { ChainInfoContext, useChainInfoFromMetadataFile } from "./useChainInfo";
2021-07-01 18:21:40 +00:00
2022-08-05 21:54:30 +00:00
const Block = React.lazy(() => import("./Block"));
const BlockTransactions = React.lazy(() => import("./BlockTransactions"));
const Address = React.lazy(() => import("./Address"));
const Transaction = React.lazy(() => import("./Transaction"));
const London = React.lazy(() => import("./special/london/London"));
const Faucets = React.lazy(() => import("./Faucets"));
const PageNotFound = React.lazy(() => import("./PageNotFound"));
2021-07-01 18:21:40 +00:00
2021-07-08 19:02:42 +00:00
const App = () => {
2021-07-09 05:07:20 +00:00
const runtime = useRuntime();
const chainInfo = useChainInfoFromMetadataFile(runtime);
2021-07-08 19:02:42 +00:00
return (
2021-10-24 04:12:05 +00:00
<Suspense fallback={null}>
{runtime.connStatus !== ConnectionStatus.CONNECTED ||
chainInfo === undefined ? (
<ConnectionErrorPanel
connStatus={runtime.connStatus}
config={runtime.config}
/>
) : (
<RuntimeContext.Provider value={runtime}>
<ChainInfoContext.Provider value={chainInfo}>
<div className="h-screen flex flex-col">
<WarningHeader />
<Router>
<Routes>
<Route index element={<Home />} />
<Route path="/special/london" element={<London />} />
<Route path="*" element={<Main />}>
<Route
path="block/:blockNumberOrHash"
element={<Block />}
/>
<Route
path="block/:blockNumber/txs"
element={<BlockTransactions />}
/>
<Route path="tx/:txhash/*" element={<Transaction />} />
<Route
path="address/:addressOrName/*"
element={<Address />}
/>
2022-04-06 01:38:27 +00:00
<Route path="faucets/*" element={<Faucets />} />
<Route path="*" element={<PageNotFound />} />
</Route>
</Routes>
</Router>
<Footer />
</div>
</ChainInfoContext.Provider>
</RuntimeContext.Provider>
)}
2021-07-08 19:02:42 +00:00
</Suspense>
);
};
2021-07-01 18:21:40 +00:00
2021-11-25 09:28:45 +00:00
export default App;