mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 01:37:40 +00:00
CW-441 xmr price issue (#1005)
* refactor fiat_rate_update * remove commented line
This commit is contained in:
parent
da2f1c62f5
commit
b28f85350a
2 changed files with 19 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue