Update API references from OpenExchange to ForexRateAPI in code and documentation

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-19 20:46:58 +01:00
parent fc3cbb0b5d
commit a1f67e71e2
4 changed files with 95 additions and 27 deletions
+26 -14
View File
@@ -13,7 +13,7 @@ import 'package:rental_income_tracker/services/storage_service.dart';
import 'package:rental_income_tracker/services/time_service.dart';
import 'package:timezone/timezone.dart' as tz;
const String openExchangeApiKey = 'REPLACE_WITH_YOUR_OPENEXCHANGE_API_KEY';
const String forexRateApiKey = 'REPLACE_WITH_YOUR_FOREXRATE_API_KEY';
class RentTableRow {
RentTableRow({
@@ -40,19 +40,19 @@ class RentTableRow {
class RentController extends ChangeNotifier {
RentController({
StorageService? storageService,
OpenExchangeService? exchangeService,
ForexRateApiService? exchangeService,
}) : _storageService = storageService ?? StorageService(),
_exchangeService =
exchangeService ??
OpenExchangeService(
ForexRateApiService(
httpClient: http.Client(),
apiKey: openExchangeApiKey,
apiKey: forexRateApiKey,
) {
_notificationService = NotificationService(_onNotificationAction);
}
final StorageService _storageService;
final OpenExchangeService _exchangeService;
final ForexRateApiService _exchangeService;
late NotificationService _notificationService;
AppSettings _settings = AppSettings.defaults();
@@ -146,12 +146,21 @@ class RentController extends ChangeNotifier {
throw StateError('Set rent amount in Settings before marking paid.');
}
final key = TimeService.monthKey(year, month);
if (_records.containsKey(key)) {
await _notificationService.cancelForMonth(year, month);
await _syncNotificationScheduleForCurrentMonth();
return;
}
final paidAt = DateTime.now().toUtc();
final usd = _settings.rentUsd;
final estPaidAt = tz.TZDateTime.from(paidAt, TimeService.est);
final estDate = DateTime(estPaidAt.year, estPaidAt.month, estPaidAt.day);
final rate = await _exchangeService.fetchUsdToSekRate(estDate: estDate);
final usd = _settings.rentUsd;
final sek = usd * rate;
final conversion = await _exchangeService.convertUsdToSek(
estDate: estDate,
amount: usd,
);
final onTime =
assumeOnTime || TimeService.isOnTimeByDeadline(paidAt, year, month);
@@ -159,8 +168,8 @@ class RentController extends ChangeNotifier {
year: year,
month: month,
usdAmount: usd,
sekAmount: sek,
usdToSekRate: rate,
sekAmount: conversion.result,
usdToSekRate: conversion.quote,
paidAtUtc: paidAt,
onTime: onTime,
source: source,
@@ -194,9 +203,12 @@ class RentController extends ChangeNotifier {
continue;
}
final estDate = DateTime(year, month, 1);
final rate = await _exchangeService.fetchUsdToSekRate(estDate: estDate);
final usd = _settings.rentUsd;
final estDate = DateTime(year, month, 1);
final conversion = await _exchangeService.convertUsdToSek(
estDate: estDate,
amount: usd,
);
final paidAtUtc = tz.TZDateTime(
TimeService.est,
@@ -210,8 +222,8 @@ class RentController extends ChangeNotifier {
year: year,
month: month,
usdAmount: usd,
sekAmount: usd * rate,
usdToSekRate: rate,
sekAmount: conversion.result,
usdToSekRate: conversion.quote,
paidAtUtc: paidAtUtc,
onTime: true,
source: 'backfill',