Skip to content

Commit 564618e

Browse files
authored
fix: scope stats history to mainnet views (#12)
1 parent a4a328c commit 564618e

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/components/network-status-content.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ export function NetworkStatusContent() {
4444
const common = useTranslations('common')
4545
const { currentNetwork } = useNetwork()
4646
const { data: status, isLoading, isError, error, refetch, isFetching } = useNodeStatus()
47-
const { data: statsHistory } = useStatsHistory()
47+
const { data: statsHistory } = useStatsHistory({ network: currentNetwork })
4848

49-
// Background series for the time-varying tiles (Connections, Difficulty).
49+
// Mainnet-only background series for the time-varying tiles (Connections, Difficulty).
5050
// Series shorter than MIN_SPARK_POINTS are dropped so the tile stays clean.
5151
const sparks = useMemo(() => {
5252
const points = statsHistory ?? []

src/components/stats-content.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { useTranslations } from '@/lib/i18n'
1919
import { useStats } from '@/hooks/use-stats'
2020
import { useStatsHistory } from '@/hooks/use-stats-history'
21+
import { useNetwork } from '@/contexts/network-context'
2122
import { computeSupplyInfo } from '@/lib/supply'
2223
import { formatBytes, formatCompactNumber, formatNumber } from '@/lib/format'
2324
import { DetailHeader } from '@/components/detail/detail-header'
@@ -41,10 +42,11 @@ const SUPPLY_BAR_GRADIENT = 'linear-gradient(90deg, hsl(var(--primary)), hsl(var
4142
export function StatsContent() {
4243
const t = useTranslations('stats')
4344
const common = useTranslations('common')
45+
const { currentNetwork } = useNetwork()
4446
const { data: stats, isLoading, isError, error, refetch, isFetching } = useStats()
45-
const { data: statsHistory } = useStatsHistory()
47+
const { data: statsHistory } = useStatsHistory({ network: currentNetwork })
4648

47-
// Per-metric background series from the sampled history. Series shorter than
49+
// Per-metric background series from the mainnet-only sampled history. Series shorter than
4850
// MIN_SPARK_POINTS are dropped so the tile renders clean (never a placeholder).
4951
const sparks = useMemo(() => {
5052
const points = statsHistory ?? []

src/hooks/use-stats-history.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useQuery } from '@tanstack/react-query'
2+
import type { NetworkType } from '@/contexts/network-context'
23

34
/**
45
* A single sampled snapshot of the network's time-varying stats, written by the
@@ -23,9 +24,21 @@ interface StatHistoryResponse {
2324
* in place and the tiles fill in their background sparklines automatically once
2425
* points exist.
2526
*/
26-
export function useStatsHistory() {
27+
interface UseStatsHistoryOptions {
28+
/**
29+
* The stats-history endpoint is intentionally sampled for mainnet only.
30+
* Network-aware pages pass their selected network so testnet views do not
31+
* accidentally render cached mainnet history alongside live testnet values.
32+
*/
33+
network?: NetworkType
34+
}
35+
36+
export function useStatsHistory(options: UseStatsHistoryOptions = {}) {
37+
const network = options.network ?? 'mainnet'
38+
2739
return useQuery<StatHistoryPoint[]>({
28-
queryKey: ['stats-history'],
40+
queryKey: ['stats-history', network],
41+
enabled: network === 'mainnet',
2942
queryFn: async (): Promise<StatHistoryPoint[]> => {
3043
const response = await fetch('/api/stats/history', {
3144
headers: { Accept: 'application/json' },

0 commit comments

Comments
 (0)