diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Config.java b/src/main/java/com/sparrowwallet/sparrow/io/Config.java index f93ad0f4..83b13cc2 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Config.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Config.java @@ -7,6 +7,7 @@ import com.sparrowwallet.sparrow.Mode; import com.sparrowwallet.sparrow.Theme; import com.sparrowwallet.sparrow.control.QRDensity; import com.sparrowwallet.sparrow.control.WebcamResolution; +import com.sparrowwallet.sparrow.joinstr.VpnGateway; import com.sparrowwallet.sparrow.net.*; import com.sparrowwallet.sparrow.wallet.FeeRatesSelection; import com.sparrowwallet.sparrow.wallet.OptimizationStrategy; @@ -82,6 +83,18 @@ public class Config { private Double appWidth; private Double appHeight; + // Joinstr settings + + private VpnGateway vpnGateway; + + private String nostrRelay; + + private String nodeUsername; + + private String nodePassword; + + // ================ + private static Config INSTANCE; private static Gson getGson() { @@ -685,6 +698,41 @@ public class Config { flush(); } + public VpnGateway getVpnGateway() { + return vpnGateway; + } + + public void setVpnGateway(VpnGateway vpnGateway) { + this.vpnGateway = vpnGateway; + flush(); + } + + public String getNostrRelay() { + return nostrRelay; + } + + public void setNostrRelay(String nostrRelay) { + this.nostrRelay = nostrRelay; + flush(); + } + + public String getNodeUsername() { + return nodeUsername; + } + + public void setNodeUsername(String nodeUsername) { + this.nodeUsername = nodeUsername; + flush(); + } + + public String getNodePassword() { + return nodePassword; + } + public void setNodePassword(String nodePassword) { + this.nodePassword = nodePassword; + flush(); + } + private synchronized void flush() { Gson gson = getGson(); try { diff --git a/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrController.java b/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrController.java index 9d475e25..35a60a25 100644 --- a/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrController.java +++ b/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrController.java @@ -22,6 +22,8 @@ public class JoinstrController extends JoinstrFormController { private Stage stage; + protected String selectedWallet; + @FXML private StackPane joinstrPane; @@ -49,7 +51,7 @@ public class JoinstrController extends JoinstrFormController { if(joinstrDisplay.getUserData().equals(display)) { existing = true; joinstrDisplay.setViewOrder(0); - } else if(display != JoinstrDisplay.LOCK) { + } else { joinstrDisplay.setViewOrder(1); } } @@ -68,17 +70,14 @@ public class JoinstrController extends JoinstrFormController { joinstrDisplay.setUserData(display); joinstrDisplay.setViewOrder(1); - JoinstrFormController controller = displayLoader.getController(); - JoinstrForm joinstrForm = getJoinstrForm(); - controller.setJoinstrForm(joinstrForm); - controller.initializeView(); - joinstrPane.getChildren().add(joinstrDisplay); } - else { - JoinstrFormController controller = displayLoader.getController(); - controller.initializeView(); - } + + JoinstrFormController controller = displayLoader.getController(); + JoinstrForm joinstrForm = getJoinstrForm(); + controller.setJoinstrForm(joinstrForm); + controller.initializeView(); + } catch (IOException e) { throw new IllegalStateException("Can't find pane", e); } diff --git a/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrDisplay.java b/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrDisplay.java index bf23f146..7fc2d19b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrDisplay.java +++ b/src/main/java/com/sparrowwallet/sparrow/joinstr/JoinstrDisplay.java @@ -5,5 +5,5 @@ public enum JoinstrDisplay { MY_POOLS, OTHER_POOLS, HISTORY, - LOCK + SETTINGS } diff --git a/src/main/java/com/sparrowwallet/sparrow/joinstr/OtherPoolsController.java b/src/main/java/com/sparrowwallet/sparrow/joinstr/OtherPoolsController.java index 76f42094..000ff945 100644 --- a/src/main/java/com/sparrowwallet/sparrow/joinstr/OtherPoolsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/joinstr/OtherPoolsController.java @@ -4,8 +4,6 @@ import com.sparrowwallet.sparrow.joinstr.control.JoinstrInfoPane; import com.sparrowwallet.sparrow.joinstr.control.JoinstrPoolList; import javafx.beans.property.SimpleStringProperty; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.TextField; diff --git a/src/main/java/com/sparrowwallet/sparrow/joinstr/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/joinstr/SettingsController.java new file mode 100644 index 00000000..9746bb4b --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/joinstr/SettingsController.java @@ -0,0 +1,151 @@ +package com.sparrowwallet.sparrow.joinstr; + +import com.sparrowwallet.sparrow.io.Config; + +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.scene.control.TextField; +import javafx.scene.control.PasswordField; + +public class SettingsController extends JoinstrFormController { + + @FXML + Label urlLabel; + + @FXML + Label selectedWalletLabel; + + @FXML + TextField usernameTextField; + + @FXML + PasswordField passwordTextField; + + @FXML + TextField nostrRelayTextField; + + @FXML + TextField hostTextField; + + @FXML + TextField locationTextField; + + @FXML + TextField ipAddressTextField; + + @FXML + TextField portTextField; + + @FXML + TextField protocolTextField; + + private VpnGateway vpnGateway; + + @Override + public void initializeView() { + + try { + + // Node settings + urlLabel.setText(Config.get().getServer().getUrl()); + selectedWalletLabel.setText(this.getJoinstrForm().getWallet().getName()); + + usernameTextField.setText(Config.get().getNodeUsername()); + usernameTextField.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + Config.get().setNodeUsername(usernameTextField.getText()); + } + }); + + passwordTextField.setText(Config.get().getNodePassword()); + passwordTextField.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + Config.get().setNodePassword(passwordTextField.getText()); + } + }); + + nostrRelayTextField.setText(Config.get().getNostrRelay()); + nostrRelayTextField.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + if(nostrRelayTextField.getText().isEmpty()) { + nostrRelayTextField.setText("wss://nostr.fmt.wiz.biz"); + } + Config.get().setNostrRelay(nostrRelayTextField.getText()); + } + }); + + // VPN Gateway settings + vpnGateway = Config.get().getVpnGateway(); + if(vpnGateway == null) + vpnGateway = new VpnGateway(); + + hostTextField.setText(vpnGateway.getHost()); + hostTextField.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + vpnGateway.setHost(hostTextField.getText()); + Config.get().setVpnGateway(vpnGateway); + } + }); + + locationTextField.setText(vpnGateway.getLocation()); + locationTextField.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + vpnGateway.setLocation(locationTextField.getText()); + Config.get().setVpnGateway(vpnGateway); + } + }); + + ipAddressTextField.setText(vpnGateway.getIpAddress()); + ipAddressTextField.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + vpnGateway.setIpAddress(ipAddressTextField.getText()); + Config.get().setVpnGateway(vpnGateway); + } + }); + + portTextField.setText(String.valueOf(vpnGateway.getPort())); + portTextField.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + if (!newValue.matches("\\d{0,4}")) { + portTextField.setText(newValue.replaceAll("[^\\d]", "")); + } + if (newValue.length() > 4) { + portTextField.setText(newValue.substring(0, 4)); + } + vpnGateway.setPort(Integer.getInteger(portTextField.getText())); + Config.get().setVpnGateway(vpnGateway); + } + }); + + protocolTextField.setText(vpnGateway.getProtocol()); + protocolTextField.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + vpnGateway.setProtocol(protocolTextField.getText()); + Config.get().setVpnGateway(vpnGateway); + } + }); + + } catch(Exception e) { + if(e != null) {} + } + } + +} diff --git a/src/main/java/com/sparrowwallet/sparrow/joinstr/VpnGateway.java b/src/main/java/com/sparrowwallet/sparrow/joinstr/VpnGateway.java new file mode 100644 index 00000000..fce7687d --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/joinstr/VpnGateway.java @@ -0,0 +1,38 @@ +package com.sparrowwallet.sparrow.joinstr; + +import java.io.Serializable; + +public class VpnGateway implements Serializable { + + private String host; + private String location; + private String ipAddress; + private int port; + private String protocol; + + public VpnGateway() {} + + public VpnGateway(String host, String location, String ipAddress, int port, String protocol) { + this.host = host; + this.location = location; + this.ipAddress = ipAddress; + this.port = port; + this.protocol = protocol; + } + + public String getHost() { return host; }; + public void setHost(String host) { this.host = host; }; + + public String getLocation() { return location; }; + public void setLocation(String location) { this.location = location; }; + + public String getIpAddress() { return ipAddress; }; + public void setIpAddress(String ipAddress) { this.ipAddress = ipAddress; }; + + public int getPort() { return port; }; + public void setPort(int port) { this.port = port; }; + + public String getProtocol() { return protocol; }; + public void setProtocol(String protocol) { this.protocol = protocol; }; + +} diff --git a/src/main/java/com/sparrowwallet/sparrow/joinstr/control/JoinstrPoolListRow.java b/src/main/java/com/sparrowwallet/sparrow/joinstr/control/JoinstrPoolListRow.java deleted file mode 100644 index 26269293..00000000 --- a/src/main/java/com/sparrowwallet/sparrow/joinstr/control/JoinstrPoolListRow.java +++ /dev/null @@ -1,170 +0,0 @@ -package com.sparrowwallet.sparrow.joinstr.control; - -import com.sparrowwallet.sparrow.joinstr.JoinstrAction; -import com.sparrowwallet.sparrow.joinstr.JoinstrPool; - -import javafx.event.ActionEvent; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.layout.ColumnConstraints; -import javafx.scene.layout.GridPane; -import javafx.scene.layout.Priority; -import javafx.scene.layout.VBox; - -public class JoinstrPoolListRow extends GridPane { - - private JoinstrPool poolData; - - /// Constructor for header - public JoinstrPoolListRow() { - - setMaxWidth(Double.MAX_VALUE); - setMaxHeight(Double.MAX_VALUE); - GridPane.setHgrow(this, Priority.ALWAYS); - setColumnConstraints(); - - Label relayLabel = new Label("Relay"); - GridPane.setRowIndex(relayLabel, 0); - GridPane.setColumnIndex(relayLabel, 0); - - Label pubkeyLabel = new Label("Pubkey (Shortened)"); - GridPane.setRowIndex(pubkeyLabel, 0); - GridPane.setColumnIndex(pubkeyLabel, 1); - - Label denominationLabel = new Label("Denomination"); - GridPane.setRowIndex(denominationLabel, 0); - GridPane.setColumnIndex(denominationLabel, 2); - - Label peersLabel = new Label("Peers"); - GridPane.setRowIndex(peersLabel, 0); - GridPane.setColumnIndex(peersLabel, 3); - - Label timeoutLabel = new Label("Timeout"); - GridPane.setRowIndex(timeoutLabel, 0); - GridPane.setColumnIndex(timeoutLabel, 4); - - Label actionLabel = new Label("Action"); - GridPane.setRowIndex(actionLabel, 0); - GridPane.setColumnIndex(actionLabel, 5); - - getChildren().addAll(relayLabel, pubkeyLabel, denominationLabel, peersLabel, timeoutLabel, actionLabel); - - getStyleClass().add("joinstr-list-header"); - - } - - /// Constructor for data rows - public JoinstrPoolListRow(JoinstrPool poolData_, JoinstrAction action) { - poolData = poolData_; - - setMaxWidth(Double.MAX_VALUE); - setMaxHeight(Double.MAX_VALUE); - GridPane.setHgrow(this, Priority.ALWAYS); - setColumnConstraints(); - - VBox relayVBox = new VBox(); - Label relayLabel = new Label(poolData.getRelay()); - relayLabel.getStyleClass().add("joinstr-list-item"); - - Label portLabel = new Label("Port: " + poolData.getPort().toString()); - portLabel.getStyleClass().add("joinstr-list-item-subtitle"); - - relayVBox.getChildren().addAll(relayLabel, portLabel); - GridPane.setRowIndex(relayVBox, 0); - GridPane.setColumnIndex(relayVBox, 0); - - VBox pubkeyVBox = new VBox(); - Label pubkeyLabel = new Label(poolData.getPubkey()); - pubkeyLabel.getStyleClass().add("joinstr-list-item"); - - Label pubkeyTypeLabel = new Label("type"); - pubkeyTypeLabel.getStyleClass().add("joinstr-list-item-subtitle"); - - pubkeyVBox.getChildren().addAll(pubkeyLabel, pubkeyTypeLabel); - GridPane.setRowIndex(pubkeyVBox, 0); - GridPane.setColumnIndex(pubkeyVBox, 1); - - VBox denominationVBox = new VBox(); - Label denominationLabel = new Label(poolData.getDenomination().toString()); - denominationLabel.getStyleClass().add("joinstr-list-item"); - - Label denominationMinLabel = new Label("Min: _____ BTC"); - denominationMinLabel.getStyleClass().add("joinstr-list-item-subtitle"); - - denominationVBox.getChildren().addAll(denominationLabel, denominationMinLabel); - GridPane.setRowIndex(denominationVBox, 0); - GridPane.setColumnIndex(denominationVBox, 2); - - VBox peersVBox = new VBox(); - Label peersLabel = new Label("__/__"); - peersLabel.getStyleClass().add("joinstr-list-item"); - - Label peersMinLabel = new Label("Min: -"); - peersMinLabel.getStyleClass().add("joinstr-list-item-subtitle"); - - peersVBox.getChildren().addAll(peersLabel, peersMinLabel); - GridPane.setRowIndex(peersVBox, 0); - GridPane.setColumnIndex(peersVBox, 3); - - VBox timeoutVBox = new VBox(); - Label timeoutLabel = new Label("0"); - timeoutLabel.getStyleClass().add("joinstr-list-item"); - - Label timeoutTypeLabel = new Label("mins"); - timeoutTypeLabel.getStyleClass().add("joinstr-list-item-subtitle"); - - timeoutVBox.getChildren().addAll(timeoutLabel, timeoutTypeLabel); - GridPane.setRowIndex(timeoutVBox, 0); - GridPane.setColumnIndex(timeoutVBox, 4); - - Button actionButton = new Button(); - actionButton.getStyleClass().add("joinstr-list-action-button"); - switch(action) { - case JOIN -> { - actionButton.setText("Join"); - actionButton.setOnAction(event -> { - System.out.println("Join " + poolData.getRelay() + "!"); - }); - } - case REMOVE -> { - // For MY_POOLS & HISTORY - actionButton.setText("Remove"); - actionButton.setOnAction(event -> { - System.out.println("Remove " + poolData.getRelay() + "!"); - }); - } - } - GridPane.setRowIndex(actionButton, 0); - GridPane.setColumnIndex(actionButton, 5); - - getChildren().addAll( relayVBox, pubkeyVBox, denominationVBox, peersVBox, timeoutVBox, actionButton); - getStyleClass().add("joinstr-list-row"); - - } - - private void setColumnConstraints() { - - ColumnConstraints column1 = new ColumnConstraints(); - column1.setPercentWidth(25); - ColumnConstraints column2 = new ColumnConstraints(); - column2.setPercentWidth(25); - ColumnConstraints column3 = new ColumnConstraints(); - column3.setPercentWidth(16); - ColumnConstraints column4 = new ColumnConstraints(); - column4.setPercentWidth(10); - ColumnConstraints column5 = new ColumnConstraints(); - column5.setPercentWidth(10); - ColumnConstraints column6 = new ColumnConstraints(); - column6.setPercentWidth(14); - - getColumnConstraints().addAll(column1, column2, column3, column4, column5, column6); - - } - - public void handleActionButton(ActionEvent e) { - if(e.getSource()!=null) { - System.out.println("Action!"); - }; - } - -} diff --git a/src/main/resources/com/sparrowwallet/sparrow/joinstr/history.fxml b/src/main/resources/com/sparrowwallet/sparrow/joinstr/history.fxml index dab41352..1c3a7dba 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/joinstr/history.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/joinstr/history.fxml @@ -9,7 +9,7 @@
- + diff --git a/src/main/resources/com/sparrowwallet/sparrow/joinstr/joinstr.fxml b/src/main/resources/com/sparrowwallet/sparrow/joinstr/joinstr.fxml index 3ad26024..1b392d6a 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/joinstr/joinstr.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/joinstr/joinstr.fxml @@ -36,6 +36,11 @@ + + + + +
diff --git a/src/main/resources/com/sparrowwallet/sparrow/joinstr/new_pool.fxml b/src/main/resources/com/sparrowwallet/sparrow/joinstr/new_pool.fxml index abd08ad8..52216428 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/joinstr/new_pool.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/joinstr/new_pool.fxml @@ -9,7 +9,7 @@
- + diff --git a/src/main/resources/com/sparrowwallet/sparrow/joinstr/settings.fxml b/src/main/resources/com/sparrowwallet/sparrow/joinstr/settings.fxml new file mode 100644 index 00000000..47b4d0e1 --- /dev/null +++ b/src/main/resources/com/sparrowwallet/sparrow/joinstr/settings.fxml @@ -0,0 +1,61 @@ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + +
+
\ No newline at end of file