Allow for domains in add node dialog

This commit is contained in:
pokkst 2022-09-17 18:47:23 -05:00
parent d6d5e82bec
commit 142a42c84c
No known key found for this signature in database
GPG Key ID: 90C2ED85E67A50FF
3 changed files with 3 additions and 56 deletions

View File

@ -21,7 +21,6 @@ import net.mynero.wallet.model.WalletManager;
import net.mynero.wallet.util.OnionHelper;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URLDecoder;
import java.net.URLEncoder;
@ -286,56 +285,4 @@ public class Node {
password = anotherNode.password;
favourite = anotherNode.favourite;
}
static class Address {
final private InetAddress inet;
final private String onion;
private Address(InetAddress address, String onion) {
this.inet = address;
this.onion = onion;
}
static Address of(InetAddress address) {
return new Address(address, null);
}
static Address of(String host) throws UnknownHostException {
if (OnionHelper.isOnionHost(host)) {
return new Address(null, host);
} else {
return new Address(InetAddress.getByName(host), null);
}
}
public boolean isOnion() {
return onion != null;
}
public String getHostName() {
if (inet != null) {
return inet.getHostName();
} else {
return onion;
}
}
public String getHostAddress() {
if (inet != null) {
return inet.getHostAddress();
} else {
return onion;
}
}
@Override
public int hashCode() {
return getHostAddress().hashCode();
}
@Override
public boolean equals(Object other) {
return (other instanceof Address) && (getHostAddress().equals(((Address) other).getHostAddress()));
}
}
}

View File

@ -53,8 +53,8 @@ public class AddNodeBottomSheetDialog extends BottomSheetDialogFragment {
String address = nodeParts[0];
int port = Integer.parseInt(nodeParts[1]);
String newNodeString = address + ":" + port + "/mainnet/" + name;
boolean validIp = Patterns.IP_ADDRESS.matcher(address).matches();
if(validIp) {
boolean validAddress = Patterns.IP_ADDRESS.matcher(address).matches() || Patterns.DOMAIN_NAME.matcher(address).matches();
if(validAddress) {
String nodesArray = PrefService.getInstance().getString(Constants.PREF_CUSTOM_NODES, "[]");
JSONArray jsonArray = new JSONArray(nodesArray);
boolean exists = false;

View File

@ -65,7 +65,7 @@
android:background="@drawable/edittext_bg"
android:hint="@string/node_address_hint"
android:inputType="text"
android:digits="1234567890.:"
android:digits="-QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890.:"
app:layout_constraintBottom_toTopOf="@id/add_node_button"
app:layout_constraintEnd_toStartOf="@id/paste_address_imagebutton"
app:layout_constraintStart_toStartOf="parent" />