From 8ef3c179992d1dcd79c9f0719f57dcbbac7726e0 Mon Sep 17 00:00:00 2001 From: parodyBit <58690522+parodyBit@users.noreply.github.com> Date: Thu, 21 Nov 2024 20:33:08 -0700 Subject: [PATCH 1/3] fix: scanned content values --- .../vtt_create/vtt_create_bloc.dart | 3 +- lib/globals.dart | 5 ++- lib/screens/create_wallet/enc_xprv_card.dart | 37 ++++++++++--------- lib/util/storage/scanned_content.dart | 22 ++++++++--- lib/widgets/inputs/input_address.dart | 17 +++++---- lib/widgets/inputs/input_amount.dart | 1 - lib/widgets/inputs/input_authorization.dart | 10 +++-- lib/widgets/inputs/input_xprv.dart | 10 +++-- .../create_dialog_box/qr_scanner.dart | 15 +++++--- .../vtt_builder/01_recipient_step.dart | 10 ++--- 10 files changed, 79 insertions(+), 51 deletions(-) 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 b133b5a0d..af9742eb2 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 9e22150ea..774e87c48 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 e64b8614b..72fdea042 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 b817b7cbe..ddc3d7fa2 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 af3fdd8b1..10477d496 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 452fdb582..0db425e18 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 0b1b772bc..4c1d47892 100644 --- a/lib/widgets/inputs/input_authorization.dart +++ b/lib/widgets/inputs/input_authorization.dart @@ -42,8 +42,8 @@ class _InputAuthorizationState extends State { @override void initState() { super.initState(); - if (scannedContent.scannedContent != null) { - _handleQrAddressResults(scannedContent.scannedContent!); + if (scannedContent.scannedAuthorization != null) { + _handleQrAddressResults(scannedContent.scannedAuthorization!); } widget.focusNode.addListener(widget.onFocusChange); _scanQrFocusNode.addListener(_handleQrFocus); @@ -100,8 +100,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 cd9b01b39..787ce529d 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 4ab12db0a..c3518f712 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 28b15cf1f..8c0604037 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 @@ -202,11 +202,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() { From de033d40d62e50f1f87041df4a9d430dba54e146 Mon Sep 17 00:00:00 2001 From: parodyBit <58690522+parodyBit@users.noreply.github.com> Date: Tue, 26 Nov 2024 07:16:34 -0700 Subject: [PATCH 2/3] fix: handle setAuth callback --- lib/widgets/inputs/input_authorization.dart | 8 ++++++-- .../create_dialog_box/vtt_builder/01_recipient_step.dart | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/widgets/inputs/input_authorization.dart b/lib/widgets/inputs/input_authorization.dart index 4c1d47892..71a5fd8c6 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; @@ -43,7 +46,7 @@ class _InputAuthorizationState extends State { void initState() { super.initState(); if (scannedContent.scannedAuthorization != null) { - _handleQrAddressResults(scannedContent.scannedAuthorization!); + _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; } 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 8c0604037..f334ae9e8 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 @@ -456,6 +456,7 @@ class RecipientStepState extends State focusNode: _authorizationFocusNode, styledTextController: _authorizationController, errorText: _authorization.error, + setAuthorizationCallback: setAuthorization, onFieldSubmitted: (value) async { _amountFocusNode.requestFocus(); }, From 0675b2af124310f37335a4e26a687b67c545fa63 Mon Sep 17 00:00:00 2001 From: parodyBit <58690522+parodyBit@users.noreply.github.com> Date: Wed, 27 Nov 2024 06:09:52 -0700 Subject: [PATCH 3/3] fix: move input listeners from build to initState --- .../create_dialog_box/vtt_builder/01_recipient_step.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f334ae9e8..7a931cf94 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 @@ -546,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,