Skip to content

feat(frontend): add useInterval hook and real-time balance polling on user dashboard#492

Open
mandyslovestories-sudo wants to merge 2 commits into
Dev-AdeTutu:mainfrom
mandyslovestories-sudo:feat/balance-polling-use-interval
Open

feat(frontend): add useInterval hook and real-time balance polling on user dashboard#492
mandyslovestories-sudo wants to merge 2 commits into
Dev-AdeTutu:mainfrom
mandyslovestories-sudo:feat/balance-polling-use-interval

Conversation

@mandyslovestories-sudo

Copy link
Copy Markdown
Contributor

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

- 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
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

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