Skip to content

Core implement offline first with queue and sync#28

Merged
EmeditWeb merged 3 commits into
StepFi-app:mainfrom
OG-wura:core_implement_offline_first_with_queue_and_sync
Jun 17, 2026
Merged

Core implement offline first with queue and sync#28
EmeditWeb merged 3 commits into
StepFi-app:mainfrom
OG-wura:core_implement_offline_first_with_queue_and_sync

Conversation

@OG-wura

@OG-wura OG-wura commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Close #12

PR description:
Summary
Implements offline support for the StepFi app. When the device loses connectivity, mutation requests (repay, deposit, vouch, create loan, submit signed XDR) are queued to persisted storage and automatically replayed when connectivity is restored. GET responses are cached with a 5-minute TTL and served from cache on network failure to allow browsing previously loaded data offline.
Changes
New modules (src/offline/)

  • cache.ts — AsyncStorage-backed response cache with configurable TTL (default 5 min). Stores { data, timestamp, ttl } entries keyed by GET:.
  • offline-queue.ts — Persisted FIFO action queue. Supports enqueueAction, dequeueAction, getQueue, clearQueue. Each action stores { id, type, endpoint, method, data, timestamp }.
  • offline-sync.ts — Queue processor. Iterates over queued actions sequentially via api.request(), removes successfully replayed ones, emits sync:start/complete/error/progress events for UI feedback.
  • connectivity.store.ts — Zustand store tracking isConnected, connectionType, isInternetReachable, updated by the NetInfo listener in the root layout.
    New hook
  • hooks/useConnectivity.ts — React hook exposing { isConnected, connectionType, isInternetReachable } from the connectivity store.
    Modified files
  • services/api.ts — Three interceptor additions:
  1. Request interceptor (mutations): Checks connectivity.store; if offline, queues the action via enqueueAction and rejects the request with __offline_queued.
  2. Response success interceptor: Caches all successful GET responses.
  3. Response error interceptor: Returns mock 202 for offline-queued mutations (avoids error in caller); serves cached data for failed GET requests; existing 401/refresh flow unchanged.
  • app/_layout.tsx — On mount, fetches initial NetInfo state and subscribes to connectivity changes. Updates the connectivity store on every change. When transitioning from offline → online, triggers processQueue() to drain the action queue.
    Dependencies added
  • @react-native-community/netinfo
  • @react-native-async-storage/async-storage
    Verification
  • TypeScript: no new errors (npx tsc --noEmit)
  • Lint: no new errors (npx eslint)
  • All pre-existing errors (Node v18 Metro compat, CalendarSourceType) are unrelated

@EmeditWeb EmeditWeb merged commit 0d70468 into StepFi-app:main Jun 17, 2026
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.

core: implement offline-first with queue and sync

2 participants