mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-17 05:41:29 +02:00
CW-441 xmr price issue (#1005)
* refactor fiat_rate_update * remove commented line
This commit is contained in:
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user