Skip to content

feat(scan): refresh validators and tokens on new blocks#103

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/scan-ws-refresh
Jun 25, 2026
Merged

feat(scan): refresh validators and tokens on new blocks#103
github-actions[bot] merged 1 commit into
mainfrom
feat/scan-ws-refresh

Conversation

@satyakwok

@satyakwok satyakwok commented Jun 25, 2026

Copy link
Copy Markdown
Member

The validators and tokens pages waited a full poll interval (15s and 30s) to reflect chain changes. They now refresh shortly after each new block, using the newHeads websocket the home page already relies on.

What changed

Added useRefetchOnNewBlock(network, refetch) in lib/ws.ts. It subscribes to the shared newHeads websocket and calls the hook's refetch on each new block, throttled to once per 10s. The throttle matters because testnet blocks are ~0.5s apart; without it, slow-changing data like the validator set and token list would refetch many times a second and blow the 60 req/min per-IP budget the poll intervals are sized for.

Wired it into the validators and tokens pages.

Testing

typecheck and build pass. Verified on testnet: the websocket delivers newHeads (the home page refetches per block), and the validators page tightens from a 15s poll to ~10s block-synced refreshes. The tokens page benefits once its EVM-factory cache is warm; during the initial factory walk the in-flight guard dedupes the trigger and it falls back to the 30s poll. No regressions, no console errors.

Notes

Conservative throttle (10s). Could be lowered per page if a fresher view is wanted, within the rate budget. The same hook can be applied to other slow-polling pages later.

Summary by CodeRabbit

  • New Features
    • Token and validator pages now refresh automatically shortly after each new block, so data stays more up to date with less manual waiting.
  • Bug Fixes
    • Improved refresh behavior to reduce reliance on slower polling, helping latest blockchain changes appear sooner.

Both pages waited a full poll interval (15s and 30s) to reflect chain
changes. Added useRefetchOnNewBlock, which refetches shortly after each new
block from the existing newHeads websocket, throttled to once per 10s so
fast block times do not flood the per-IP request budget. Mirrors the home
page live-refresh trigger.
@github-actions github-actions Bot enabled auto-merge (squash) June 25, 2026 08:21
@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A new useRefetchOnNewBlock hook was added in apps/scan/lib/ws.ts. The tokens and validators pages now import it, capture refetch from useTokens / useValidators, and trigger refetches when a newer block is observed.

Sequence Diagram(s)

Tokens page:

sequenceDiagram
  participant useLatestBlock
  participant useRefetchOnNewBlock
  participant useTokens
  useLatestBlock->>useRefetchOnNewBlock: head?.number advances
  useRefetchOnNewBlock->>useTokens: call refetch() when throttle window allows
Loading

Validators page:

sequenceDiagram
  participant useLatestBlock
  participant useRefetchOnNewBlock
  participant useValidators
  useLatestBlock->>useRefetchOnNewBlock: head?.number advances
  useRefetchOnNewBlock->>useValidators: call refetch() when throttle window allows
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Sentriscloud/frontend#100: Also changes apps/scan/app/[locale]/validators/page.tsx data-fetching wiring and refresh-related hook usage on the same page.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: refreshing validators and tokens on new blocks.
Description check ✅ Passed The description covers the summary and testing, but it does not use the repository's exact Summary/Test plan/Related template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/scan-ws-refresh

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/scan/lib/ws.ts (1)

168-183: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Hook logic is sound; two behavioral nuances worth confirming.

The throttle is correct and won't flood (one refetch per minIntervalMs, no re-render loop since the dep is the primitive head?.number). Two points to confirm are intended:

  1. Leading-edge throttle with drop, no trailing call. A block that lands inside the throttle window is dropped, not deferred. On fast chains the next block after the window triggers the refresh, so freshness is fine; if blocks go quiet right after a dropped one, the page only updates on the next poll (15s/30s). That polling fallback makes this acceptable, just worth acknowledging.

  2. refetch excluded from deps is an implicit caller contract. This is safe for useTokens/useValidators today because their refetch identity only changes on network change, which also resets head and re-runs the effect with the fresh closure. But the hook silently assumes a stable refetch; an inline/unstable refetch from a future caller would go stale. Consider documenting that in the hook comment.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/scan/lib/ws.ts` around lines 168 - 183, Document the caller contract for
useRefetchOnNewBlock: it uses a leading-edge throttle with dropped intermediate
blocks and intentionally omits refetch from the effect deps, so callers must
pass a stable refetch. Add a brief note near useRefetchOnNewBlock explaining
that useTokens and useValidators are safe because their refetch is
network-stable, and that inline/unstable refetch functions would become stale.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@apps/scan/lib/ws.ts`:
- Around line 168-183: Document the caller contract for useRefetchOnNewBlock: it
uses a leading-edge throttle with dropped intermediate blocks and intentionally
omits refetch from the effect deps, so callers must pass a stable refetch. Add a
brief note near useRefetchOnNewBlock explaining that useTokens and useValidators
are safe because their refetch is network-stable, and that inline/unstable
refetch functions would become stale.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4d4a3011-61f3-4f76-afb8-16a085cd0fce

📥 Commits

Reviewing files that changed from the base of the PR and between 95347bb and e6cb823.

📒 Files selected for processing (3)
  • apps/scan/app/[locale]/tokens/page.tsx
  • apps/scan/app/[locale]/validators/page.tsx
  • apps/scan/lib/ws.ts

@github-actions github-actions Bot merged commit b03fa31 into main Jun 25, 2026
7 checks passed
@satyakwok satyakwok deleted the feat/scan-ws-refresh branch June 25, 2026 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant