2022-01-21 13:02:00 +00:00
|
|
|
import 'package:cake_wallet/di.dart';
|
|
|
|
import 'package:cake_wallet/entities/wake_lock.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';
|
2022-01-21 13:02:00 +00:00
|
|
|
import 'package:flutter/services.dart';
|
2020-09-21 11:50:26 +00:00
|
|
|
|
|
|
|
ReactionDisposer _onWalletSyncStatusChangeReaction;
|
|
|
|
|
2021-05-07 07:36:38 +00:00
|
|
|
void startWalletSyncStatusChangeReaction(
|
|
|
|
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
|
|
|
|
TransactionInfo>
|
|
|
|
wallet) {
|
2022-01-24 15:21:52 +00:00
|
|
|
final _wakeLock = getIt.get<WakeLock>();
|
2020-09-21 11:50:26 +00:00
|
|
|
_onWalletSyncStatusChangeReaction?.reaction?.dispose();
|
|
|
|
_onWalletSyncStatusChangeReaction =
|
|
|
|
reaction((_) => wallet.syncStatus, (SyncStatus status) async {
|
2021-05-07 07:36:38 +00:00
|
|
|
if (status is ConnectedSyncStatus) {
|
|
|
|
await wallet.startSync();
|
|
|
|
}
|
2022-01-21 13:02:00 +00:00
|
|
|
if (status is SyncingSyncStatus) {
|
|
|
|
await _wakeLock.enableWake();
|
|
|
|
}
|
|
|
|
if (status is SyncedSyncStatus || status is FailedSyncStatus) {
|
|
|
|
await _wakeLock.disableWake();
|
|
|
|
}
|
2021-05-07 07:36:38 +00:00
|
|
|
});
|
|
|
|
}
|