mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-21 18:24:41 +00:00
fix:node QR Code URI parsing
This commit is contained in:
parent
eb8c6a76e2
commit
ef0054b057
2 changed files with 13 additions and 14 deletions
|
@ -58,6 +58,12 @@ class NodeForm extends StatelessWidget {
|
|||
}
|
||||
});
|
||||
|
||||
reaction((_) => nodeViewModel.path, (String path) {
|
||||
if (path != _pathController.text) {
|
||||
_pathController.text = path;
|
||||
}
|
||||
});
|
||||
|
||||
_addressController.addListener(() => nodeViewModel.address = _addressController.text);
|
||||
_pathController.addListener(() => nodeViewModel.path = _pathController.text);
|
||||
_portController.addListener(() => nodeViewModel.port = _portController.text);
|
||||
|
|
|
@ -219,28 +219,21 @@ abstract class NodeCreateOrEditViewModelBase with Store {
|
|||
throw Exception('Unexpected scan QR code value: value is empty');
|
||||
}
|
||||
|
||||
if (!code.contains('://')) {
|
||||
code = 'tcp://$code';
|
||||
}
|
||||
|
||||
final uri = Uri.tryParse(code);
|
||||
|
||||
if (uri == null) {
|
||||
throw Exception('Unexpected scan QR code value: Value is invalid');
|
||||
if (uri == null || uri.host.isEmpty) {
|
||||
throw Exception('Invalid QR code: Unable to parse or missing host.');
|
||||
}
|
||||
|
||||
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 ipAddress = uri.host;
|
||||
final port = uri.port.toString();
|
||||
final port = uri.hasPort ? uri.port.toString() : '';
|
||||
final path = uri.path;
|
||||
|
||||
setAddress(ipAddress);
|
||||
setPath(path);
|
||||
setPassword(rpcPassword);
|
||||
setLogin(rpcUser);
|
||||
setPort(port);
|
||||
} on Exception catch (e) {
|
||||
connectionState = FailureState(e.toString());
|
||||
|
|
Loading…
Reference in a new issue