Skip to content

feat: add inactivity detection to stop background API calls - #73

Merged
sirpy merged 3 commits into
mainfrom
feat-inactivity
Oct 13, 2026
Merged

sirpy merged 3 commits into
mainfrom
feat-inactivity

Conversation

@sirpy

@sirpy sirpy commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements inactivity detection to prevent unnecessary background API calls when the wallet tab is left open but inactive.

Changes

  • Create inactivityStore: Tracks user interactions (mouse, keyboard, touch, scroll) and determines wallet activity status
  • Stop API polling on inactivity: Pauses balance and token fetches after 5 minutes of inactivity
  • Add focus checks: Updated amountsStore and tokensStore to respect both window focus and inactivity state
  • Auto-resume on interaction: Polling resumes immediately when user interacts with the page

Problem Solved

Previously, the wallet would continue making background API calls (balance checks for Bitcoin/Doge) even when left idle in a tab, consuming bandwidth and rate limits.

Configuration

Inactivity timeout is configurable via inactivityStore.inactivityTimeoutMs (currently 5 minutes).

Files Changed

  • src/hooks/useTokenBalances/stores/inactivityStore.ts (new)
  • src/hooks/useTokenBalances/stores/amountsStore.ts
  • src/hooks/useTokenBalances/stores/tokensStore.ts
  • src/app/api/chains/[family]/addresses/[address]/balance/route.ts

- Create inactivityStore to track user interactions (mouse, keyboard, touch, scroll)
- Stop API polling when tab is inactive for 5+ minutes
- Add inactivity check to amountsStore and tokensStore
- Prevents unnecessary background balance/token fetches
- Resumes immediately on user interaction

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Server evaluation can crash, and skipped token refreshes do not resume immediately.

2 open findings
What changed in this PR

Adds inactivity-aware polling to reduce background wallet API calls.

Changes:

  • Tracks user activity with a configurable timeout.
  • Pauses token and balance polling when unfocused or inactive.
  • Adds CDN-specific balance caching headers.
File Description
inactivityStore.ts Tracks interactions and inactivity state.
amountsStore.ts Pauses balance polling during inactivity.
tokensStore.ts Pauses hourly token polling.
route.ts Configures CDN balance caching.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/hooks/useTokenBalances/stores/inactivityStore.ts Outdated
Comment thread src/hooks/useTokenBalances/stores/tokensStore.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: sirpy <hadarr@gmail.com>
Co-authored-by: sirpy <671095+sirpy@users.noreply.github.com>
@sirpy
sirpy enabled auto-merge (squash) October 12, 2026 08:25
@sirpy
sirpy requested review from L03TJ3 and a balanced review from Copilot October 12, 2026 08:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Due balance refreshes are not triggered immediately when activity resumes.

0 open findings

2 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Medium severity Resume activity does not immediately trigger due balance refresh

src/​hooks/​useTokenBalances/​stores/​amountsStore.ts:104

Balance polling does not perform the stated immediate catch-up when activity resumes. An interaction changes isActive, but this code is only re-evaluated by the 10-second timer, so a due balance refresh remains stale until that timer fires. Subscribe the same due-check callback to the focus/activity stores, as tokensStore now does.

🧠 Review effort: Balanced

@sirpy
sirpy merged commit f7ebcae into main Oct 13, 2026
3 checks passed
@sirpy
sirpy deleted the feat-inactivity branch October 13, 2026 11:59
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.

4 participants