2021-09-23 21:25:52 +00:00
|
|
|
import React, { Suspense, useMemo, useState } from "react";
|
2021-07-01 18:21:40 +00:00
|
|
|
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
|
2021-07-24 08:46:48 +00:00
|
|
|
import WarningHeader from "./WarningHeader";
|
2021-07-01 18:21:40 +00:00
|
|
|
import Home from "./Home";
|
|
|
|
import Search from "./Search";
|
|
|
|
import Title from "./Title";
|
2021-07-12 20:10:16 +00:00
|
|
|
import ConnectionErrorPanel from "./ConnectionErrorPanel";
|
2021-07-10 06:17:07 +00:00
|
|
|
import Footer from "./Footer";
|
2021-07-12 20:10:16 +00:00
|
|
|
import { ConnectionStatus } from "./types";
|
2021-07-09 05:07:20 +00:00
|
|
|
import { RuntimeContext, useRuntime } from "./useRuntime";
|
2021-09-23 21:25:52 +00:00
|
|
|
import { AppConfig, AppConfigContext } from "./useAppConfig";
|
|
|
|
import { SourcifySource } from "./url";
|
2021-07-01 18:21:40 +00:00
|
|
|
|
|
|
|
const Block = React.lazy(() => import("./Block"));
|
|
|
|
const BlockTransactions = React.lazy(() => import("./BlockTransactions"));
|
|
|
|
const AddressTransactions = React.lazy(() => import("./AddressTransactions"));
|
|
|
|
const Transaction = React.lazy(() => import("./Transaction"));
|
2021-10-21 07:31:37 +00:00
|
|
|
const London = React.lazy(() => import("./special/london/London"));
|
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();
|
2021-09-23 21:25:52 +00:00
|
|
|
const [sourcifySource, setSourcifySource] = useState<SourcifySource>(
|
|
|
|
SourcifySource.IPFS_IPNS
|
|
|
|
);
|
|
|
|
const appConfig = useMemo((): AppConfig => {
|
|
|
|
return {
|
|
|
|
sourcifySource,
|
|
|
|
setSourcifySource,
|
|
|
|
};
|
|
|
|
}, [sourcifySource, setSourcifySource]);
|
2021-07-08 19:02:42 +00:00
|
|
|
|
|
|
|
return (
|
2021-10-24 04:12:05 +00:00
|
|
|
<Suspense fallback={null}>
|
2021-07-12 20:10:16 +00:00
|
|
|
{runtime.connStatus !== ConnectionStatus.CONNECTED ? (
|
|
|
|
<ConnectionErrorPanel
|
|
|
|
connStatus={runtime.connStatus}
|
|
|
|
config={runtime.config}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<RuntimeContext.Provider value={runtime}>
|
|
|
|
<div className="h-screen flex flex-col">
|
2021-07-24 08:46:48 +00:00
|
|
|
<WarningHeader />
|
2021-07-12 20:10:16 +00:00
|
|
|
<Router>
|
|
|
|
<Switch>
|
|
|
|
<Route path="/" exact>
|
|
|
|
<Home />
|
|
|
|
</Route>
|
|
|
|
<Route path="/search" exact>
|
|
|
|
<Search />
|
|
|
|
</Route>
|
2021-07-29 04:24:39 +00:00
|
|
|
<Route path="/special/london" exact>
|
|
|
|
<London />
|
|
|
|
</Route>
|
2021-07-12 20:10:16 +00:00
|
|
|
<Route>
|
2021-09-23 21:25:52 +00:00
|
|
|
<AppConfigContext.Provider value={appConfig}>
|
2021-10-22 18:08:46 +00:00
|
|
|
<Title />
|
|
|
|
<Route path="/block/:blockNumberOrHash" exact>
|
|
|
|
<Block />
|
|
|
|
</Route>
|
|
|
|
<Route path="/block/:blockNumber/txs" exact>
|
|
|
|
<BlockTransactions />
|
|
|
|
</Route>
|
|
|
|
<Route path="/tx/:txhash">
|
|
|
|
<Transaction />
|
|
|
|
</Route>
|
|
|
|
<Route path="/address/:addressOrName/:direction?">
|
|
|
|
<AddressTransactions />
|
|
|
|
</Route>
|
2021-09-23 21:25:52 +00:00
|
|
|
</AppConfigContext.Provider>
|
2021-07-12 20:10:16 +00:00
|
|
|
</Route>
|
|
|
|
</Switch>
|
|
|
|
</Router>
|
|
|
|
<Footer />
|
|
|
|
</div>
|
|
|
|
</RuntimeContext.Provider>
|
|
|
|
)}
|
2021-07-08 19:02:42 +00:00
|
|
|
</Suspense>
|
|
|
|
);
|
|
|
|
};
|
2021-07-01 18:21:40 +00:00
|
|
|
|
|
|
|
export default React.memo(App);
|