Merge pull request #143 from cake-tech/CAKE-172-restore-and-rescan-screen-fixes

CAKE-172 | added onHeightOrDateEntered function to blockchain_height_…
This commit is contained in:
M 2020-11-12 22:31:13 +02:00
commit 58280d1bb2
7 changed files with 69 additions and 25 deletions

View file

@ -21,23 +21,9 @@ class RescanPage extends BasePage {
padding: EdgeInsets.only(left: 24, right: 24, bottom: 24), padding: EdgeInsets.only(left: 24, right: 24, bottom: 24),
child: child:
Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Column( BlockchainHeightWidget(key: _blockchainHeightWidgetKey,
children: <Widget>[ onHeightOrDateEntered: (value) =>
BlockchainHeightWidget(key: _blockchainHeightWidgetKey), _rescanViewModel.isButtonEnabled = value),
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
),
),
)
],
),
Observer( Observer(
builder: (_) => LoadingPrimaryButton( builder: (_) => LoadingPrimaryButton(
isLoading: isLoading:
@ -51,6 +37,7 @@ class RescanPage extends BasePage {
}, },
color: Theme.of(context).accentTextTheme.body2.color, color: Theme.of(context).accentTextTheme.body2.color,
textColor: Colors.white, textColor: Colors.white,
isDisabled: !_rescanViewModel.isButtonEnabled,
)) ))
]), ]),
); );

View file

@ -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'; import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
class WalletRestoreFromKeysFrom extends StatefulWidget { class WalletRestoreFromKeysFrom extends StatefulWidget {
WalletRestoreFromKeysFrom({Key key}) : super(key: key); WalletRestoreFromKeysFrom({Key key, this.onHeightOrDateEntered})
: super(key: key);
final Function (bool) onHeightOrDateEntered;
@override @override
WalletRestoreFromKeysFromState createState() => WalletRestoreFromKeysFromState createState() =>
@ -63,7 +66,9 @@ class WalletRestoreFromKeysFromState extends State<WalletRestoreFromKeysFrom> {
hintText: S.of(context).restore_spend_key_private, hintText: S.of(context).restore_spend_key_private,
maxLines: null)), maxLines: null)),
BlockchainHeightWidget( BlockchainHeightWidget(
key: blockchainHeightKey, onHeightChange: (_) => null) key: blockchainHeightKey,
onHeightChange: (_) => null,
onHeightOrDateEntered: widget.onHeightOrDateEntered)
]), ]),
)); ));
} }

View file

@ -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'; import 'package:cake_wallet/src/widgets/blockchain_height_widget.dart';
class WalletRestoreFromSeedForm extends StatefulWidget { class WalletRestoreFromSeedForm extends StatefulWidget {
WalletRestoreFromSeedForm({Key key, this.blockHeightFocusNode}) WalletRestoreFromSeedForm({Key key, this.blockHeightFocusNode,
this.onHeightOrDateEntered})
: super(key: key); : super(key: key);
final FocusNode blockHeightFocusNode; final FocusNode blockHeightFocusNode;
final Function (bool) onHeightOrDateEntered;
@override @override
WalletRestoreFromSeedFormState createState() => WalletRestoreFromSeedFormState createState() =>
@ -63,7 +65,8 @@ class WalletRestoreFromSeedFormState extends State<WalletRestoreFromSeedForm> {
readOnly: true)))), readOnly: true)))),
BlockchainHeightWidget( BlockchainHeightWidget(
focusNode: widget.blockHeightFocusNode, focusNode: widget.blockHeightFocusNode,
key: blockchainHeightKey) key: blockchainHeightKey,
onHeightOrDateEntered: widget.onHeightOrDateEntered)
])); ]));
} }

View file

@ -28,8 +28,12 @@ class WalletRestorePage extends BasePage {
_pages.addAll([ _pages.addAll([
WalletRestoreFromSeedForm( WalletRestoreFromSeedForm(
key: walletRestoreFromSeedFormKey, key: walletRestoreFromSeedFormKey,
blockHeightFocusNode: _blockHeightFocusNode), blockHeightFocusNode: _blockHeightFocusNode,
WalletRestoreFromKeysFrom(key: walletRestoreFromKeysFormKey) 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: [ return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
Expanded( Expanded(
child: PageView.builder( child: PageView.builder(
@ -113,7 +132,8 @@ class WalletRestorePage extends BasePage {
.accentTextTheme .accentTextTheme
.headline .headline
.decorationColor, .decorationColor,
isLoading: walletRestoreViewModel.state is IsExecutingState); isLoading: walletRestoreViewModel.state is IsExecutingState,
isDisabled: !walletRestoreViewModel.isButtonEnabled,);
}, },
)) ))
]); ]);

View file

@ -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'; import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
class BlockchainHeightWidget extends StatefulWidget { class BlockchainHeightWidget extends StatefulWidget {
BlockchainHeightWidget({GlobalKey key, this.onHeightChange, this.focusNode}) BlockchainHeightWidget({GlobalKey key, this.onHeightChange, this.focusNode,
this.onHeightOrDateEntered})
: super(key: key); : super(key: key);
final Function(int) onHeightChange; final Function(int) onHeightChange;
final Function(bool) onHeightOrDateEntered;
final FocusNode focusNode; final FocusNode focusNode;
@override @override
@ -26,6 +28,13 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
@override @override
void initState() { void initState() {
restoreHeightController.addListener(() { restoreHeightController.addListener(() {
if (restoreHeightController.text.isNotEmpty) {
widget.onHeightOrDateEntered?.call(true);
}
else {
widget.onHeightOrDateEntered?.call(false);
dateController.text = '';
}
try { try {
_changeHeight(restoreHeightController.text != null && _changeHeight(restoreHeightController.text != null &&
restoreHeightController.text.isNotEmpty restoreHeightController.text.isNotEmpty
@ -83,6 +92,18 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
)) ))
], ],
), ),
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
),
),
)
], ],
); );
} }

View file

@ -10,12 +10,16 @@ enum RescanWalletState { rescaning, none }
abstract class RescanViewModelBase with Store { abstract class RescanViewModelBase with Store {
RescanViewModelBase(this._wallet) { RescanViewModelBase(this._wallet) {
state = RescanWalletState.none; state = RescanWalletState.none;
isButtonEnabled = false;
} }
@observable @observable
RescanWalletState state; RescanWalletState state;
final WalletBase _wallet; final WalletBase _wallet;
@observable
bool isButtonEnabled;
@action @action
Future<void> rescanCurrentWallet({int restoreHeight}) async { Future<void> rescanCurrentWallet({int restoreHeight}) async {
state = RescanWalletState.rescaning; state = RescanWalletState.rescaning;

View file

@ -23,6 +23,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
Box<WalletInfo> walletInfoSource, Box<WalletInfo> walletInfoSource,
{@required WalletType type}) {@required WalletType type})
: super(appStore, walletInfoSource, type: type, isRecovery: true) { : super(appStore, walletInfoSource, type: type, isRecovery: true) {
isButtonEnabled = false;
mode = WalletRestoreMode.seed; mode = WalletRestoreMode.seed;
_walletCreationService.changeWalletType(type: WalletType.monero); _walletCreationService.changeWalletType(type: WalletType.monero);
} }
@ -30,6 +31,9 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
@observable @observable
WalletRestoreMode mode; WalletRestoreMode mode;
@observable
bool isButtonEnabled;
final WalletCreationService _walletCreationService; final WalletCreationService _walletCreationService;
@override @override