cake_wallet/lib/view_model/rescan_view_model.dart

35 lines
968 B
Dart

import 'package:cake_wallet/bitcoin/bitcoin.dart';
import 'package:cw_core/wallet_base.dart';
import 'package:cw_core/wallet_type.dart';
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 {
RescanViewModelBase(this._wallet)
: state = RescanWalletState.none,
isButtonEnabled = false;
final WalletBase _wallet;
@observable
RescanWalletState state;
@observable
bool isButtonEnabled;
@computed
bool get isSilentPaymentsScan => bitcoin!.hasSelectedSilentPayments(_wallet);
@action
Future<void> rescanCurrentWallet({required int restoreHeight}) async {
state = RescanWalletState.rescaning;
_wallet.rescan(height: restoreHeight);
if (_wallet.type != WalletType.bitcoin) _wallet.transactionHistory.clear();
state = RescanWalletState.none;
}
}