mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
allow no scheme in add/edit xmr/wow node url entry field. Auto try https first then http if none entered.
This commit is contained in:
parent
7a1b094eff
commit
a5fd214d32
1 changed files with 50 additions and 34 deletions
|
@ -62,6 +62,44 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
|
|||
late bool saveEnabled;
|
||||
late bool testConnectionEnabled;
|
||||
|
||||
Future<bool> _xmrHelper(String url, int? port) async {
|
||||
final uri = Uri.parse(url);
|
||||
|
||||
final String path = uri.path.isEmpty ? "/json_rpc" : uri.path;
|
||||
|
||||
final uriString = "${uri.scheme}://${uri.host}:${port ?? 0}$path";
|
||||
|
||||
ref.read(nodeFormDataProvider).useSSL = true;
|
||||
|
||||
final response = await testMoneroNodeConnection(
|
||||
Uri.parse(uriString),
|
||||
false,
|
||||
);
|
||||
|
||||
if (response.cert != null) {
|
||||
if (mounted) {
|
||||
final shouldAllowBadCert = await showBadX509CertificateDialog(
|
||||
response.cert!,
|
||||
response.url!,
|
||||
response.port!,
|
||||
context,
|
||||
);
|
||||
|
||||
if (shouldAllowBadCert) {
|
||||
final response =
|
||||
await testMoneroNodeConnection(Uri.parse(uriString), true);
|
||||
ref.read(nodeFormDataProvider).host = url;
|
||||
return response.success;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ref.read(nodeFormDataProvider).host = url;
|
||||
return response.success;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<bool> _testConnection({bool showFlushBar = true}) async {
|
||||
final formData = ref.read(nodeFormDataProvider);
|
||||
|
||||
|
@ -86,41 +124,19 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
|
|||
case Coin.monero:
|
||||
case Coin.wownero:
|
||||
try {
|
||||
final uri = Uri.parse(formData.host!);
|
||||
if (uri.scheme.startsWith("http")) {
|
||||
final String path = uri.path.isEmpty ? "/json_rpc" : uri.path;
|
||||
final url = formData.host!;
|
||||
final uri = Uri.tryParse(url);
|
||||
if (uri != null) {
|
||||
if (!uri.hasScheme) {
|
||||
// try https first
|
||||
testPassed = await _xmrHelper("https://$url", formData.port);
|
||||
|
||||
String uriString =
|
||||
"${uri.scheme}://${uri.host}:${formData.port ?? 0}$path";
|
||||
|
||||
if (uri.host == "https") {
|
||||
ref.read(nodeFormDataProvider).useSSL = true;
|
||||
} else {
|
||||
ref.read(nodeFormDataProvider).useSSL = false;
|
||||
}
|
||||
|
||||
final response = await testMoneroNodeConnection(
|
||||
Uri.parse(uriString),
|
||||
false,
|
||||
);
|
||||
|
||||
if (response.cert != null) {
|
||||
if (mounted) {
|
||||
final shouldAllowBadCert = await showBadX509CertificateDialog(
|
||||
response.cert!,
|
||||
response.url!,
|
||||
response.port!,
|
||||
context,
|
||||
);
|
||||
|
||||
if (shouldAllowBadCert) {
|
||||
final response = await testMoneroNodeConnection(
|
||||
Uri.parse(uriString), true);
|
||||
testPassed = response.success;
|
||||
}
|
||||
if (testPassed == false) {
|
||||
// try http
|
||||
testPassed = await _xmrHelper("http://$url", formData.port);
|
||||
}
|
||||
} else {
|
||||
testPassed = response.success;
|
||||
testPassed = await _xmrHelper(url, formData.port);
|
||||
}
|
||||
}
|
||||
} catch (e, s) {
|
||||
|
@ -158,7 +174,7 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
|
|||
break;
|
||||
}
|
||||
|
||||
if (showFlushBar) {
|
||||
if (showFlushBar && mounted) {
|
||||
if (testPassed) {
|
||||
unawaited(showFloatingFlushBar(
|
||||
type: FlushBarType.success,
|
||||
|
@ -182,7 +198,7 @@ class _AddEditNodeViewState extends ConsumerState<AddEditNodeView> {
|
|||
|
||||
bool? shouldSave;
|
||||
|
||||
if (!canConnect) {
|
||||
if (!canConnect && mounted) {
|
||||
await showDialog<dynamic>(
|
||||
context: context,
|
||||
useSafeArea: true,
|
||||
|
|
Loading…
Reference in a new issue