Skip to content

fix(frontend): ensure isLive is false whenever polling is the active source (Closes #904) - #923

Merged
Topmatrixmor2014 merged 1 commit into
FinChippay:mainfrom
waterWang:fix/balance-stream-live-state-904
Aug 26, 2026
Merged

fix(frontend): ensure isLive is false whenever polling is the active source (Closes #904)#923
Topmatrixmor2014 merged 1 commit into
FinChippay:mainfrom
waterWang:fix/balance-stream-live-state-904

Conversation

@waterWang

Copy link
Copy Markdown
Contributor

Summary

Fixes #904 — the useBalanceStream hook could leave isLive: true on the UI even when polling was the active data source, or carry a stale "live" badge across account switches.

Root cause

startPolling() was never asserting setIsLive(false). It is reached from several paths that skip closeSource():

  • No EventSource support
  • No SEP-10 token after refresh
  • Ticket-fetch failure
  • new EventSource(...) construction failure

In all of those the consumer's isLive indicator was left at whatever the previous session/account had set it to, so a "live" badge could persist while polling was actually running.

Changes

frontend/lib/useBalanceStream.ts

  • startPolling now explicitly calls setIsLive(false) so polling as the active source is always reflected in the consumer-facing indicator.

frontend/__tests__/balance-stream.test.tsx

  • Added 3 targeted tests for #127 — SSE Endpoint Fallback to Polling Never Clears on Reconnect Failure #904:
    1. isLive drops to false after a stream error hands over to polling.
    2. A stale reconnect (late balance event) from an old account cannot flip isLive back on.
    3. Account switches cleanly reset the live flag before the new stream delivers anything.
  • Fixed pre-existing stale assertions (token=ticket= after the short-lived-ticket auth change) and added an apiFetch mock so SSE tests can actually construct EventSource instances.

Verification

  • npm test -- __tests__/balance-stream.test.tsx16/16 passing
  • lint + type-check run clean

…source (Closes FinChippay#904)

- startPolling now explicitly sets isLive(false) so that polling is the
  active data source is always reflected in the consumer-facing indicator.
- Adds 3 targeted tests for FinChippay#904:
  1. isLive drops after a stream error hands over to polling
  2. A stale reconnect from an old account cannot flip isLive back on
  3. Account switches cleanly reset the live flag before the new stream
     delivers anything
- Fixes stale test assertions (token= -> ticket=) and adds apiFetch mock
  so SSE tests can actually create EventSource instances.
@github-actions github-actions Bot added the needs-review PR ready for Greptile AI code review label Aug 26, 2026
@github-actions

Copy link
Copy Markdown

🤖 Greptile AI Code Review

Greptile will automatically review this PR (2 file(s) changed).

Review gates:

  • ✅ CodeQL Security Scan
  • ✅ Custom rules (.greptile/config.json)
  • ✅ Architecture guidelines (.greptile/rules.md)

To manually trigger a re-review, comment @greptileai on this PR.
To skip review, add the skip-review label.

@Topmatrixmor2014
Topmatrixmor2014 merged commit 52bacd9 into FinChippay:main Aug 26, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review PR ready for Greptile AI code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#127 — SSE Endpoint Fallback to Polling Never Clears on Reconnect Failure

2 participants