Skip to content

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

Open
sirpy wants to merge 3 commits into
mainfrom
feat-inactivity
Open

sirpy wants to merge 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 a review from L03TJ3 October 12, 2026 08:26

This branch has not been deployed

No deployments
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.

3 participants