feat(frontend): add useInterval hook and real-time balance polling on user dashboard#492
Open
mandyslovestories-sudo wants to merge 2 commits into
Conversation
- Create useInterval(callback, delay) hook with stable callback ref pattern — no stale closures, no double-fetch on mount - delay=null suspends polling without unmounting; resumes when set - NEXT_PUBLIC_POLL_INTERVAL_MS env var overrides default 30s interval - Replace raw pollRef/setInterval block in user dashboard with useInterval - Polling pauses automatically when wallet disconnects or no meters loaded - Remove unused useRef import from dashboard page - Add useInterval.test.ts: 8 cases covering no-fire-on-mount, interval cadence, unmount cleanup, null pause, latest-callback, delay change, null-to-number resume Closes Dev-AdeTutu#400
|
@mandyslovestories-sudo Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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\n\nCloses #400\n\nReplaces the raw setInterval/pollRef pattern in the user dashboard with a proper reusable useInterval hook, adds NEXT_PUBLIC_POLL_INTERVAL_MS env override, and guarantees no double-fetch on first render.\n\n## Changes\n\nhooks/useInterval.ts (new)\n- useInterval(callback, delay) with stable useRef callback pattern\n- delay=null suspends interval without unmounting; resumes on change\n- Cleans up on unmount automatically\n- Does NOT fire on mount — initial fetch stays in useEffect\n\ndashboard/user/page.tsx\n- Import and wire useInterval for balance polling\n- NEXT_PUBLIC_POLL_INTERVAL_MS env var overrides the 30s default\n- Polling pauses automatically when wallet disconnects or no meters loaded\n- Remove unused useRef import and raw setInterval block\n\nuseInterval.test.ts (new — 8 cases)\n- No fire on mount\n- Fires at correct interval cadence\n- Stops on unmount\n- Pauses on null delay\n- Uses latest callback (no stale closure)\n- Restarts when delay changes\n- Resumes when delay goes from null to number\n\n## Definition of Done\n- [x] useInterval hook created and exported\n- [x] Balance refreshes every 30s on dashboard\n- [x] Polling stops when component unmounts\n- [x] NEXT_PUBLIC_POLL_INTERVAL_MS env var overrides default interval\n- [x] No double-fetch on first render