diff --git a/lib/bloc/transactions/value_transfer/vtt_create/vtt_create_bloc.dart b/lib/bloc/transactions/value_transfer/vtt_create/vtt_create_bloc.dart index b133b5a0..af9742eb 100644 --- a/lib/bloc/transactions/value_transfer/vtt_create/vtt_create_bloc.dart +++ b/lib/bloc/transactions/value_transfer/vtt_create/vtt_create_bloc.dart @@ -852,7 +852,8 @@ class TransactionBloc extends Bloc { void _resetTransactionEvent( ResetTransactionEvent event, Emitter emit) { - scannedContent.clearScannedContent(); + scannedContent.clearScannedContent(type: ScannedType.address); + scannedContent.clearScannedContent(type: ScannedType.authorization); selectedUtxos.clear(); inputs.clear(); outputs.clear(); diff --git a/lib/globals.dart b/lib/globals.dart index 9e22150e..774e87c4 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -5,6 +5,9 @@ bool testingDeleteStorage = false; bool biometricsAuthInProgress = false; bool avoidBiometrics = false; bool firstRun = false; -String? scannedContent = null; +String? scannedAddress = null; +String? scannedAuthorization = null; +String? scannedXprv = null; + bool? isPanelClose; GlobalKey navigatorKey = GlobalKey(); diff --git a/lib/screens/create_wallet/enc_xprv_card.dart b/lib/screens/create_wallet/enc_xprv_card.dart index e64b8614..72fdea04 100644 --- a/lib/screens/create_wallet/enc_xprv_card.dart +++ b/lib/screens/create_wallet/enc_xprv_card.dart @@ -9,6 +9,7 @@ import 'package:my_wit_wallet/screens/create_wallet/bloc/create_wallet_bloc.dart import 'package:my_wit_wallet/screens/create_wallet/create_wallet_screen.dart'; import 'package:my_wit_wallet/shared/locator.dart'; import 'package:my_wit_wallet/util/storage/database/wallet.dart'; +import 'package:my_wit_wallet/util/storage/scanned_content.dart'; import 'package:my_wit_wallet/widgets/inputs/input_xprv.dart'; import 'package:my_wit_wallet/widgets/labeled_form_entry.dart'; import 'package:my_wit_wallet/widgets/suffix_icon_button.dart'; @@ -100,10 +101,10 @@ class EnterXprvCardState extends State } void setXprv(String value) { - xprv = XprvInput.dirty( - xprvType: _xprvType, - allowValidation: validationUtils.isFormUnFocus(_formFocusElements), - value: value); + xprv = XprvInput.dirty( + xprvType: _xprvType, + allowValidation: validationUtils.isFormUnFocus(_formFocusElements), + value: value); } void clearForm() { @@ -152,19 +153,21 @@ class EnterXprvCardState extends State context, MaterialPageRoute( builder: (context) => QrScanner( - currentRoute: CreateWalletScreen.route, - onChanged: (String value) async { - _textController.text = value; - xprv = XprvInput.dirty( - xprvType: _xprvType, - allowValidation: false, - value: value); - if (_xprvType == CreateWalletType.xprv) { - validate(force: true); - } else { - _passFocusNode.requestFocus(); - } - }))) + currentRoute: CreateWalletScreen.route, + onChanged: (String value) async { + _textController.text = value; + xprv = XprvInput.dirty( + xprvType: _xprvType, + allowValidation: false, + value: value); + if (_xprvType == CreateWalletType.xprv) { + validate(force: true); + } else { + _passFocusNode.requestFocus(); + } + }, + type: ScannedType.xprv, + ))) }, )) : null, diff --git a/lib/util/storage/scanned_content.dart b/lib/util/storage/scanned_content.dart index b817b7cb..ddc3d7fa 100644 --- a/lib/util/storage/scanned_content.dart +++ b/lib/util/storage/scanned_content.dart @@ -1,13 +1,25 @@ import 'package:my_wit_wallet/globals.dart' as globals; +enum ScannedType { + address, + authorization, + xprv, +} + class ScannedContent { - String? get scannedContent => globals.scannedContent; + String? get scannedAddress => globals.scannedAddress; + String? get scannedAuthorization => globals.scannedAuthorization; + String? get scannedXprv => globals.scannedXprv; - void setScannedContent(String value) { - globals.scannedContent = value; + void setScannedContent({required String value, required type}) { + if (type == ScannedType.address) globals.scannedAddress = value; + if (type == ScannedType.authorization) globals.scannedAuthorization = value; + if (type == ScannedType.xprv) globals.scannedXprv = value; } - void clearScannedContent() { - globals.scannedContent = null; + void clearScannedContent({required ScannedType type}) { + if (type == ScannedType.address) globals.scannedAddress = null; + if (type == ScannedType.authorization) globals.scannedAuthorization = null; + if (type == ScannedType.xprv) globals.scannedXprv = null; } } diff --git a/lib/widgets/inputs/input_address.dart b/lib/widgets/inputs/input_address.dart index af3fdd8b..10477d49 100644 --- a/lib/widgets/inputs/input_address.dart +++ b/lib/widgets/inputs/input_address.dart @@ -47,8 +47,8 @@ class _InputAddressState extends State { @override void initState() { super.initState(); - if (scannedContent.scannedContent != null) { - _handleQrAddressResults(scannedContent.scannedContent!); + if (scannedContent.scannedAddress != null) { + _handleQrAddressResults(scannedContent.scannedAddress!); } widget.focusNode.addListener(widget.onFocusChange); _scanQrFocusNode.addListener(_handleQrFocus); @@ -98,11 +98,14 @@ class _InputAddressState extends State { label: localization.scanQrCodeLabel, child: SuffixIcon( onPressed: () => { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => QrScanner( - currentRoute: widget.route!, - onChanged: (_value) => {}))) + Navigator.of(context) + .push(MaterialPageRoute( + builder: (context) => QrScanner( + currentRoute: widget.route!, + onChanged: (_value) => {}, + type: ScannedType.address, + ), + )) }, icon: FontAwesomeIcons.qrcode, isFocus: isScanQrFocused, diff --git a/lib/widgets/inputs/input_amount.dart b/lib/widgets/inputs/input_amount.dart index 452fdb58..0db425e1 100644 --- a/lib/widgets/inputs/input_amount.dart +++ b/lib/widgets/inputs/input_amount.dart @@ -5,7 +5,6 @@ import 'package:my_wit_wallet/widgets/buttons/text_btn.dart'; import 'package:my_wit_wallet/widgets/inputs/input_text.dart'; import 'package:my_wit_wallet/widgets/validations/vtt_amount_input.dart'; - class InputAmount extends InputText { InputAmount({ required this.amount, diff --git a/lib/widgets/inputs/input_authorization.dart b/lib/widgets/inputs/input_authorization.dart index 0b1b772b..71a5fd8c 100644 --- a/lib/widgets/inputs/input_authorization.dart +++ b/lib/widgets/inputs/input_authorization.dart @@ -27,8 +27,11 @@ class InputAuthorization extends InputText { super.onTap, super.onSuffixTap, super.maxLines = 3, + this.setAuthorizationCallback, }); + final void Function(String, {bool? validate})? setAuthorizationCallback; + @override _InputAuthorizationState createState() => _InputAuthorizationState(); final String route; @@ -42,8 +45,8 @@ class _InputAuthorizationState extends State { @override void initState() { super.initState(); - if (scannedContent.scannedContent != null) { - _handleQrAddressResults(scannedContent.scannedContent!); + if (scannedContent.scannedAuthorization != null) { + _handleQrAuthorizationResults(scannedContent.scannedAuthorization!); } widget.focusNode.addListener(widget.onFocusChange); _scanQrFocusNode.addListener(_handleQrFocus); @@ -56,7 +59,8 @@ class _InputAuthorizationState extends State { _scanQrFocusNode.removeListener(_handleQrFocus); } - _handleQrAddressResults(String value) { + _handleQrAuthorizationResults(String value) { + widget.setAuthorizationCallback!(value); widget.styledTextController.text = value; } @@ -100,8 +104,10 @@ class _InputAuthorizationState extends State { context, MaterialPageRoute( builder: (context) => QrScanner( - currentRoute: widget.route, - onChanged: (_value) => {}))) + currentRoute: widget.route, + onChanged: (_value) => {}, + type: ScannedType.authorization, + ))) }, )) : null, diff --git a/lib/widgets/inputs/input_xprv.dart b/lib/widgets/inputs/input_xprv.dart index cd9b01b3..787ce529 100644 --- a/lib/widgets/inputs/input_xprv.dart +++ b/lib/widgets/inputs/input_xprv.dart @@ -44,8 +44,8 @@ class _InputXprvState extends State { @override void initState() { super.initState(); - if (scannedContent.scannedContent != null) { - _handleQrAddressResults(scannedContent.scannedContent!); + if (scannedContent.scannedXprv != null) { + _handleQrAddressResults(scannedContent.scannedXprv!); } widget.focusNode.addListener(widget.onFocusChange); _scanQrFocusNode.addListener(_handleQrFocus); @@ -102,8 +102,10 @@ class _InputXprvState extends State { { Navigator.of(context).push(MaterialPageRoute( builder: (context) => QrScanner( - currentRoute: widget.route, - onChanged: (_value) => {}))) + currentRoute: widget.route, + onChanged: (_value) => {}, + type: ScannedType.xprv, + ))) }, }, )) diff --git a/lib/widgets/witnet/transactions/value_transfer/create_dialog_box/qr_scanner.dart b/lib/widgets/witnet/transactions/value_transfer/create_dialog_box/qr_scanner.dart index 4ab12db0..c3518f71 100644 --- a/lib/widgets/witnet/transactions/value_transfer/create_dialog_box/qr_scanner.dart +++ b/lib/widgets/witnet/transactions/value_transfer/create_dialog_box/qr_scanner.dart @@ -11,11 +11,13 @@ class QrScanner extends StatelessWidget { static final route = '/scan'; final StringCallback onChanged; final String currentRoute; - const QrScanner({ - Key? key, - required this.currentRoute, - required this.onChanged, - }) : super(key: key); + final ScannedType type; + const QrScanner( + {Key? key, + required this.currentRoute, + required this.onChanged, + required this.type}) + : super(key: key); @override Widget build(BuildContext context) { @@ -30,7 +32,8 @@ class QrScanner extends StatelessWidget { final List barcodes = capture.barcodes; for (final barcode in barcodes) { onChanged(barcode.rawValue ?? ''); - scannedContent.setScannedContent(barcode.rawValue ?? ''); + scannedContent.setScannedContent( + value: barcode.rawValue ?? '', type: type); Navigator.popUntil( context, ModalRoute.withName(this.currentRoute)); } diff --git a/lib/widgets/witnet/transactions/value_transfer/create_dialog_box/vtt_builder/01_recipient_step.dart b/lib/widgets/witnet/transactions/value_transfer/create_dialog_box/vtt_builder/01_recipient_step.dart index 28b15cf1..7a931cf9 100644 --- a/lib/widgets/witnet/transactions/value_transfer/create_dialog_box/vtt_builder/01_recipient_step.dart +++ b/lib/widgets/witnet/transactions/value_transfer/create_dialog_box/vtt_builder/01_recipient_step.dart @@ -122,6 +122,8 @@ class RecipientStepState extends State int weeksToAdd = 2; setMinimunTimelock(date.add(Duration(days: (7 * weeksToAdd).toInt()))); } + _addressFocusNode.addListener(() => validateForm()); + _amountFocusNode.addListener(() => validateForm()); } @override @@ -202,11 +204,11 @@ class RecipientStepState extends State } void setAuthorization(String value, {bool? validate}) { - _authorization = AuthorizationInput.dirty( - withdrawerAddress: _address.value, - allowValidation: - validate ?? validationUtils.isFormUnFocus(_formFocusElements()), - value: value); + _authorization = AuthorizationInput.dirty( + withdrawerAddress: _address.value, + allowValidation: + validate ?? validationUtils.isFormUnFocus(_formFocusElements()), + value: value); } void _setSavedTxData() { @@ -456,6 +458,7 @@ class RecipientStepState extends State focusNode: _authorizationFocusNode, styledTextController: _authorizationController, errorText: _authorization.error, + setAuthorizationCallback: setAuthorization, onFieldSubmitted: (value) async { _amountFocusNode.requestFocus(); }, @@ -545,8 +548,6 @@ class RecipientStepState extends State _buildForm(BuildContext context, ThemeData theme) { final theme = Theme.of(context); - _addressFocusNode.addListener(() => validateForm()); - _amountFocusNode.addListener(() => validateForm()); return Form( key: _formKey, autovalidateMode: AutovalidateMode.disabled,