cake_wallet/lib/view_model/rescan_view_model.dart

44 lines
1.1 KiB
Dart
Raw Normal View History

import 'package:cake_wallet/bitcoin/bitcoin.dart';
2021-12-24 12:37:24 +00:00
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
2020-09-21 11:50:26 +00:00
import 'package:mobx/mobx.dart';
part 'rescan_view_model.g.dart';
class RescanViewModel = RescanViewModelBase with _$RescanViewModel;
enum RescanWalletState { rescaning, none }
abstract class RescanViewModelBase with Store {
2022-10-12 17:09:57 +00:00
RescanViewModelBase(this._wallet)
: state = RescanWalletState.none,
isButtonEnabled = false,
doSingleScan = false;
2022-10-12 17:09:57 +00:00
final WalletBase _wallet;
2020-09-21 11:50:26 +00:00
@observable
RescanWalletState state;
@observable
bool isButtonEnabled;
@observable
bool doSingleScan;
@computed
bool get isSilentPaymentsScan => _wallet.type == WalletType.bitcoin;
2020-09-21 11:50:26 +00:00
@action
2022-10-12 17:09:57 +00:00
Future<void> rescanCurrentWallet({required int restoreHeight}) async {
2020-09-21 11:50:26 +00:00
state = RescanWalletState.rescaning;
if (_wallet.type != WalletType.bitcoin) {
_wallet.rescan(height: restoreHeight);
_wallet.transactionHistory.clear();
} else {
bitcoin!.rescan(_wallet, height: restoreHeight, doSingleScan: doSingleScan);
}
2020-09-21 11:50:26 +00:00
state = RescanWalletState.none;
}
}