diff --git a/cw_zcash/lib/src/zcash_wallet.dart b/cw_zcash/lib/src/zcash_wallet.dart index 0a6e192d8..4948baf26 100644 --- a/cw_zcash/lib/src/zcash_wallet.dart +++ b/cw_zcash/lib/src/zcash_wallet.dart @@ -999,6 +999,14 @@ abstract class ZcashWalletBase static int zashiAnnouncedBlockHeight = 2419420; + Future getBirthHeight() async => runWithCoin( + accountId: accountId, + func: (final coin) async => (await zkool_account.listAccounts(c: coin)) + .where((final a) => a.id == accountId) + .firstOrNull + ?.birth, + ); + Future _getAddressesForAccount(final int id) async { return runWithCoin( accountId: id, diff --git a/lib/src/screens/rescan/rescan_page.dart b/lib/src/screens/rescan/rescan_page.dart index 8d7395068..afd0a75a5 100644 --- a/lib/src/screens/rescan/rescan_page.dart +++ b/lib/src/screens/rescan/rescan_page.dart @@ -25,6 +25,16 @@ class RescanPage extends StatefulWidget { class _RescanPageState extends State { final TextEditingController _heightController = TextEditingController(); + @override + void initState() { + super.initState(); + widget._rescanViewModel.savedRestoreHeight.then((height) { + if (mounted && (height ?? 0) > 0 && _heightController.text.isEmpty) { + _heightController.text = '$height'; + } + }); + } + @override Widget build(BuildContext context) { Widget child; diff --git a/lib/view_model/rescan_view_model.dart b/lib/view_model/rescan_view_model.dart index bfc048763..991d92691 100644 --- a/lib/view_model/rescan_view_model.dart +++ b/lib/view_model/rescan_view_model.dart @@ -1,4 +1,6 @@ import 'package:cake_wallet/bitcoin/bitcoin.dart'; +import 'package:cake_wallet/monero/monero.dart'; +import 'package:cake_wallet/zcash/zcash.dart'; import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:mobx/mobx.dart'; @@ -32,6 +34,14 @@ abstract class RescanViewModelBase with Store { @computed bool get isMwebScan => wallet.type == WalletType.litecoin; + Future get savedRestoreHeight async => switch (wallet.type) { + WalletType.monero => wallet.walletInfo.restoreHeight != 0 + ? wallet.walletInfo.restoreHeight + : monero!.getRestoreHeight(wallet), + WalletType.zcash => await zcash!.getBirthHeight(wallet), + _ => null, + }; + Future get isBitcoinMempoolAPIEnabled async => wallet.type == WalletType.bitcoin && await bitcoin!.checkIfMempoolAPIIsEnabled(wallet); diff --git a/lib/zcash/cw_zcash.dart b/lib/zcash/cw_zcash.dart index 525dac193..0f13d254c 100644 --- a/lib/zcash/cw_zcash.dart +++ b/lib/zcash/cw_zcash.dart @@ -119,6 +119,9 @@ class CWZcash extends Zcash { return getAddress(wallet); } + @override + Future getBirthHeight(Object wallet) => (wallet as ZcashWallet).getBirthHeight(); + @override Map getKeys(Object wallet) { final zcashWallet = wallet as ZcashWallet; diff --git a/tool/configure.dart b/tool/configure.dart index c11d020e1..5e0bc9a0c 100644 --- a/tool/configure.dart +++ b/tool/configure.dart @@ -1778,6 +1778,7 @@ abstract class Zcash { String getPrivateKey(WalletBase wallet); String getPublicKey(WalletBase wallet); Map getKeys(Object wallet); + Future getBirthHeight(Object wallet); Object createZcashTransactionCredentials( List outputs, {