mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-24 12:46:45 +00:00
remember recent servers for quick reconfiguration
This commit is contained in:
parent
25dd0440f6
commit
d7ff73243c
6 changed files with 122 additions and 11 deletions
|
@ -846,6 +846,7 @@ public class AppServices {
|
||||||
addMempoolRateSizes(event.getMempoolRateSizes());
|
addMempoolRateSizes(event.getMempoolRateSizes());
|
||||||
minimumRelayFeeRate = event.getMinimumRelayFeeRate();
|
minimumRelayFeeRate = event.getMinimumRelayFeeRate();
|
||||||
latestBlockHeader = event.getBlockHeader();
|
latestBlockHeader = event.getBlockHeader();
|
||||||
|
Config.get().addRecentServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
|
|
|
@ -12,6 +12,8 @@ import org.controlsfx.control.textfield.CustomTextField;
|
||||||
public class ComboBoxTextField extends CustomTextField {
|
public class ComboBoxTextField extends CustomTextField {
|
||||||
private final ObjectProperty<ComboBox<?>> comboProperty = new SimpleObjectProperty<>();
|
private final ObjectProperty<ComboBox<?>> comboProperty = new SimpleObjectProperty<>();
|
||||||
|
|
||||||
|
private boolean comboShowing;
|
||||||
|
|
||||||
public ComboBoxTextField() {
|
public ComboBoxTextField() {
|
||||||
super();
|
super();
|
||||||
getStyleClass().add("combo-text-field");
|
getStyleClass().add("combo-text-field");
|
||||||
|
@ -26,7 +28,13 @@ public class ComboBoxTextField extends CustomTextField {
|
||||||
showComboButtonPane.setCursor(Cursor.DEFAULT);
|
showComboButtonPane.setCursor(Cursor.DEFAULT);
|
||||||
showComboButtonPane.setOnMouseReleased(e -> {
|
showComboButtonPane.setOnMouseReleased(e -> {
|
||||||
if(comboProperty.isNotNull().get()) {
|
if(comboProperty.isNotNull().get()) {
|
||||||
comboProperty.get().show();
|
if(comboShowing) {
|
||||||
|
comboProperty.get().hide();
|
||||||
|
} else {
|
||||||
|
comboProperty.get().show();
|
||||||
|
}
|
||||||
|
|
||||||
|
comboShowing = !comboShowing;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Currency;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
|
@ -52,10 +49,12 @@ public class Config {
|
||||||
private ServerType serverType;
|
private ServerType serverType;
|
||||||
private String publicElectrumServer;
|
private String publicElectrumServer;
|
||||||
private String coreServer;
|
private String coreServer;
|
||||||
|
private List<String> recentCoreServers;
|
||||||
private CoreAuthType coreAuthType;
|
private CoreAuthType coreAuthType;
|
||||||
private File coreDataDir;
|
private File coreDataDir;
|
||||||
private String coreAuth;
|
private String coreAuth;
|
||||||
private String electrumServer;
|
private String electrumServer;
|
||||||
|
private List<String> recentElectrumServers;
|
||||||
private File electrumServerCert;
|
private File electrumServerCert;
|
||||||
private boolean useProxy;
|
private boolean useProxy;
|
||||||
private String proxyServer;
|
private String proxyServer;
|
||||||
|
@ -397,6 +396,23 @@ public class Config {
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getRecentCoreServers() {
|
||||||
|
return recentCoreServers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRecentCoreServer(String coreServer) {
|
||||||
|
if(recentCoreServers == null) {
|
||||||
|
recentCoreServers = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!recentCoreServers.contains(coreServer)) {
|
||||||
|
recentCoreServers.stream().filter(url -> Objects.equals(Protocol.getHost(url), Protocol.getHost(coreServer)))
|
||||||
|
.findFirst().ifPresent(existingUrl -> recentCoreServers.remove(existingUrl));
|
||||||
|
recentCoreServers.add(coreServer);
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public CoreAuthType getCoreAuthType() {
|
public CoreAuthType getCoreAuthType() {
|
||||||
return coreAuthType;
|
return coreAuthType;
|
||||||
}
|
}
|
||||||
|
@ -433,6 +449,31 @@ public class Config {
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getRecentElectrumServers() {
|
||||||
|
return recentElectrumServers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRecentServer() {
|
||||||
|
if(serverType == ServerType.BITCOIN_CORE && coreServer != null) {
|
||||||
|
addRecentCoreServer(coreServer);
|
||||||
|
} else if(serverType == ServerType.ELECTRUM_SERVER && electrumServer != null) {
|
||||||
|
addRecentElectrumServer(electrumServer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addRecentElectrumServer(String electrumServer) {
|
||||||
|
if(recentElectrumServers == null) {
|
||||||
|
recentElectrumServers = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!recentElectrumServers.contains(electrumServer)) {
|
||||||
|
recentElectrumServers.stream().filter(url -> Objects.equals(Protocol.getHost(url), Protocol.getHost(electrumServer)))
|
||||||
|
.findFirst().ifPresent(existingUrl -> recentElectrumServers.remove(existingUrl));
|
||||||
|
recentElectrumServers.add(electrumServer);
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public File getElectrumServerCert() {
|
public File getElectrumServerCert() {
|
||||||
return electrumServerCert;
|
return electrumServerCert;
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,4 +144,13 @@ public enum Protocol {
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getHost(String url) {
|
||||||
|
Protocol protocol = getProtocol(url);
|
||||||
|
if(protocol != null) {
|
||||||
|
return protocol.getServerHostAndPort(url).getHost();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.sparrowwallet.drongo.Network;
|
||||||
import com.sparrowwallet.sparrow.AppServices;
|
import com.sparrowwallet.sparrow.AppServices;
|
||||||
import com.sparrowwallet.sparrow.EventManager;
|
import com.sparrowwallet.sparrow.EventManager;
|
||||||
import com.sparrowwallet.sparrow.Mode;
|
import com.sparrowwallet.sparrow.Mode;
|
||||||
|
import com.sparrowwallet.sparrow.control.ComboBoxTextField;
|
||||||
import com.sparrowwallet.sparrow.control.TextFieldValidator;
|
import com.sparrowwallet.sparrow.control.TextFieldValidator;
|
||||||
import com.sparrowwallet.sparrow.control.UnlabeledToggleSwitch;
|
import com.sparrowwallet.sparrow.control.UnlabeledToggleSwitch;
|
||||||
import com.sparrowwallet.sparrow.event.*;
|
import com.sparrowwallet.sparrow.event.*;
|
||||||
|
@ -23,6 +24,7 @@ import javafx.stage.DirectoryChooser;
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
|
import javafx.util.StringConverter;
|
||||||
import org.berndpruenster.netlayer.tor.Tor;
|
import org.berndpruenster.netlayer.tor.Tor;
|
||||||
import org.controlsfx.control.SegmentedButton;
|
import org.controlsfx.control.SegmentedButton;
|
||||||
import org.controlsfx.glyphfont.Glyph;
|
import org.controlsfx.glyphfont.Glyph;
|
||||||
|
@ -41,6 +43,7 @@ import java.io.FileInputStream;
|
||||||
import java.security.cert.CertificateFactory;
|
import java.security.cert.CertificateFactory;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -76,7 +79,10 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
private Form coreForm;
|
private Form coreForm;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField coreHost;
|
private ComboBox<String> recentCoreServers;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ComboBoxTextField coreHost;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField corePort;
|
private TextField corePort;
|
||||||
|
@ -115,7 +121,10 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
private Form electrumForm;
|
private Form electrumForm;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField electrumHost;
|
private ComboBox<String> recentElectrumServers;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ComboBoxTextField electrumHost;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField electrumPort;
|
private TextField electrumPort;
|
||||||
|
@ -258,6 +267,29 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
recentCoreServers.setConverter(new UrlHostConverter());
|
||||||
|
recentCoreServers.setItems(FXCollections.observableList(Config.get().getRecentCoreServers() == null ? new ArrayList<>() : Config.get().getRecentCoreServers()));
|
||||||
|
recentCoreServers.prefWidthProperty().bind(coreHost.widthProperty());
|
||||||
|
recentCoreServers.valueProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if(newValue != null && Protocol.getProtocol(newValue) != null) {
|
||||||
|
HostAndPort hostAndPort = Protocol.getProtocol(newValue).getServerHostAndPort(newValue);
|
||||||
|
coreHost.setText(hostAndPort.getHost());
|
||||||
|
corePort.setText(Integer.toString(hostAndPort.getPort()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
recentElectrumServers.setConverter(new UrlHostConverter());
|
||||||
|
recentElectrumServers.setItems(FXCollections.observableList(Config.get().getRecentElectrumServers() == null ? new ArrayList<>() : Config.get().getRecentElectrumServers()));
|
||||||
|
recentElectrumServers.prefWidthProperty().bind(electrumHost.widthProperty());
|
||||||
|
recentElectrumServers.valueProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
if(newValue != null && Protocol.getProtocol(newValue) != null) {
|
||||||
|
HostAndPort hostAndPort = Protocol.getProtocol(newValue).getServerHostAndPort(newValue);
|
||||||
|
electrumHost.setText(hostAndPort.getHost());
|
||||||
|
electrumPort.setText(Integer.toString(hostAndPort.getPort()));
|
||||||
|
electrumUseSsl.setSelected(Protocol.getProtocol(newValue) == Protocol.SSL);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
electrumUseSsl.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
electrumUseSsl.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
setElectrumServerInConfig(config);
|
setElectrumServerInConfig(config);
|
||||||
electrumCertificate.setDisable(!newValue);
|
electrumCertificate.setDisable(!newValue);
|
||||||
|
@ -507,6 +539,7 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
publicProxyHost.setDisable(!editable);
|
publicProxyHost.setDisable(!editable);
|
||||||
publicProxyPort.setDisable(!editable);
|
publicProxyPort.setDisable(!editable);
|
||||||
|
|
||||||
|
recentCoreServers.setVisible(editable);
|
||||||
coreHost.setDisable(!editable);
|
coreHost.setDisable(!editable);
|
||||||
corePort.setDisable(!editable);
|
corePort.setDisable(!editable);
|
||||||
coreAuthToggleGroup.getToggles().forEach(toggle -> ((ToggleButton)toggle).setDisable(!editable));
|
coreAuthToggleGroup.getToggles().forEach(toggle -> ((ToggleButton)toggle).setDisable(!editable));
|
||||||
|
@ -518,6 +551,7 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
coreProxyHost.setDisable(!editable);
|
coreProxyHost.setDisable(!editable);
|
||||||
coreProxyPort.setDisable(!editable);
|
coreProxyPort.setDisable(!editable);
|
||||||
|
|
||||||
|
recentElectrumServers.setVisible(editable);
|
||||||
electrumHost.setDisable(!editable);
|
electrumHost.setDisable(!editable);
|
||||||
electrumPort.setDisable(!editable);
|
electrumPort.setDisable(!editable);
|
||||||
electrumUseSsl.setDisable(!editable);
|
electrumUseSsl.setDisable(!editable);
|
||||||
|
@ -808,4 +842,16 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class UrlHostConverter extends StringConverter<String> {
|
||||||
|
@Override
|
||||||
|
public String toString(String serverUrl) {
|
||||||
|
return serverUrl == null || Protocol.getProtocol(serverUrl) == null ? "" : Protocol.getProtocol(serverUrl).getServerHostAndPort(serverUrl).getHost();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String fromString(String string) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
<?import com.sparrowwallet.sparrow.net.ServerType?>
|
<?import com.sparrowwallet.sparrow.net.ServerType?>
|
||||||
<?import com.sparrowwallet.sparrow.net.CoreAuthType?>
|
<?import com.sparrowwallet.sparrow.net.CoreAuthType?>
|
||||||
<?import com.sparrowwallet.sparrow.control.HelpLabel?>
|
<?import com.sparrowwallet.sparrow.control.HelpLabel?>
|
||||||
<?import javafx.collections.FXCollections?>
|
|
||||||
<?import com.sparrowwallet.sparrow.net.PublicElectrumServer?>
|
|
||||||
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
|
<?import com.sparrowwallet.sparrow.control.CopyableLabel?>
|
||||||
|
<?import com.sparrowwallet.sparrow.control.ComboBoxTextField?>
|
||||||
|
|
||||||
<GridPane hgap="10.0" vgap="10.0" stylesheets="@preferences.css, @../general.css" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.preferences.ServerPreferencesController">
|
<GridPane hgap="10.0" vgap="10.0" stylesheets="@preferences.css, @../general.css" xmlns="http://javafx.com/javafx/10.0.2-internal" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.sparrowwallet.sparrow.preferences.ServerPreferencesController">
|
||||||
<padding>
|
<padding>
|
||||||
<Insets left="25.0" right="25.0" top="25.0" />
|
<Insets left="25.0" right="25.0" top="25.0" />
|
||||||
|
@ -100,7 +100,10 @@
|
||||||
<Form fx:id="coreForm" GridPane.columnIndex="0" GridPane.rowIndex="1">
|
<Form fx:id="coreForm" GridPane.columnIndex="0" GridPane.rowIndex="1">
|
||||||
<Fieldset inputGrow="SOMETIMES" text="Bitcoin Core RPC">
|
<Fieldset inputGrow="SOMETIMES" text="Bitcoin Core RPC">
|
||||||
<Field text="URL:">
|
<Field text="URL:">
|
||||||
<TextField fx:id="coreHost" promptText="e.g. 127.0.0.1"/>
|
<StackPane>
|
||||||
|
<ComboBox fx:id="recentCoreServers" />
|
||||||
|
<ComboBoxTextField fx:id="coreHost" promptText="e.g. 127.0.0.1" comboProperty="$recentCoreServers" />
|
||||||
|
</StackPane>
|
||||||
<TextField fx:id="corePort" promptText="e.g. 8332" maxWidth="120" />
|
<TextField fx:id="corePort" promptText="e.g. 8332" maxWidth="120" />
|
||||||
</Field>
|
</Field>
|
||||||
<Field text="Authentication:">
|
<Field text="Authentication:">
|
||||||
|
@ -147,7 +150,10 @@
|
||||||
<Form fx:id="electrumForm" GridPane.columnIndex="0" GridPane.rowIndex="1">
|
<Form fx:id="electrumForm" GridPane.columnIndex="0" GridPane.rowIndex="1">
|
||||||
<Fieldset inputGrow="SOMETIMES" text="Private Electrum Server">
|
<Fieldset inputGrow="SOMETIMES" text="Private Electrum Server">
|
||||||
<Field text="URL:">
|
<Field text="URL:">
|
||||||
<TextField fx:id="electrumHost" promptText="e.g. 127.0.0.1 or Tor hostname (.onion)"/>
|
<StackPane>
|
||||||
|
<ComboBox fx:id="recentElectrumServers" />
|
||||||
|
<ComboBoxTextField fx:id="electrumHost" promptText="e.g. 127.0.0.1 or Tor hostname (.onion)" comboProperty="$recentElectrumServers" />
|
||||||
|
</StackPane>
|
||||||
<TextField fx:id="electrumPort" promptText="e.g. 50002" maxWidth="120" />
|
<TextField fx:id="electrumPort" promptText="e.g. 50002" maxWidth="120" />
|
||||||
</Field>
|
</Field>
|
||||||
<Field text="Use SSL:">
|
<Field text="Use SSL:">
|
||||||
|
|
Loading…
Reference in a new issue