From 545342dfb4562c230765a2c5acb7f6f8be01be83 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 9 Feb 2023 10:29:19 +0200 Subject: [PATCH] disable server toggle when no server is configured (url host is empty) --- .../com/sparrowwallet/sparrow/AppController.java | 5 +++-- .../preferences/ServerPreferencesController.java | 12 ++++++++---- .../sparrowwallet/sparrow/preferences/server.fxml | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index d2674f1c..991d7ed3 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -386,7 +386,7 @@ public class AppController implements Initializable { configureSwitchServer(); setServerType(Config.get().getServerType()); serverToggle.setSelected(isConnected()); - serverToggle.setDisable(Config.get().getServerType() == null); + serverToggle.setDisable(!Config.get().hasServer()); onlineProperty().bindBidirectional(serverToggle.selectedProperty()); onlineProperty().addListener(new WeakChangeListener<>(serverToggleOnlineListener)); serverToggle.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> { @@ -1248,6 +1248,7 @@ public class AppController implements Initializable { PreferencesDialog preferencesDialog = new PreferencesDialog(preferenceGroup); preferencesDialog.showAndWait(); configureSwitchServer(); + serverToggle.setDisable(!Config.get().hasServer()); } public void signVerifyMessage(ActionEvent event) { @@ -2091,7 +2092,7 @@ public class AppController implements Initializable { serverToggle.getStyleClass().remove("core-server"); } - serverToggle.setDisable(false); + serverToggle.setDisable(!Config.get().hasServer()); } public void setTheme(ActionEvent event) { diff --git a/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java b/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java index 6a7786cf..956ba817 100644 --- a/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java +++ b/src/main/java/com/sparrowwallet/sparrow/preferences/ServerPreferencesController.java @@ -748,11 +748,13 @@ public class ServerPreferencesController extends PreferencesDetailController { String hostAsString = getHost(coreHost.getText()); Integer portAsInteger = getPort(corePort.getText()); - if(hostAsString != null && portAsInteger != null && isValidPort(portAsInteger)) { + if(hostAsString != null && !hostAsString.isEmpty() && portAsInteger != null && isValidPort(portAsInteger)) { Protocol protocol = portAsInteger == Protocol.HTTPS.getDefaultPort() ? Protocol.HTTPS : Protocol.HTTP; config.setCoreServer(new Server(protocol.toUrlString(hostAsString, portAsInteger))); - } else if(hostAsString != null) { + } else if(hostAsString != null && !hostAsString.isEmpty()) { config.setCoreServer(new Server(Protocol.HTTP.toUrlString(hostAsString))); + } else { + config.setCoreServer(null); } } @@ -781,10 +783,12 @@ public class ServerPreferencesController extends PreferencesDetailController { String hostAsString = getHost(electrumHost.getText()); Integer portAsInteger = getPort(electrumPort.getText()); - if(hostAsString != null && portAsInteger != null && isValidPort(portAsInteger)) { + if(hostAsString != null && !hostAsString.isEmpty() && portAsInteger != null && isValidPort(portAsInteger)) { config.setElectrumServer(new Server(getProtocol().toUrlString(hostAsString, portAsInteger))); - } else if(hostAsString != null) { + } else if(hostAsString != null && !hostAsString.isEmpty()) { config.setElectrumServer(new Server(getProtocol().toUrlString(hostAsString))); + } else { + config.setElectrumServer(null); } } diff --git a/src/main/resources/com/sparrowwallet/sparrow/preferences/server.fxml b/src/main/resources/com/sparrowwallet/sparrow/preferences/server.fxml index 43691886..fb504815 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/preferences/server.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/preferences/server.fxml @@ -154,7 +154,7 @@ - +