From 838368c1f44212d20df3b344fe69a43987a1a9f7 Mon Sep 17 00:00:00 2001 From: OleksandrSobol Date: Thu, 12 Nov 2020 21:03:57 +0200 Subject: [PATCH] CAKE-172 | added onHeightOrDateEntered function to blockchain_height_widget and called it in the restoreHeightController listener; added string resources to blockchain_height_widget; added isButtonEnabled parameter to rescan view model and wallet restore view model; added reaction on mode in the wallet restore page; applied isDisable to buttons in wallet restore page and rescan page --- lib/src/screens/rescan/rescan_page.dart | 21 +++------------ .../wallet_restore_from_keys_form.dart | 9 +++++-- .../wallet_restore_from_seed_form.dart | 7 +++-- .../screens/restore/wallet_restore_page.dart | 26 ++++++++++++++++--- lib/src/widgets/blockchain_height_widget.dart | 23 +++++++++++++++- lib/view_model/rescan_view_model.dart | 4 +++ lib/view_model/wallet_restore_view_model.dart | 4 +++ 7 files changed, 69 insertions(+), 25 deletions(-) diff --git a/lib/src/screens/rescan/rescan_page.dart b/lib/src/screens/rescan/rescan_page.dart index a1eaed7f5..f00ee685b 100644 --- a/lib/src/screens/rescan/rescan_page.dart +++ b/lib/src/screens/rescan/rescan_page.dart @@ -21,23 +21,9 @@ class RescanPage extends BasePage { padding: EdgeInsets.only(left: 24, right: 24, bottom: 24), child: Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Column( - children: [ - BlockchainHeightWidget(key: _blockchainHeightWidgetKey), - Padding( - padding: EdgeInsets.only(left: 40, right: 40, top: 24), - child: Text( - S.of(context).restore_from_date_or_blockheight, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.normal, - color: Theme.of(context).hintColor - ), - ), - ) - ], - ), + BlockchainHeightWidget(key: _blockchainHeightWidgetKey, + onHeightOrDateEntered: (value) => + _rescanViewModel.isButtonEnabled = value), Observer( builder: (_) => LoadingPrimaryButton( isLoading: @@ -51,6 +37,7 @@ class RescanPage extends BasePage { }, color: Theme.of(context).accentTextTheme.body2.color, textColor: Colors.white, + isDisabled: !_rescanViewModel.isButtonEnabled, )) ]), ); diff --git a/lib/src/screens/restore/wallet_restore_from_keys_form.dart b/lib/src/screens/restore/wallet_restore_from_keys_form.dart index 5a36b81d1..ade173d6f 100644 --- a/lib/src/screens/restore/wallet_restore_from_keys_form.dart +++ b/lib/src/screens/restore/wallet_restore_from_keys_form.dart @@ -6,7 +6,10 @@ import 'package:cake_wallet/src/widgets/blockchain_height_widget.dart'; import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; class WalletRestoreFromKeysFrom extends StatefulWidget { - WalletRestoreFromKeysFrom({Key key}) : super(key: key); + WalletRestoreFromKeysFrom({Key key, this.onHeightOrDateEntered}) + : super(key: key); + + final Function (bool) onHeightOrDateEntered; @override WalletRestoreFromKeysFromState createState() => @@ -63,7 +66,9 @@ class WalletRestoreFromKeysFromState extends State { hintText: S.of(context).restore_spend_key_private, maxLines: null)), BlockchainHeightWidget( - key: blockchainHeightKey, onHeightChange: (_) => null) + key: blockchainHeightKey, + onHeightChange: (_) => null, + onHeightOrDateEntered: widget.onHeightOrDateEntered) ]), )); } diff --git a/lib/src/screens/restore/wallet_restore_from_seed_form.dart b/lib/src/screens/restore/wallet_restore_from_seed_form.dart index ad8c4f84b..6044531d9 100644 --- a/lib/src/screens/restore/wallet_restore_from_seed_form.dart +++ b/lib/src/screens/restore/wallet_restore_from_seed_form.dart @@ -7,10 +7,12 @@ import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; import 'package:cake_wallet/src/widgets/blockchain_height_widget.dart'; class WalletRestoreFromSeedForm extends StatefulWidget { - WalletRestoreFromSeedForm({Key key, this.blockHeightFocusNode}) + WalletRestoreFromSeedForm({Key key, this.blockHeightFocusNode, + this.onHeightOrDateEntered}) : super(key: key); final FocusNode blockHeightFocusNode; + final Function (bool) onHeightOrDateEntered; @override WalletRestoreFromSeedFormState createState() => @@ -63,7 +65,8 @@ class WalletRestoreFromSeedFormState extends State { readOnly: true)))), BlockchainHeightWidget( focusNode: widget.blockHeightFocusNode, - key: blockchainHeightKey) + key: blockchainHeightKey, + onHeightOrDateEntered: widget.onHeightOrDateEntered) ])); } diff --git a/lib/src/screens/restore/wallet_restore_page.dart b/lib/src/screens/restore/wallet_restore_page.dart index 8b5e604e4..1a00639b6 100644 --- a/lib/src/screens/restore/wallet_restore_page.dart +++ b/lib/src/screens/restore/wallet_restore_page.dart @@ -28,8 +28,12 @@ class WalletRestorePage extends BasePage { _pages.addAll([ WalletRestoreFromSeedForm( key: walletRestoreFromSeedFormKey, - blockHeightFocusNode: _blockHeightFocusNode), - WalletRestoreFromKeysFrom(key: walletRestoreFromKeysFormKey) + blockHeightFocusNode: _blockHeightFocusNode, + onHeightOrDateEntered: (value) + => walletRestoreViewModel.isButtonEnabled = value), + WalletRestoreFromKeysFrom(key: walletRestoreFromKeysFormKey, + onHeightOrDateEntered: (value) + => walletRestoreViewModel.isButtonEnabled = value) ]); } @@ -72,6 +76,21 @@ class WalletRestorePage extends BasePage { } }); + reaction((_) => walletRestoreViewModel.mode, (WalletRestoreMode mode) + { + walletRestoreViewModel.isButtonEnabled = false; + + walletRestoreFromSeedFormKey.currentState.blockchainHeightKey + .currentState.restoreHeightController.text = ''; + walletRestoreFromSeedFormKey.currentState.blockchainHeightKey + .currentState.dateController.text = ''; + + walletRestoreFromKeysFormKey.currentState.blockchainHeightKey + .currentState.restoreHeightController.text = ''; + walletRestoreFromKeysFormKey.currentState.blockchainHeightKey + .currentState.dateController.text = ''; + }); + return Column(mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( child: PageView.builder( @@ -113,7 +132,8 @@ class WalletRestorePage extends BasePage { .accentTextTheme .headline .decorationColor, - isLoading: walletRestoreViewModel.state is IsExecutingState); + isLoading: walletRestoreViewModel.state is IsExecutingState, + isDisabled: !walletRestoreViewModel.isButtonEnabled,); }, )) ]); diff --git a/lib/src/widgets/blockchain_height_widget.dart b/lib/src/widgets/blockchain_height_widget.dart index 384700839..7cf11e408 100644 --- a/lib/src/widgets/blockchain_height_widget.dart +++ b/lib/src/widgets/blockchain_height_widget.dart @@ -6,10 +6,12 @@ import 'package:cake_wallet/monero/get_height_by_date.dart'; import 'package:cake_wallet/src/widgets/base_text_form_field.dart'; class BlockchainHeightWidget extends StatefulWidget { - BlockchainHeightWidget({GlobalKey key, this.onHeightChange, this.focusNode}) + BlockchainHeightWidget({GlobalKey key, this.onHeightChange, this.focusNode, + this.onHeightOrDateEntered}) : super(key: key); final Function(int) onHeightChange; + final Function(bool) onHeightOrDateEntered; final FocusNode focusNode; @override @@ -26,6 +28,13 @@ class BlockchainHeightState extends State { @override void initState() { restoreHeightController.addListener(() { + if (restoreHeightController.text.isNotEmpty) { + widget.onHeightOrDateEntered?.call(true); + } + else { + widget.onHeightOrDateEntered?.call(false); + dateController.text = ''; + } try { _changeHeight(restoreHeightController.text != null && restoreHeightController.text.isNotEmpty @@ -83,6 +92,18 @@ class BlockchainHeightState extends State { )) ], ), + Padding( + padding: EdgeInsets.only(left: 40, right: 40, top: 24), + child: Text( + S.of(context).restore_from_date_or_blockheight, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.normal, + color: Theme.of(context).hintColor + ), + ), + ) ], ); } diff --git a/lib/view_model/rescan_view_model.dart b/lib/view_model/rescan_view_model.dart index 54df6af1a..be9477df5 100644 --- a/lib/view_model/rescan_view_model.dart +++ b/lib/view_model/rescan_view_model.dart @@ -10,12 +10,16 @@ enum RescanWalletState { rescaning, none } abstract class RescanViewModelBase with Store { RescanViewModelBase(this._wallet) { state = RescanWalletState.none; + isButtonEnabled = false; } @observable RescanWalletState state; final WalletBase _wallet; + @observable + bool isButtonEnabled; + @action Future rescanCurrentWallet({int restoreHeight}) async { state = RescanWalletState.rescaning; diff --git a/lib/view_model/wallet_restore_view_model.dart b/lib/view_model/wallet_restore_view_model.dart index 4c2411a23..49dab88e4 100644 --- a/lib/view_model/wallet_restore_view_model.dart +++ b/lib/view_model/wallet_restore_view_model.dart @@ -23,6 +23,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { Box walletInfoSource, {@required WalletType type}) : super(appStore, walletInfoSource, type: type, isRecovery: true) { + isButtonEnabled = false; mode = WalletRestoreMode.seed; _walletCreationService.changeWalletType(type: WalletType.monero); } @@ -30,6 +31,9 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store { @observable WalletRestoreMode mode; + @observable + bool isButtonEnabled; + final WalletCreationService _walletCreationService; @override