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

OmarHatem committed Dec 9, 2022 at 19:41 UTC 5310c265a77e9facb44e88edfc469ca4f833015a
1 file changed +13 -11
lib/reactions/fiat_rate_update.dart
+13 -11
@@ -15,26 +15,28 @@ Future<void> startFiatRateUpdate(
15 return;
16 }
17
18 - if (appStore.wallet != null && settingsStore.fiatApiMode == FiatApiMode.enabled) {
19 - fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice(
20 - appStore.wallet!.currency, settingsStore.fiatCurrency);
21 - }
18 + _updateFiatRate(appStore, settingsStore, fiatConversionStore);
19
20 _timer = Timer.periodic(Duration(seconds: 30), (_) async {
24 - if (settingsStore.fiatApiMode == FiatApiMode.disabled) {
25 - return;
26 - }
27 -
21 try {
22 if (appStore.wallet!.type == WalletType.haven) {
23 await updateHavenRate(fiatConversionStore);
24 } else {
32 - fiatConversionStore.prices[appStore.wallet!.currency] =
33 - await FiatConversionService.fetchPrice(
34 - appStore.wallet!.currency, settingsStore.fiatCurrency);
25 + _updateFiatRate(appStore, settingsStore, fiatConversionStore);
26 }
27 } catch (e) {
28 print(e);
29 }
30 });
31 }
32 +
33 +void _updateFiatRate(
34 + AppStore appStore,
35 + SettingsStore settingsStore,
36 + FiatConversionStore fiatConversionStore,
37 +) async {
38 + if (appStore.wallet != null && settingsStore.fiatApiMode == FiatApiMode.enabled) {
39 + fiatConversionStore.prices[appStore.wallet!.currency] = await FiatConversionService.fetchPrice(
40 + appStore.wallet!.currency, settingsStore.fiatCurrency);
41 + }
42 +}