Skip to content

Average block time: live refresh via stats API refetch interval ENV#3461

Merged
tom2drum merged 2 commits into
mainfrom
tom2drum/issue-3407
May 19, 2026
Merged

Average block time: live refresh via stats API refetch interval ENV#3461
tom2drum merged 2 commits into
mainfrom
tom2drum/issue-3407

Conversation

@tom2drum
Copy link
Copy Markdown
Collaborator

Description and Related Issue(s)

Resolves #3407

Adds optional polling for Stats API resources so average block time (and related homepage stats) update while the user stays on the page, on both the main page and /stats.

Proposed Changes

  • Introduce NEXT_PUBLIC_STATS_API_REFETCH_INTERVAL — a JSON map of Stats API resource names to refetch intervals in milliseconds.
  • Wire refetchInterval into:
    • stats:pages_main on the homepage (Stats, ChainIndicators, chart queries)
    • stats:counters on the chain stats page (ChainStatsCounters)
  • Stop refetch polling when a query is in error state; treat refetch errors separately so a transient failure during polling does not replace the UI with a full error state.
  • Add env validator schema (requires NEXT_PUBLIC_STATS_API_HOST when set) and document the variable in ENVS.md.

Environment variable changes

Variable Purpose
NEXT_PUBLIC_STATS_API_REFETCH_INTERVAL Sets how often (ms) Stats API resources are refetched in the background. Keys: stats:counters (chain stats counters, including average block time on /stats) and stats:pages_main (homepage stats widgets and charts, including average block time on the main page). Example: {'stats:pages_main': 10000, 'stats:counters': 10000}. Only valid when NEXT_PUBLIC_STATS_API_HOST is configured.

Breaking or Incompatible Changes

None. The variable is optional; without it, behavior is unchanged (no polling).

Additional Information

Checklist for PR author

  • I have tested these changes locally.
  • I added tests to cover any new functionality, following this guide
  • Whenever I fix a bug, I include a regression test to ensure that the bug does not reappear silently.
  • If I have added a feature or functionality that is not privacy-compliant (e.g., tracking, analytics, third-party services), I have disabled it for private mode.
  • If I have added, changed, renamed, or removed an environment variable
    • I updated the list of environment variables in the documentation
    • I made the necessary changes to the validator script according to the guide
    • I added "ENVs" label to this pull request

@tom2drum tom2drum added the ENVs label May 19, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

Important

Review skipped

Auto reviews are disabled on this repository. To trigger a review, include @coderabbitai review in the PR description. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 258cd68e-3455-455c-bcca-80155cbeee11

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds optional, ENV-configured polling for selected Stats API resources so “average block time” and related homepage / /stats counters can refresh while the user stays on the page, without treating background refetch failures as full-page errors.

Changes:

  • Introduces NEXT_PUBLIC_STATS_API_REFETCH_INTERVAL (JSON map) and wires it into Stats API config parsing.
  • Adds refetchInterval to homepage stats widgets/charts and /stats counters queries, and adjusts error handling to ignore refetch-only errors.
  • Extends env validator + test env base values and documents the new variable.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
docs/ENVS.md Documents the new NEXT_PUBLIC_STATS_API_REFETCH_INTERVAL env var.
deploy/tools/envs-validator/test/.env.base Adds a sample value for the new env var in validator tests.
deploy/tools/envs-validator/schemas/apis.ts Adds yup validation for the new env var and dependency on NEXT_PUBLIC_STATS_API_HOST.
configs/app/apis.ts Parses env JSON map and exposes stats.refetchInterval in app config.
client/slices/home/pages/index/stats/Stats.tsx Adds polling for stats:pages_main and avoids degrading UI on refetch-only errors.
client/slices/home/pages/index/charts/ChainIndicators.tsx Adds polling for stats:pages_main indicators.
client/slices/home/hooks/useChartDataQuery.ts Adds polling for stats:pages_main chart queries and refetch-error handling.
client/features/chain-stats/types/config.ts Defines the allowed Stats API resources that can be configured for polling.
client/features/chain-stats/pages/index/ChainStatsCounters.tsx Adds polling for stats:counters and ignores refetch-only errors for alert display.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/ENVS.md Outdated
Comment thread deploy/tools/envs-validator/schemas/apis.ts
Comment thread client/slices/home/hooks/useChartDataQuery.ts Outdated
@tom2drum tom2drum merged commit f922e9f into main May 19, 2026
2 checks passed
@tom2drum tom2drum deleted the tom2drum/issue-3407 branch May 19, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Average block time: new ENV to update in realtime

2 participants