CW-441 xmr price issue (#1005)

* refactor fiat_rate_update

* remove commented line
This commit is contained in:
Matthew Fosse 2023-07-26 21:08:12 -04:00 committed by GitHub
parent da2f1c62f5
commit b28f85350a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import 'package:cake_wallet/store/app_store.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
Timer? _timer;
@ -15,7 +16,7 @@ Future<void> startFiatRateUpdate(
return;
}
_timer = Timer.periodic(Duration(seconds: 30), (_) async {
final _updateFiat = (_) async {
try {
if (appStore.wallet == null || settingsStore.fiatApiMode == FiatApiMode.disabled) {
return;
@ -33,5 +34,20 @@ Future<void> startFiatRateUpdate(
} catch (e) {
print(e);
}
};
_timer = Timer.periodic(Duration(seconds: 30), _updateFiat);
// also run immediately:
_updateFiat(null);
// setup autorun to listen to changes in fiatApiMode
autorun((_) {
// restart the timer if fiatApiMode was re-enabled
if (settingsStore.fiatApiMode != FiatApiMode.disabled) {
_timer = Timer.periodic(Duration(seconds: 30), _updateFiat);
_updateFiat(null);
} else {
_timer?.cancel();
}
});
}

View file

@ -66,7 +66,8 @@ abstract class BalanceViewModelBase with Store {
final price = fiatConvertationStore.prices[appStore.wallet!.currency];
if (price == null) {
throw Exception('No price for ${appStore.wallet!.currency} (current wallet)');
// price should update on next fetch:
return 0;
}
return price;