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

CW-898 fix fast scanner #1957

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 2 additions & 4 deletions lib/entities/qr_scanner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Future<String> presentQRScanner(BuildContext context) async {
),
);
isQrScannerShown = false;
return result??'';
return result!;
} catch (e) {
isQrScannerShown = false;
rethrow;
Expand Down Expand Up @@ -95,9 +95,7 @@ class _BarcodeScannerSimpleState extends State<BarcodeScannerSimple> {
setState(() {
popped = true;
});
SchedulerBinding.instance.addPostFrameCallback((_) {
Navigator.of(context).pop(_barcode?.rawValue ?? "");
});
Navigator.of(context).pop(_barcode!.rawValue ?? _barcode!.rawBytes);
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions lib/view_model/node_list/node_create_or_edit_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:cake_wallet/core/execution_state.dart';
import 'package:cake_wallet/entities/qr_scanner.dart';
import 'package:cake_wallet/store/settings_store.dart';
import 'package:cw_core/utils/print_verbose.dart';
import 'package:flutter/cupertino.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
Expand Down Expand Up @@ -214,29 +215,26 @@ abstract class NodeCreateOrEditViewModelBase with Store {
await PermissionHandler.checkPermission(Permission.camera, context);
if (!isCameraPermissionGranted) return;
String code = await presentQRScanner(context);

if (code.isEmpty) {
throw Exception('Unexpected scan QR code value: value is empty');
}

final uri = Uri.tryParse(code);

if (uri == null) {
throw Exception('Unexpected scan QR code value: Value is invalid');
}
final uri = Uri.parse(code);

final userInfo = uri.userInfo.split(':');

if (userInfo.length < 2) {
throw Exception('Unexpected scan QR code value: Value is invalid');
}

final rpcUser = userInfo[0];
final rpcPassword = userInfo[1];
final rpcUser = userInfo.length == 2 ? userInfo[0] : '';
final rpcPassword = userInfo.length == 2 ? userInfo[1] : '';
final ipAddress = uri.host;
final port = uri.port.toString();
final path = uri.path;

await Future.delayed(Duration(milliseconds: 345));

setAddress(ipAddress);
setPath(path);
setPassword(rpcPassword);
Expand Down
2 changes: 1 addition & 1 deletion pubspec_base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies:
fast_scanner:
git:
url: https://github.com/MrCyjaneK/fast_scanner
ref: c5a08720216a508bf1fe3d062ad19d2836545a42
ref: 69b3276b090fa6ac01b4483ca3adca93a8e615be
http: ^1.1.0
path_provider: ^2.0.11
mobx: ^2.1.4
Expand Down