Separate update fiat rate in a function to enhance readability [skip ci]

This commit is contained in:
OmarHatem 2022-12-09 19:41:54 +02:00
parent ae1d2a3bec
commit 5310c265a7

View file

@ -15,26 +15,28 @@ Future<void> startFiatRateUpdate(
return; return;
} }
if (appStore.wallet != null && settingsStore.fiatApiMode == FiatApiMode.enabled) { _updateFiatRate(appStore, settingsStore, fiatConversionStore);
fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice(
appStore.wallet!.currency, settingsStore.fiatCurrency);
}
_timer = Timer.periodic(Duration(seconds: 30), (_) async { _timer = Timer.periodic(Duration(seconds: 30), (_) async {
if (settingsStore.fiatApiMode == FiatApiMode.disabled) {
return;
}
try { try {
if (appStore.wallet!.type == WalletType.haven) { if (appStore.wallet!.type == WalletType.haven) {
await updateHavenRate(fiatConversionStore); await updateHavenRate(fiatConversionStore);
} else { } else {
fiatConversionStore.prices[appStore.wallet!.currency] = _updateFiatRate(appStore, settingsStore, fiatConversionStore);
await FiatConversionService.fetchPrice(
appStore.wallet!.currency, settingsStore.fiatCurrency);
} }
} catch (e) { } catch (e) {
print(e); print(e);
} }
}); });
} }
void _updateFiatRate(
AppStore appStore,
SettingsStore settingsStore,
FiatConversionStore fiatConversionStore,
) async {
if (appStore.wallet != null && settingsStore.fiatApiMode == FiatApiMode.enabled) {
fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice(
appStore.wallet!.currency, settingsStore.fiatCurrency);
}
}