Repository navigation
[Frontend] Optimistic UI State Engine & IndexedDB Offline Stream Cache #1473
Copy link
Copy link
Closed
Labels
Stellar WaveIssues in the Stellar wave programIssues in the Stellar wave programdrips-wavefrontendFrontend related tasksFrontend related tasksperformancepwa
Description
Overview & Background
In Web3 applications, blockchain transactions and indexer synchronization introduce latency (typically 3 to 10 seconds on Stellar/Soroban). Users who submit transactions (create stream, withdraw, top-up, pause) experience an awkward delay where the UI remains stale or shows blocking loading spinners until the transaction confirms and the backend indexer processes the event. Implementing an Optimistic UI state engine paired with client-side IndexedDB caching delivers instantaneous feedback and fluid user experience.
Detailed Problem Statement
- Perceived Latency & UI Freezes:
- Submitting a withdrawal currently forces the user to wait for ledger inclusion and API polling before the balance updates on screen.
- Cold-Start Latency:
- Every page refresh queries the backend REST endpoints from scratch, causing empty skeletons or layout shifts while data is fetched.
- Flaky Network Disconnects:
- Users on intermittent mobile connections or high-latency networks cannot view their existing streams or draft transactions if offline.
Technical Specification & Architecture
1. IndexedDB Persistence Layer (Dexie.js or idb-keyval)
Implement frontend/src/lib/storage/stream-cache.ts:
- Schema:
cached_streams: Primary store keyed bystreamId, indexed bysender,recipient,tokenAddress,updatedAt.optimistic_mutations: Store of pending user actions (CREATE,WITHDRAW,TOP_UP,CANCEL,PAUSE).
- Cache lifecycle:
- On app load: Read instantly from IndexedDB to hydrate React Query / Zustand stores in < 15ms.
- Background sync: Query backend API / SSE / WebSocket in the background and reconcile stale entries.
2. Optimistic Mutation Engine
- When a user submits an action (e.g.
withdraw(streamId, amount)):- Generate an ephemeral optimistic patch updating
stream.withdrawnAmount += amountandstream.claimableAmount -= amount. - Instantly re-render the UI with optimistic state and attach a subtle "Pending Ledger Confirmation" pulse badge.
- Store the optimistic patch in
optimistic_mutations.
- Generate an ephemeral optimistic patch updating
- Reconciliation:
- When the indexer event arrives via SSE or transaction hash is confirmed by RPC, replace the optimistic state with the canonical on-chain record.
- If the transaction reverts or fails on-chain, automatically roll back the optimistic patch and display an actionable toast error.
3. Continuous Ticker Synchronization
- Ensure the real-time claimable balance ticker integrates seamlessly with optimistic mutations without jumping backward or jittering.
Target Files
frontend/src/lib/storage/stream-cache.tsfrontend/src/context/StreamContext.tsxfrontend/src/hooks/useOptimisticStream.tsfrontend/src/components/dashboard/StreamCard.tsxfrontend/src/__tests__/optimistic-ui.test.tsx
Acceptance Criteria
- Application loads and renders cached streams from IndexedDB immediately on launch without waiting for network responses.
- Submitting stream mutations (withdraw, top-up, cancel) immediately updates the UI without blocking spinners.
- Pending optimistic state displays a non-intrusive status indicator.
- Canonical indexer updates silently reconcile optimistic values without UI flicker.
- Simulated transaction failures trigger a clean rollback to prior state and show explanatory error toast.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Stellar WaveIssues in the Stellar wave programIssues in the Stellar wave programdrips-wavefrontendFrontend related tasksFrontend related tasksperformancepwa
Activity
Ayomide3271 commentedon Sep 27, 2026
@Ayomide3271 has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Ayomide3271 to this issue.
bright5455 commentedon Sep 27, 2026
@bright5455 has applied to work on this issue as part of the Stellar Wave Program's 9th wave.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @bright5455 to this issue.
drips-wave commentedon Sep 29, 2026
Congratulations, @bright5455! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on September 30, 2026.
🧑💻 @bright5455: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.
Warning
When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.
🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.
🌊 Happy Wave 🌊
grantfox-oss commentedon Oct 10, 2026
🎉 This issue has been marked as completed on GrantFox!
@bright5455's PR #1585 was approved and merged by @K1NGD4VID.
🏆 @bright5455: You earned 40 FoxPoints for this contribution! Your current tier: Builder (1,249 total points). Track your full progress on GrantFox.
👏 Great work, @bright5455! Keep contributing to LabsCrypt.