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

OleksandrSobol committed Nov 12, 2020 at 21:03 UTC 838368c1f44212d20df3b344fe69a43987a1a9f7
7 files changed +69 -25
lib/src/screens/rescan/rescan_page.dart
+4 -17
@@ -21,23 +21,9 @@ class RescanPage extends BasePage {
21 padding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
22 child:
23 Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
24 - Column(
25 - children: <Widget>[
26 - BlockchainHeightWidget(key: _blockchainHeightWidgetKey),
27 - Padding(
28 - padding: EdgeInsets.only(left: 40, right: 40, top: 24),
29 - child: Text(
30 - S.of(context).restore_from_date_or_blockheight,
31 - textAlign: TextAlign.center,
32 - style: TextStyle(
33 - fontSize: 12,
34 - fontWeight: FontWeight.normal,
35 - color: Theme.of(context).hintColor
36 - ),
37 - ),
38 - )
39 - ],
40 - ),
24 + BlockchainHeightWidget(key: _blockchainHeightWidgetKey,
25 + onHeightOrDateEntered: (value) =>
26 + _rescanViewModel.isButtonEnabled = value),
27 Observer(
28 builder: (_) => LoadingPrimaryButton(
29 isLoading:
@@ -51,6 +37,7 @@ class RescanPage extends BasePage {
37 },
38 color: Theme.of(context).accentTextTheme.body2.color,
39 textColor: Colors.white,
40 + isDisabled: !_rescanViewModel.isButtonEnabled,
41 ))
42 ]),
43 );
lib/src/screens/restore/wallet_restore_from_keys_form.dart
+7 -2
@@ -6,7 +6,10 @@ import 'package:cake_wallet/src/widgets/blockchain_height_widget.dart';
6 import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
7
8 class WalletRestoreFromKeysFrom extends StatefulWidget {
9 - WalletRestoreFromKeysFrom({Key key}) : super(key: key);
9 + WalletRestoreFromKeysFrom({Key key, this.onHeightOrDateEntered})
10 + : super(key: key);
11 +
12 + final Function (bool) onHeightOrDateEntered;
13
14 @override
15 WalletRestoreFromKeysFromState createState() =>
@@ -63,7 +66,9 @@ class WalletRestoreFromKeysFromState extends State<WalletRestoreFromKeysFrom> {
66 hintText: S.of(context).restore_spend_key_private,
67 maxLines: null)),
68 BlockchainHeightWidget(
66 - key: blockchainHeightKey, onHeightChange: (_) => null)
69 + key: blockchainHeightKey,
70 + onHeightChange: (_) => null,
71 + onHeightOrDateEntered: widget.onHeightOrDateEntered)
72 ]),
73 ));
74 }
lib/src/screens/restore/wallet_restore_from_seed_form.dart
+5 -2
@@ -7,10 +7,12 @@ import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
7 import 'package:cake_wallet/src/widgets/blockchain_height_widget.dart';
8
9 class WalletRestoreFromSeedForm extends StatefulWidget {
10 - WalletRestoreFromSeedForm({Key key, this.blockHeightFocusNode})
10 + WalletRestoreFromSeedForm({Key key, this.blockHeightFocusNode,
11 + this.onHeightOrDateEntered})
12 : super(key: key);
13
14 final FocusNode blockHeightFocusNode;
15 + final Function (bool) onHeightOrDateEntered;
16
17 @override
18 WalletRestoreFromSeedFormState createState() =>
@@ -63,7 +65,8 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
65 readOnly: true)))),
66 BlockchainHeightWidget(
67 focusNode: widget.blockHeightFocusNode,
66 - key: blockchainHeightKey)
68 + key: blockchainHeightKey,
69 + onHeightOrDateEntered: widget.onHeightOrDateEntered)
70 ]));
71 }
72
lib/src/screens/restore/wallet_restore_page.dart
+23 -3
@@ -28,8 +28,12 @@ class WalletRestorePage extends BasePage {
28 _pages.addAll([
29 WalletRestoreFromSeedForm(
30 key: walletRestoreFromSeedFormKey,
31 - blockHeightFocusNode: _blockHeightFocusNode),
32 - WalletRestoreFromKeysFrom(key: walletRestoreFromKeysFormKey)
31 + blockHeightFocusNode: _blockHeightFocusNode,
32 + onHeightOrDateEntered: (value)
33 + => walletRestoreViewModel.isButtonEnabled = value),
34 + WalletRestoreFromKeysFrom(key: walletRestoreFromKeysFormKey,
35 + onHeightOrDateEntered: (value)
36 + => walletRestoreViewModel.isButtonEnabled = value)
37 ]);
38 }
39
@@ -72,6 +76,21 @@ class WalletRestorePage extends BasePage {
76 }
77 });
78
79 + reaction((_) => walletRestoreViewModel.mode, (WalletRestoreMode mode)
80 + {
81 + walletRestoreViewModel.isButtonEnabled = false;
82 +
83 + walletRestoreFromSeedFormKey.currentState.blockchainHeightKey
84 + .currentState.restoreHeightController.text = '';
85 + walletRestoreFromSeedFormKey.currentState.blockchainHeightKey
86 + .currentState.dateController.text = '';
87 +
88 + walletRestoreFromKeysFormKey.currentState.blockchainHeightKey
89 + .currentState.restoreHeightController.text = '';
90 + walletRestoreFromKeysFormKey.currentState.blockchainHeightKey
91 + .currentState.dateController.text = '';
92 + });
93 +
94 return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
95 Expanded(
96 child: PageView.builder(
@@ -113,7 +132,8 @@ class WalletRestorePage extends BasePage {
132 .accentTextTheme
133 .headline
134 .decorationColor,
116 - isLoading: walletRestoreViewModel.state is IsExecutingState);
135 + isLoading: walletRestoreViewModel.state is IsExecutingState,
136 + isDisabled: !walletRestoreViewModel.isButtonEnabled,);
137 },
138 ))
139 ]);
lib/src/widgets/blockchain_height_widget.dart
+22 -1
@@ -6,10 +6,12 @@ import 'package:cake_wallet/monero/get_height_by_date.dart';
6 import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
7
8 class BlockchainHeightWidget extends StatefulWidget {
9 - BlockchainHeightWidget({GlobalKey key, this.onHeightChange, this.focusNode})
9 + BlockchainHeightWidget({GlobalKey key, this.onHeightChange, this.focusNode,
10 + this.onHeightOrDateEntered})
11 : super(key: key);
12
13 final Function(int) onHeightChange;
14 + final Function(bool) onHeightOrDateEntered;
15 final FocusNode focusNode;
16
17 @override
@@ -26,6 +28,13 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
28 @override
29 void initState() {
30 restoreHeightController.addListener(() {
31 + if (restoreHeightController.text.isNotEmpty) {
32 + widget.onHeightOrDateEntered?.call(true);
33 + }
34 + else {
35 + widget.onHeightOrDateEntered?.call(false);
36 + dateController.text = '';
37 + }
38 try {
39 _changeHeight(restoreHeightController.text != null &&
40 restoreHeightController.text.isNotEmpty
@@ -83,6 +92,18 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
92 ))
93 ],
94 ),
95 + Padding(
96 + padding: EdgeInsets.only(left: 40, right: 40, top: 24),
97 + child: Text(
98 + S.of(context).restore_from_date_or_blockheight,
99 + textAlign: TextAlign.center,
100 + style: TextStyle(
101 + fontSize: 12,
102 + fontWeight: FontWeight.normal,
103 + color: Theme.of(context).hintColor
104 + ),
105 + ),
106 + )
107 ],
108 );
109 }
lib/view_model/rescan_view_model.dart
+4
@@ -10,12 +10,16 @@ enum RescanWalletState { rescaning, none }
10 abstract class RescanViewModelBase with Store {
11 RescanViewModelBase(this._wallet) {
12 state = RescanWalletState.none;
13 + isButtonEnabled = false;
14 }
15
16 @observable
17 RescanWalletState state;
18 final WalletBase _wallet;
19
20 + @observable
21 + bool isButtonEnabled;
22 +
23 @action
24 Future<void> rescanCurrentWallet({int restoreHeight}) async {
25 state = RescanWalletState.rescaning;
lib/view_model/wallet_restore_view_model.dart
+4
@@ -23,6 +23,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
23 Box<WalletInfo> walletInfoSource,
24 {@required WalletType type})
25 : super(appStore, walletInfoSource, type: type, isRecovery: true) {
26 + isButtonEnabled = false;
27 mode = WalletRestoreMode.seed;
28 _walletCreationService.changeWalletType(type: WalletType.monero);
29 }
@@ -30,6 +31,9 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
31 @observable
32 WalletRestoreMode mode;
33
34 + @observable
35 + bool isButtonEnabled;
36 +
37 final WalletCreationService _walletCreationService;
38
39 @override