Skip to content

FX Implementation Summary

Masked-Kunsiquat edited this page Dec 25, 2025 · 4 revisions

FX Implementation Summary

This page summarizes the FX (multi-currency) system for CrewSplit.

Goals

  • Offline-first conversions using cached rates
  • Deterministic math for reproducible settlements
  • Clear audit trail of which rates were used

Schema Overview

fx_rates

Stores cached exchange rates from multiple sources.

  • Key fields: base_currency, quote_currency, rate, source, fetched_at, priority
  • Manual rates win via higher priority
  • Soft deletes preserve auditability

fx_rate_snapshots (optional)

Links trips to specific rates used at the time of settlement or export.

Rate Selection Rules

  1. Same currency: return 1.0 and skip DB lookup.
  2. Direct rate lookup (base -> quote) with priority + recency ordering.
  3. Inverse lookup (quote -> base) and use 1/rate.
  4. If missing, prompt for manual rate entry.

Data Flow (High Level)

  • Fetch rates when online and stale
  • Store rates in SQLite
  • Convert amounts on read using cached rates
  • Persist original + converted amounts for auditability

UI Integration Notes

  • Show a staleness warning when rates are old
  • Provide manual entry for missing pairs
  • Display both original and converted amounts

References

Clone this wiki locally