Make balance and stream state update in real time with optimistic UI, while recovering gracefully from SSE disconnects and reconciling with the server.
Requirements and Context
frontend/lib/useBalanceStream.ts and backend/src/services/balanceStreamService.js already provide a streaming balance path. The frontend still relies on polling in places, and there is no unified optimistic-update/reconnect story: a dropped SSE connection can leave stale balances on screen, or a slow network can make a payment appear not to have registered.
Objectives
- Unify balance/stream updates on the SSE feed with automatic reconnect + exponential backoff.
- Apply optimistic updates on user actions (send/claim) and roll back on server error.
- Reconcile on reconnect (fetch authoritative state and diff against the UI).
- Surface connection state (live / reconnecting / stale) in the UI.
Suggested Execution
git checkout -b feat/realtime-sync.
- Extend
useBalanceStream.ts with reconnect/backoff and a reconciliation hook.
- Wire optimistic updates into
SendPaymentForm.tsx / StreamingPayments.tsx.
- Add
frontend/__tests__/useBalanceStream.test.ts and run npm run type-check && npm test.
Acceptance Criteria
Guidelines
- Keep the existing
balanceStreamService.js contract; this is primarily a frontend hook/state issue.
- Avoid optimistic updates for irreversible actions (show "processing" instead).
Timeframe: 96 hours
Requirements and Context
frontend/lib/useBalanceStream.tsandbackend/src/services/balanceStreamService.jsalready provide a streaming balance path. The frontend still relies on polling in places, and there is no unified optimistic-update/reconnect story: a dropped SSE connection can leave stale balances on screen, or a slow network can make a payment appear not to have registered.Objectives
Suggested Execution
git checkout -b feat/realtime-sync.useBalanceStream.tswith reconnect/backoff and a reconciliation hook.SendPaymentForm.tsx/StreamingPayments.tsx.frontend/__tests__/useBalanceStream.test.tsand runnpm run type-check && npm test.Acceptance Criteria
Guidelines
balanceStreamService.jscontract; this is primarily a frontend hook/state issue.Timeframe: 96 hours