From 5310c265a77e9facb44e88edfc469ca4f833015a Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 9 Dec 2022 19:41:54 +0200 Subject: [PATCH] Separate update fiat rate in a function to enhance readability [skip ci] --- lib/reactions/fiat_rate_update.dart | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/reactions/fiat_rate_update.dart b/lib/reactions/fiat_rate_update.dart index 99a3bc4ae..70387be97 100644 --- a/lib/reactions/fiat_rate_update.dart +++ b/lib/reactions/fiat_rate_update.dart @@ -15,26 +15,28 @@ Future startFiatRateUpdate( return; } - if (appStore.wallet != null && settingsStore.fiatApiMode == FiatApiMode.enabled) { - fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice( - appStore.wallet!.currency, settingsStore.fiatCurrency); - } + _updateFiatRate(appStore, settingsStore, fiatConversionStore); _timer = Timer.periodic(Duration(seconds: 30), (_) async { - if (settingsStore.fiatApiMode == FiatApiMode.disabled) { - return; - } - try { if (appStore.wallet!.type == WalletType.haven) { await updateHavenRate(fiatConversionStore); } else { - fiatConversionStore.prices[appStore.wallet!.currency] = - await FiatConversionService.fetchPrice( - appStore.wallet!.currency, settingsStore.fiatCurrency); + _updateFiatRate(appStore, settingsStore, fiatConversionStore); } } catch (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); + } +}