cake_wallet/lib/reactions/on_wallet_sync_status_change.dart

39 lines
1.4 KiB
Dart
Raw Normal View History

2022-03-30 15:57:04 +00:00
import 'package:cake_wallet/entities/update_haven_rate.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cw_core/wallet_type.dart';
2020-09-21 11:50:26 +00:00
import 'package:mobx/mobx.dart';
2021-12-24 12:37:24 +00:00
import 'package:cw_core/transaction_history.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/balance.dart';
import 'package:cw_core/transaction_info.dart';
import 'package:cw_core/sync_status.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
2020-09-21 11:50:26 +00:00
2022-10-12 17:09:57 +00:00
ReactionDisposer? _onWalletSyncStatusChangeReaction;
2020-09-21 11:50:26 +00:00
void startWalletSyncStatusChangeReaction(
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> wallet,
2022-03-30 15:57:04 +00:00
FiatConversionStore fiatConversionStore) {
2022-10-12 17:09:57 +00:00
_onWalletSyncStatusChangeReaction?.reaction.dispose();
_onWalletSyncStatusChangeReaction = reaction((_) => wallet.syncStatus, (SyncStatus status) async {
if (!(status is SyncingSyncStatus) || wallet.type != WalletType.bitcoin)
try {
if (status is ConnectedSyncStatus) {
await wallet.startSync();
2022-03-30 15:57:04 +00:00
if (wallet.type == WalletType.haven) {
await updateHavenRate(fiatConversionStore);
}
}
if (status is SyncingSyncStatus) {
await WakelockPlus.enable();
}
if (status is SyncedSyncStatus || status is FailedSyncStatus) {
await WakelockPlus.disable();
}
} catch (e) {
print(e.toString());
2022-03-30 15:57:04 +00:00
}
});
}