You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: add inactivity detection to stop background API calls - #73
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).
- 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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements inactivity detection to prevent unnecessary background API calls when the wallet tab is left open but inactive.
Changes
amountsStoreandtokensStoreto respect both window focus and inactivity stateProblem 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.tssrc/hooks/useTokenBalances/stores/tokensStore.tssrc/app/api/chains/[family]/addresses/[address]/balance/route.ts