Skip to content
Merged

Fixes #1023

Show file tree
Hide file tree
Changes from all commits
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 @@ -66,6 +66,62 @@ class _NewContactAddressEntryFormState

List<CryptoCurrency> coins = [];

void _onQrTapped() async {
try {
// ref
// .read(shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = false;
final qrResult = await widget.barcodeScanner.scan();

// Future<void>.delayed(
// const Duration(seconds: 2),
// () => ref
// .read(
// shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = true,
// );

final paymentData = AddressUtils.parsePaymentUri(
qrResult.rawContent,
logging: Logging.instance,
);

if (paymentData != null) {
addressController.text = paymentData.address;
ref.read(addressEntryDataProvider(widget.id)).address =
addressController.text.isEmpty ? null : addressController.text;

addressLabelController.text =
paymentData.label ?? addressLabelController.text;
ref.read(addressEntryDataProvider(widget.id)).addressLabel =
addressLabelController.text.isEmpty
? null
: addressLabelController.text;

// now check for non standard encoded basic address
} else if (ref.read(addressEntryDataProvider(widget.id)).coin != null) {
if (ref.read(addressEntryDataProvider(widget.id)).coin!.validateAddress(
qrResult.rawContent,
)) {
addressController.text = qrResult.rawContent;
ref.read(addressEntryDataProvider(widget.id)).address =
qrResult.rawContent;
}
}
} on PlatformException catch (e, s) {
// ref
// .read(shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = true;
Logging.instance.log(
"Failed to get camera permissions to scan address qr code: $e\n$s",
level: LogLevel.Warning,
);
}
}

@override
void initState() {
addressLabelController = TextEditingController()
Expand Down Expand Up @@ -404,71 +460,7 @@ class _NewContactAddressEntryFormState
null)
TextFieldIconButton(
key: const Key("addAddressBookEntryScanQrButtonKey"),
onTap: () async {
try {
// ref
// .read(shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = false;
final qrResult = await widget.barcodeScanner.scan();

// Future<void>.delayed(
// const Duration(seconds: 2),
// () => ref
// .read(
// shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = true,
// );

final results =
AddressUtils.parseUri(qrResult.rawContent);
if (results.isNotEmpty) {
addressController.text = results["address"] ?? "";
ref
.read(addressEntryDataProvider(widget.id))
.address =
addressController.text.isEmpty
? null
: addressController.text;

addressLabelController.text = results["label"] ??
addressLabelController.text;
ref
.read(addressEntryDataProvider(widget.id))
.addressLabel =
addressLabelController.text.isEmpty
? null
: addressLabelController.text;

// now check for non standard encoded basic address
} else if (ref
.read(addressEntryDataProvider(widget.id))
.coin !=
null) {
if (ref
.read(addressEntryDataProvider(widget.id))
.coin!
.validateAddress(
qrResult.rawContent,
)) {
addressController.text = qrResult.rawContent;
ref
.read(addressEntryDataProvider(widget.id))
.address = qrResult.rawContent;
}
}
} on PlatformException catch (e, s) {
// ref
// .read(shouldShowLockscreenOnResumeStateProvider
// .state)
// .state = true;
Logging.instance.log(
"Failed to get camera permissions to scan address qr code: $e\n$s",
level: LogLevel.Warning,
);
}
},
onTap: _onQrTapped,
child: const QrCodeIcon(),
),
const SizedBox(
Expand Down
112 changes: 55 additions & 57 deletions lib/pages/buy_view/buy_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,60 @@ class _BuyFormState extends ConsumerState<BuyForm> {
}
}

void _onQrTapped() async {
try {
if (FocusScope.of(context).hasFocus) {
FocusScope.of(context).unfocus();
await Future<void>.delayed(
const Duration(milliseconds: 75),
);
}

final qrResult = await scanner.scan();

Logging.instance.log(
"qrResult content: ${qrResult.rawContent}",
level: LogLevel.Info,
);

final paymentData = AddressUtils.parsePaymentUri(
qrResult.rawContent,
logging: Logging.instance,
);

Logging.instance.log(
"qrResult parsed: $paymentData",
level: LogLevel.Info,
);

if (paymentData != null) {
// auto fill address
_address = paymentData.address;
_receiveAddressController.text = _address!;

setState(() {
_addressToggleFlag = _receiveAddressController.text.isNotEmpty;
});

// now check for non standard encoded basic address
} else {
_address = qrResult.rawContent;
_receiveAddressController.text = _address ?? "";

setState(() {
_addressToggleFlag = _receiveAddressController.text.isNotEmpty;
});
}
} on PlatformException catch (e, s) {
// here we ignore the exception caused by not giving permission
// to use the camera to scan a qr code
Logging.instance.log(
"Failed to get camera permissions while trying to scan qr code in SendView: $e\n$s",
level: LogLevel.Warning,
);
}
}

@override
void initState() {
_receiveAddressController = TextEditingController();
Expand Down Expand Up @@ -1375,63 +1429,7 @@ class _BuyFormState extends ConsumerState<BuyForm> {
!isDesktop)
TextFieldIconButton(
key: const Key("buyViewScanQrButtonKey"),
onTap: () async {
try {
if (FocusScope.of(context).hasFocus) {
FocusScope.of(context).unfocus();
await Future<void>.delayed(
const Duration(milliseconds: 75),
);
}

final qrResult = await scanner.scan();

Logging.instance.log(
"qrResult content: ${qrResult.rawContent}",
level: LogLevel.Info,
);

final results = AddressUtils.parseUri(
qrResult.rawContent,
);

Logging.instance.log(
"qrResult parsed: $results",
level: LogLevel.Info,
);

if (results.isNotEmpty) {
// auto fill address
_address = results["address"] ?? "";
_receiveAddressController.text = _address!;

setState(() {
_addressToggleFlag =
_receiveAddressController
.text.isNotEmpty;
});

// now check for non standard encoded basic address
} else {
_address = qrResult.rawContent;
_receiveAddressController.text =
_address ?? "";

setState(() {
_addressToggleFlag =
_receiveAddressController
.text.isNotEmpty;
});
}
} on PlatformException catch (e, s) {
// here we ignore the exception caused by not giving permission
// to use the camera to scan a qr code
Logging.instance.log(
"Failed to get camera permissions while trying to scan qr code in SendView: $e\n$s",
level: LogLevel.Warning,
);
}
},
onTap: _onQrTapped,
child: const QrCodeIcon(),
),
],
Expand Down
Loading
Loading