2024-04-05 20:27:42 +00:00
|
|
|
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
2024-04-09 19:37:00 +00:00
|
|
|
import 'package:cake_wallet/store/settings_store.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/wallet_base.dart';
|
2024-02-26 18:32:54 +00:00
|
|
|
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 {
|
2024-04-09 19:37:00 +00:00
|
|
|
RescanViewModelBase(this.wallet, this.settingsStore)
|
2024-02-26 18:32:54 +00:00
|
|
|
: state = RescanWalletState.none,
|
2024-04-09 15:15:21 +00:00
|
|
|
isButtonEnabled = false,
|
|
|
|
doSingleScan = false;
|
2022-10-12 17:09:57 +00:00
|
|
|
|
2024-04-09 19:37:00 +00:00
|
|
|
final WalletBase wallet;
|
|
|
|
|
|
|
|
final SettingsStore settingsStore;
|
2020-09-21 11:50:26 +00:00
|
|
|
|
|
|
|
@observable
|
|
|
|
RescanWalletState state;
|
|
|
|
|
2020-11-12 19:03:57 +00:00
|
|
|
@observable
|
|
|
|
bool isButtonEnabled;
|
|
|
|
|
2024-04-09 15:15:21 +00:00
|
|
|
@observable
|
|
|
|
bool doSingleScan;
|
|
|
|
|
2024-04-05 20:27:42 +00:00
|
|
|
@computed
|
2024-04-09 19:37:00 +00:00
|
|
|
bool get isSilentPaymentsScan => wallet.type == WalletType.bitcoin;
|
2024-04-05 20:27:42 +00:00
|
|
|
|
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;
|
2024-04-09 19:37:00 +00:00
|
|
|
if (wallet.type != WalletType.bitcoin) {
|
|
|
|
wallet.rescan(height: restoreHeight);
|
|
|
|
wallet.transactionHistory.clear();
|
2024-04-09 15:15:21 +00:00
|
|
|
} else {
|
2024-04-09 19:37:00 +00:00
|
|
|
bitcoin!.rescan(wallet, settingsStore, height: restoreHeight, doSingleScan: doSingleScan);
|
2024-04-09 15:15:21 +00:00
|
|
|
}
|
2020-09-21 11:50:26 +00:00
|
|
|
state = RescanWalletState.none;
|
|
|
|
}
|
2024-02-26 18:32:54 +00:00
|
|
|
}
|