Skip to content

Commit

Permalink
fix: scanned content values
Browse files Browse the repository at this point in the history
  • Loading branch information
parodyBit committed Nov 22, 2024
1 parent ad34693 commit 8ef3c17
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,8 @@ class TransactionBloc extends Bloc<TransactionEvent, TransactionState> {

void _resetTransactionEvent(
ResetTransactionEvent event, Emitter<TransactionState> emit) {
scannedContent.clearScannedContent();
scannedContent.clearScannedContent(type: ScannedType.address);
scannedContent.clearScannedContent(type: ScannedType.authorization);
selectedUtxos.clear();
inputs.clear();
outputs.clear();
Expand Down
5 changes: 4 additions & 1 deletion lib/globals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
37 changes: 20 additions & 17 deletions lib/screens/create_wallet/enc_xprv_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -100,10 +101,10 @@ class EnterXprvCardState extends State<EnterEncryptedXprvCard>
}

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() {
Expand Down Expand Up @@ -152,19 +153,21 @@ class EnterXprvCardState extends State<EnterEncryptedXprvCard>
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,
Expand Down
22 changes: 17 additions & 5 deletions lib/util/storage/scanned_content.dart
Original file line number Diff line number Diff line change
@@ -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;
}
}
17 changes: 10 additions & 7 deletions lib/widgets/inputs/input_address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ class _InputAddressState extends State<InputAddress> {
@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);
Expand Down Expand Up @@ -98,11 +98,14 @@ class _InputAddressState extends State<InputAddress> {
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,
Expand Down
1 change: 0 additions & 1 deletion lib/widgets/inputs/input_amount.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 6 additions & 4 deletions lib/widgets/inputs/input_authorization.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class _InputAuthorizationState extends State<InputAuthorization> {
@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);
Expand Down Expand Up @@ -100,8 +100,10 @@ class _InputAuthorizationState extends State<InputAuthorization> {
context,
MaterialPageRoute(
builder: (context) => QrScanner(
currentRoute: widget.route,
onChanged: (_value) => {})))
currentRoute: widget.route,
onChanged: (_value) => {},
type: ScannedType.authorization,
)))
},
))
: null,
Expand Down
10 changes: 6 additions & 4 deletions lib/widgets/inputs/input_xprv.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class _InputXprvState extends State<InputXprv> {
@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);
Expand Down Expand Up @@ -102,8 +102,10 @@ class _InputXprvState extends State<InputXprv> {
{
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => QrScanner(
currentRoute: widget.route,
onChanged: (_value) => {})))
currentRoute: widget.route,
onChanged: (_value) => {},
type: ScannedType.xprv,
)))
},
},
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -30,7 +32,8 @@ class QrScanner extends StatelessWidget {
final List<Barcode> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ class RecipientStepState extends State<RecipientStep>
}

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() {
Expand Down

0 comments on commit 8ef3c17

Please sign in to comment.