cake_wallet/lib/reactions/on_wallet_sync_status_change.dart
OmarHatem a27c5005d1 Merge branch 'main' of https://github.com/cake-tech/cake_wallet into CW-62-send-all-fee-calculation
 Conflicts:
	cw_bitcoin/lib/electrum_wallet.dart
	cw_core/lib/wallet_base.dart
	cw_haven/lib/haven_wallet.dart
	cw_monero/lib/api/wallet.dart
	cw_monero/lib/monero_wallet.dart
	lib/src/screens/send/widgets/send_card.dart
	lib/view_model/exchange/exchange_view_model.dart
	lib/view_model/send/output.dart
	lib/view_model/send/send_view_model.dart
2022-11-21 14:27:36 +02:00

44 lines
1.6 KiB
Dart

import 'package:cake_wallet/di.dart';
import 'package:cake_wallet/entities/update_haven_rate.dart';
import 'package:cake_wallet/entities/wake_lock.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart';
import 'package:cw_core/wallet_type.dart';
import 'package:mobx/mobx.dart';
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';
ReactionDisposer? _onWalletSyncStatusChangeReaction;
void startWalletSyncStatusChangeReaction(WalletBase<Balance, TransactionHistoryBase<TransactionInfo>, TransactionInfo> wallet,
FiatConversionStore fiatConversionStore, SettingsStore settingsStore) {
final _wakeLock = getIt.get<WakeLock>();
_onWalletSyncStatusChangeReaction?.reaction.dispose();
_onWalletSyncStatusChangeReaction =
reaction((_) => wallet.syncStatus, (SyncStatus status) async {
try {
if (status is ConnectedSyncStatus) {
await wallet.startSync();
if (wallet.type == WalletType.haven) {
await updateHavenRate(fiatConversionStore);
}
}
if (status is SyncingSyncStatus) {
await _wakeLock.enableWake();
}
if (status is SyncedSyncStatus || status is FailedSyncStatus) {
await _wakeLock.disableWake();
}
} catch(e) {
print(e.toString());
}
if (status is SyncedSyncStatus) {
wallet.feeEstimate.update(priority: settingsStore.priority[wallet.type], outputsCount: 1);
}
});
}