/** * The page. * * A chain and a window, with at most one of a block, a miner or an account in * focus above the standings. All of it lives in the path — see `lib/routes` for * the grammar and why it is a path rather than a hash — so every view here can * be linked to, opened in a new tab, and returned to with the back button. */ import { useCallback, useEffect, useMemo } from 'react' import { Link, useLocation, useNavigate } from 'react-router-dom' import { AccountPanel } from './components/AccountPanel' import { BlockPanel } from './components/BlockPanel' import { BlockTicker } from './components/BlockTicker' import { ChainSwitcher } from './components/ChainSwitcher' import { Leaderboard } from './components/Leaderboard' import { MinerPanel } from './components/MinerPanel' import { StatBar } from './components/StatBar' import { seconds, windowSpan } from './lib/format' import { href, parse, WINDOWS } from './lib/routes' import { useObserver, usePinnedMiners, useWatch } from './lib/store' export default function App() { const state = useObserver() const location = useLocation() const navigate = useNavigate() const { pinned } = usePinnedMiners() const route = useMemo(() => parse(location.pathname), [location.pathname]) // Default to the busiest chain we can actually track — the list is ordered // by node count, and an untracked chain has nothing behind it. const fallbackChain = state.chains.find((c) => c.tracking === 'full')?.id ?? null const chain = route.chain ?? fallbackChain const info = useMemo( () => state.chains.find((c) => c.id === chain) ?? null, [state.chains, chain], ) // `/` is not a page, it is "whichever chain the operator put first" — a // question only the backend can answer, and only once it has answered the // chain list. Replacing rather than pushing keeps the bare domain out of the // back stack, where it would bounce the user straight forward again. useEffect(() => { if (!route.chain && fallbackChain) { navigate(href({ chain: fallbackChain, window: route.window }), { replace: true }) } }, [route.chain, route.window, fallbackChain, navigate]) useWatch(chain, route.window) /** * A height has resolved to its hash; put the hash in the address bar. * * `replace`, not a navigation: it is the same block under the name that will * still mean this block after a reorg, so it belongs in place of the height * rather than on top of it in the back stack. The panel keeps rendering from * the height it was given — `BlockPanel` keys on its own prop — so this does * not refetch. */ const blockResolved = useCallback( (hash: string) => { if (!chain) return navigate(href({ chain, block: hash }), { replace: true }) }, [chain, navigate], ) /** Back to the standings, keeping the window the panel was opened from. */ const closePanel = useCallback( () => navigate(href({ chain, window: route.window })), [chain, route.window, navigate], ) const interval = state.summary?.block_interval_seconds ?? state.summary?.target_block_time_seconds ?? 6 const activeWindow = WINDOWS.find((w) => w.id === route.window) ?? WINDOWS[1]! return (
blackbeard.observer
quantus mining · this is sparta
{/* Links, not buttons: a window is part of the address, so "the last 24 hours on Quantus" is a thing to send someone rather than a control state that a shared link would drop. */}
{state.connection}
{info?.status === 'awaiting' && (
{info.display_name} has not started producing blocks yet. This page will come alive on its own the moment it does — no refresh needed.
)} {info?.status === 'unreachable' && (
The observer has lost contact with the {info.display_name} node. The standings below are the last it saw.
)} {info?.status === 'syncing' && (
The node is still importing history. Block interval — and therefore every hashrate on this page — is nominal until it reaches the tip.
)} {route.block && chain && ( )} {route.account && chain && ( )} {route.miner && chain && ( )} {/* A miner and an account are pages, not things opened over the board. Each is somebody's own record and the whole subject of the URL that reached it; leaving eleven other miners' rows underneath is the site failing to notice which page it is on. A block keeps the board, because a block is read *against* it — who won this one, and where do they sit — and the ticker below is the row you clicked to get here. */} {!route.account && !route.miner && (

The Standings

last {activeWindow.blocks.toLocaleString('en-US')} blocks ·{' '} {windowSpan(activeWindow.blocks, interval)} {pinned.length > 0 && ` · ${pinned.length} marked yours`}

Live Blocks

{state.summary?.block_interval_seconds ? `${seconds(state.summary.block_interval_seconds)} apart` : 'measuring'}
)}
) } /** The mark: a spear-point shield, drawn rather than shipped as an asset. */ function Sigil() { return ( ) }