Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: scanned content values #622

Open
wants to merge 3 commits into
base: 2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading