Issue #13 — Offline-First Capabilities Enhancement
Labels: frontend feature pwa offline
Summary
Enhance the Progressive Web App capabilities to provide a robust offline experience, including offline transaction queuing, cached account data, and background sync when connectivity returns.
Background
The app has basic PWA support with frontend/public/manifest.json, frontend/public/sw.js (service worker), and an OfflineBanner component. The offlineQueue.ts library exists but has limited functionality. The useNetworkStatus hook monitors connectivity.
Problem Statement
Users in regions with unreliable connectivity cannot reliably use Finchippay. When offline, the app shows a banner but provides no functionality — users cannot prepare transactions, review history, or manage their portfolio.
Objectives
- Implement a full offline transaction queue with IndexedDB persistence.
- Enhance the service worker with strategic caching (app shell, API responses, asset data).
- Build an offline transaction composer that queues transactions for submission when online.
- Add background sync for automatic queue processing.
- Write tests for offline queue and service worker caching.
Scope
- In scope: offline queue, service worker caching, offline composer, background sync.
- Out of scope: full offline transaction signing (requires Freighter), offline contract interactions.
Detailed Implementation Requirements
-
Offline queue enhancement: Update frontend/lib/offlineQueue.ts:
- Store pending transactions in IndexedDB (use
idb-keyval or raw IndexedDB).
- Each queue entry:
{ id, type, payload, createdAt, status (pending/processing/failed), retryCount }.
- Methods:
enqueue(type, payload), dequeue(), peek(), remove(id), getAll(), getFailed().
- Max 3 retries per entry with exponential backoff.
-
Service worker update: Enhance frontend/public/sw.js:
- Cache-first strategy for static assets (JS, CSS, images).
- Network-first with cache fallback for API responses (balance, transactions).
- Stale-while-revalidate for price feeds.
- Cache invalidation on new service worker activation.
- Offline fallback page (
/offline).
-
Offline composer: Create frontend/components/OfflineTransactionComposer.tsx:
- Full send form that works without network.
- Validates addresses locally (regex).
- Stores composed transaction in offline queue.
- Shows queue status and pending count.
- Background sync registers a
sync event for automatic processing.
-
Connectivity-aware UI:
- Update
OfflineBanner.tsx to show pending queue count.
- Add offline badge to transaction list showing queued items.
- Show toast when transactions are auto-submitted on reconnection.
-
Background sync: Register sync event listener in service worker. On sync event, process the offline queue in FIFO order. Use the sync tag "process-transaction-queue".
-
Tests: Create frontend/__tests__/offlineQueue.test.ts with tests for enqueue/dequeue, retry logic, persistence across page reloads. Update Playwright e2e tests in frontend/e2e/offline.spec.ts.
Expected Architecture
frontend/
├── public/
│ └── sw.js (UPDATE: cache strategies, background sync)
├── lib/
│ └── offlineQueue.ts (UPDATE: IndexedDB, retry, sync)
├── components/
│ ├── OfflineBanner.tsx (UPDATE: queue count badge)
│ └── OfflineTransactionComposer.tsx (NEW)
├── pages/
│ └── offline.tsx (NEW: offline fallback page)
├── hooks/
│ └── useNetworkStatus.ts (UPDATE: queue integration)
└── __tests__/
└── offlineQueue.test.ts (NEW)
Acceptance Criteria
Issue #13 — Offline-First Capabilities Enhancement
Labels:
frontendfeaturepwaofflineSummary
Enhance the Progressive Web App capabilities to provide a robust offline experience, including offline transaction queuing, cached account data, and background sync when connectivity returns.
Background
The app has basic PWA support with
frontend/public/manifest.json,frontend/public/sw.js(service worker), and anOfflineBannercomponent. TheofflineQueue.tslibrary exists but has limited functionality. TheuseNetworkStatushook monitors connectivity.Problem Statement
Users in regions with unreliable connectivity cannot reliably use Finchippay. When offline, the app shows a banner but provides no functionality — users cannot prepare transactions, review history, or manage their portfolio.
Objectives
Scope
Detailed Implementation Requirements
Offline queue enhancement: Update
frontend/lib/offlineQueue.ts:idb-keyvalor raw IndexedDB).{ id, type, payload, createdAt, status (pending/processing/failed), retryCount }.enqueue(type, payload),dequeue(),peek(),remove(id),getAll(),getFailed().Service worker update: Enhance
frontend/public/sw.js:/offline).Offline composer: Create
frontend/components/OfflineTransactionComposer.tsx:syncevent for automatic processing.Connectivity-aware UI:
OfflineBanner.tsxto show pending queue count.Background sync: Register
syncevent listener in service worker. Onsyncevent, process the offline queue in FIFO order. Use thesynctag"process-transaction-queue".Tests: Create
frontend/__tests__/offlineQueue.test.tswith tests for enqueue/dequeue, retry logic, persistence across page reloads. Update Playwright e2e tests infrontend/e2e/offline.spec.ts.Expected Architecture
Acceptance Criteria