fetchRates method

  1. @override
Future<Map<String, double>> fetchRates(
  1. String base
)
override

Fetches exchange rates for the given base currency.

Returns a map of currency codes to their exchange rates relative to base. For example, if base is 'USD', the map might contain {'EUR': 0.92, 'GBP': 0.79, ...}.

Implementation

@override
Future<Map<String, double>> fetchRates(String base) async {
  try {
    final doc = await _firestore.collection('exchange_rates').doc(base).get();

    if (!doc.exists || doc.data() == null) {
      return _fallback.fetchRates(base);
    }

    final data = doc.data()!;
    final rates = data['rates'] as Map<String, dynamic>?;

    if (rates == null || rates.isEmpty) {
      return _fallback.fetchRates(base);
    }

    return rates.map((k, v) => MapEntry(k, (v as num).toDouble()));
  } catch (_) {
    return _fallback.fetchRates(base);
  }
}