Adapter hooks that fetch and shape site, pool, dashboard, and chart data
@tetherto/mdk-react-adapter
TanStack Query–backed hooks that fetch live data from the MDK backend and project it into view-model shapes ready for MDK foundation components. These hooks sit in the adapter layer so that tag names, aggregate field keys, and unit conversions stay out of the devkit component layer.
All hooks require <MdkProvider> to be mounted in the tree.
Projects raw site-overview container rows and pool stats into a <PoolManagerSitesOverview />-ready shape. Each container receives its per-container hashrate in MH/s, an attached pool-stats row, and a mining / offline status derived from the underlying snapshot.
import { useSitesOverviewData } from '@tetherto/mdk-react-adapter'
Projects the freshest power sample from the dashboard's existing tail-log query into a scalar MW value for the header stats strip (<HeaderConsumptionBox />). Delegates fetching to useSiteConsumptionChartData.
import { useSiteConsumption } from '@tetherto/mdk-react-adapter'
TanStack Query hook that fetches site consumption tail-log samples and returns a <LineChartCard>-ready ChartCardData payload. Applies site-powermeter defaults and converts watts to MW.
import { useSiteConsumptionChartData } from '@tetherto/mdk-react-adapter'
Reads the aggregated nominal miner capacity across all site containers from the 5-minute tail-log aggregate, giving the denominator shown in the header (e.g. the "2,188" in "MOS / 2,188").
import { useSiteContainerCapacity } from '@tetherto/mdk-react-adapter'
Derives site efficiency in W/TH/s by dividing the latest site consumption by the latest hashrate. Both upstream hooks are called internally; pass powerW to override the consumption source (e.g. to use a power-meter reading instead).
import { useSiteEfficiency } from '@tetherto/mdk-react-adapter'
Required. Stat key suffix forwarded to both upstream hooks.
start
Optional
number
none
Lower time bound (ms epoch).
end
Optional
number
none
Upper time bound (ms epoch).
tag
Optional
string
none
Thing tag override forwarded to the consumption hook.
powerAttribute
Optional
string
none
Aggregate field override forwarded to the consumption hook.
refetchInterval
Optional
number
none
Polling interval in ms forwarded to both upstream hooks.
powerW
Optional
number
none
When provided, skips the internal useSiteConsumption call and uses this watts value as the numerator directly. Pair with useSitePowerMeter().valueW for meter-level efficiency.
TanStack Query hook that reads the latest aggregate hashrate from the site tail-log and returns both a PH/s display value and the raw MH/s backend value.
import { useSiteHashrate } from '@tetherto/mdk-react-adapter'
Polls the stat-rtd realtime aggregate for the live miner stat summary — the MOS total, online/offline breakdown, and active pool worker count shown in the header.
import { useSiteMinerStats } from '@tetherto/mdk-react-adapter'
TanStack Query hook that fetches per-pool stats and transforms them into PoolRow[] objects shaped for the pool manager table. Hashrate is normalised from raw H/s to PH/s.
import { usePoolRows } from '@tetherto/mdk-react-adapter'
TanStack Query hook that fetches per-pool stats and aggregates them into site-level totals — total workers, online workers, mismatch count, and aggregate hashrate in PH/s.
import { usePoolStats } from '@tetherto/mdk-react-adapter'
Owns the single source of truth for the dashboard's date-range picker: a start / end ms-epoch pair with setters and a reset helper that restores the default 24-hour window.
import { useDashboardDateRange } from '@tetherto/mdk-react-adapter'
Reads cached query data for hashrate, consumption, incidents, and pool stats from the TanStack Query client and exposes exportCsv, exportJson, and a unified export(format) callable. Does not trigger refetches — the export represents exactly what is currently displayed.
import { useDashboardExport } from '@tetherto/mdk-react-adapter'
Tiny piece of scoped state for the dashboard's timeline selector. Owns the current timeline string and the canonical option list. Chart hooks (useHashrateChartData, useSiteConsumptionChartData, etc.) consume timeline as a prop.
import { useDashboardTimeRange } from '@tetherto/mdk-react-adapter'
TanStack Query hook returning raw consumption tail-log samples. Most dashboards should use the higher-level useSiteConsumptionChartData, which wraps this hook and returns a <LineChartCard>-ready payload.
import { useConsumptionChartData } from '@tetherto/mdk-react-adapter'
TanStack Query hook combining the site tail-log hashrate series with the per-pool hashrate history into a single ChartCardData payload for <LineChartCard />. Handles unit conversion from both MH/s (tail-log) and raw H/s (pool API) into PH/s for display.
import { useHashrateChartData } from '@tetherto/mdk-react-adapter'
Reads ?authToken=… from window.location.search, persists it into the headless authStore, and strips the parameter from the URL via history.replaceState so the token never lingers in the address bar. Router-agnostic by design. Returns the current token from the store so callers can gate navigation on authentication.
import { useAuthToken } from '@tetherto/mdk-react-adapter'
Polls the backend token-refresh endpoint at a fixed interval (default 250 s) and writes the new token back into the authStore. Fires the optional onSessionEnded callback on a 401 or 500, which MDK UI Shell uses to redirect back to /signin.
import { useTokenPolling } from '@tetherto/mdk-react-adapter'
TanStack Query hook returning the list of currently-firing alerts, shaped for <ActiveIncidentsCard items={...} />. Queries devices that have a non-null last.alerts field and maps them via the mapDevicesToIncidents utility.
import { useActiveIncidents } from '@tetherto/mdk-react-adapter'