Added my pools list + code refactoring

This commit is contained in:
QcMrHyde 2025-06-10 14:29:38 -04:00
parent 4498bad7e3
commit 1ec05a6861
11 changed files with 158 additions and 88 deletions

View file

@ -7,6 +7,7 @@ import com.sparrowwallet.sparrow.Mode;
import com.sparrowwallet.sparrow.Theme; import com.sparrowwallet.sparrow.Theme;
import com.sparrowwallet.sparrow.control.QRDensity; import com.sparrowwallet.sparrow.control.QRDensity;
import com.sparrowwallet.sparrow.control.WebcamResolution; import com.sparrowwallet.sparrow.control.WebcamResolution;
import com.sparrowwallet.sparrow.joinstr.JoinstrPool;
import com.sparrowwallet.sparrow.net.*; import com.sparrowwallet.sparrow.net.*;
import com.sparrowwallet.sparrow.wallet.FeeRatesSelection; import com.sparrowwallet.sparrow.wallet.FeeRatesSelection;
import com.sparrowwallet.sparrow.wallet.OptimizationStrategy; import com.sparrowwallet.sparrow.wallet.OptimizationStrategy;
@ -90,6 +91,7 @@ public class Config {
private String nostrRelay; private String nostrRelay;
private ArrayList<JoinstrPool> poolStore;
// ================ // ================
@ -724,6 +726,16 @@ public class Config {
flush(); flush();
} }
public ArrayList<JoinstrPool> getPoolStore() {
if(poolStore == null)
poolStore = new ArrayList<JoinstrPool>();
return poolStore;
}
public void setPoolStore(ArrayList<JoinstrPool> pools) {
this.poolStore = pools;
flush();
}
public String getNostrRelay() { public String getNostrRelay() {
return nostrRelay; return nostrRelay;

View file

@ -0,0 +1,34 @@
package com.sparrowwallet.sparrow.joinstr;
import com.google.gson.Gson;
public class JoinstrEvent {
public String type;
public String id;
public String public_key;
public String denomination;
public String peers;
public String timeout;
public String relay;
public String fee_rate;
public String transport;
public JoinstrEvent(String eventContent) {
Gson gson = new Gson();
JoinstrEvent joinstrEvent = gson.fromJson(eventContent, JoinstrEvent.class);
this.type = joinstrEvent.type;
this.id = joinstrEvent.id;
this.public_key = joinstrEvent.public_key;
this.denomination = joinstrEvent.denomination;
this.peers = joinstrEvent.peers;
this.timeout = joinstrEvent.timeout;
this.relay = joinstrEvent.relay;
this.fee_rate = joinstrEvent.fee_rate;
this.transport = joinstrEvent.transport;
}
}

View file

@ -23,50 +23,29 @@ import com.sparrowwallet.sparrow.net.Tor;
import java.util.*; import java.util.*;
import javafx.beans.property.SimpleStringProperty;
public class JoinstrPool { public class JoinstrPool {
private final Integer port; // Nostr Port ? private final SimpleStringProperty relay;
private final String pubkey; private final SimpleStringProperty pubkey;
private final long denomination; // Should be in sats, like transaction amounts private final SimpleStringProperty denomination;
private final SimpleStringProperty peers;
public JoinstrPool(Integer port, String pubkey, long denomination) { private final SimpleStringProperty timeout;
this.port = port;
this.pubkey = pubkey;
this.denomination = denomination;
public JoinstrPool(String relay, String pubkey, String denomination,
String peers, String timeout) {
this.relay = new SimpleStringProperty(relay);
this.pubkey = new SimpleStringProperty(pubkey);
this.denomination = new SimpleStringProperty(denomination);
this.peers = new SimpleStringProperty(peers);
this.timeout = new SimpleStringProperty(timeout);
} }
private String getNostrRelay() { public String getRelay() { return relay.get(); }
return Config.get().getNostrRelay(); public String getPubkey() { return pubkey.get(); }
} public String getDenomination() { return denomination.get(); }
public String getPeers() { return peers.get(); }
public Integer getPort() { public String getTimeout() { return timeout.get(); }
return port;
}
public String getPubkey() {
return pubkey;
}
public long getDenomination() {
return denomination;
}
public void getNewTorRoute() {
Tor tor = Tor.getDefault();
tor.changeIdentity();
}
public void publicNostrEvent() {
// TODO: Publish a nostr event with pool info
}
public void waitForPeers() {
// TODO: Wait for others to join
}
} }

View file

@ -1,17 +1,78 @@
package com.sparrowwallet.sparrow.joinstr; package com.sparrowwallet.sparrow.joinstr;
import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.joinstr.control.JoinstrInfoPane;
import com.sparrowwallet.sparrow.joinstr.control.JoinstrPoolList;
import java.util.ArrayList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
public class MyPoolsController extends JoinstrFormController { public class MyPoolsController extends JoinstrFormController {
@FXML
private VBox contentVBox;
@FXML @FXML
private TextField searchTextField; private TextField searchTextField;
private JoinstrPoolList joinstrPoolList;
private JoinstrInfoPane joinstrInfoPane;
@Override @Override
public void initializeView() { public void initializeView() {
try {
joinstrPoolList = new JoinstrPoolList();
joinstrPoolList.configureWithJoinButtons();
// Add pool store data
addPoolStoreData();
joinstrInfoPane = new JoinstrInfoPane();
joinstrInfoPane.initInfoPane();
joinstrInfoPane.setVisible(false);
joinstrInfoPane.setManaged(false);
joinstrPoolList.setOnPoolSelectedListener(pool -> {
if (pool != null) {
joinstrInfoPane.setVisible(true);
joinstrInfoPane.setManaged(true);
joinstrInfoPane.updatePoolInfo(pool);
} else {
joinstrInfoPane.setVisible(false);
joinstrInfoPane.setManaged(false);
}
});
contentVBox.getChildren().addAll(joinstrPoolList, joinstrInfoPane);
searchTextField.textProperty().addListener((observable, oldValue, newValue) -> {
filterPools(newValue);
});
} catch (Exception e) {
if(e != null) {
e.printStackTrace();
}
}
}
private void addPoolStoreData() {
ArrayList<JoinstrPool> pools = Config.get().getPoolStore();
for (JoinstrPool pool: pools) {
joinstrPoolList.addPool(pool);
}
}
private void filterPools(String searchText) {
joinstrPoolList.filterPools(searchText);
} }
public void handleSearchButton(ActionEvent e) { public void handleSearchButton(ActionEvent e) {

View file

@ -1,5 +1,11 @@
package com.sparrowwallet.sparrow.joinstr; package com.sparrowwallet.sparrow.joinstr;
import com.google.gson.Gson;
import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.payjoin.Payjoin;
import java.util.ArrayList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
@ -57,9 +63,20 @@ public class NewPoolController extends JoinstrFormController {
Alert alert = new Alert(AlertType.INFORMATION); Alert alert = new Alert(AlertType.INFORMATION);
alert.setHeaderText(null); alert.setHeaderText(null);
assert event != null; assert event != null;
// Custom class for ease of use
JoinstrEvent joinstrEvent = new JoinstrEvent(event.getContent());
// Add pool to pool store in Config
ArrayList<JoinstrPool> pools = Config.get().getPoolStore();
JoinstrPool pool = new JoinstrPool(joinstrEvent.relay, joinstrEvent.public_key,joinstrEvent.denomination, joinstrEvent.peers, joinstrEvent.timeout);
pools.add(pool);
Config.get().setPoolStore(pools);
alert.setContentText("Pool created successfully!\nEvent ID: " + event.getId() + alert.setContentText("Pool created successfully!\nEvent ID: " + event.getId() +
"\nDenomination: " + denomination + "\nPeers: " + peers); "\nDenomination: " + denomination + "\nPeers: " + peers);
alert.showAndWait(); alert.showAndWait();
} catch (Exception e) { } catch (Exception e) {
showError("Error: " + e.getMessage()); showError("Error: " + e.getMessage());
} }

View file

@ -6,8 +6,10 @@ import com.sparrowwallet.sparrow.joinstr.control.JoinstrPoolList;
import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.SimpleStringProperty;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import nostr.event.impl.GenericEvent;
public class OtherPoolsController extends JoinstrFormController { public class OtherPoolsController extends JoinstrFormController {
@ -60,6 +62,7 @@ public class OtherPoolsController extends JoinstrFormController {
} }
private void addSamplePoolData() { private void addSamplePoolData() {
// Create the two sample pools // Create the two sample pools
JoinstrPool pool1 = new JoinstrPool( JoinstrPool pool1 = new JoinstrPool(
"relay.joinstr.xyz", "relay.joinstr.xyz",
@ -91,26 +94,12 @@ public class OtherPoolsController extends JoinstrFormController {
} }
} }
public static class JoinstrPool { private void showError(String message) {
private final SimpleStringProperty relay; Alert alert = new Alert(Alert.AlertType.ERROR);
private final SimpleStringProperty pubkey; alert.setTitle("Error");
private final SimpleStringProperty denomination; alert.setHeaderText(null);
private final SimpleStringProperty peers; alert.setContentText(message);
private final SimpleStringProperty timeout; alert.showAndWait();
public JoinstrPool(String relay, String pubkey, String denomination,
String peers, String timeout) {
this.relay = new SimpleStringProperty(relay);
this.pubkey = new SimpleStringProperty(pubkey);
this.denomination = new SimpleStringProperty(denomination);
this.peers = new SimpleStringProperty(peers);
this.timeout = new SimpleStringProperty(timeout);
}
public String getRelay() { return relay.get(); }
public String getPubkey() { return pubkey.get(); }
public String getDenomination() { return denomination.get(); }
public String getPeers() { return peers.get(); }
public String getTimeout() { return timeout.get(); }
} }
} }

View file

@ -36,7 +36,7 @@ public class SettingsController extends JoinstrFormController {
} }
public void setDefaultNostrRelayIfEmpty() { public void setDefaultNostrRelayIfEmpty() {
if(nostrRelayTextField.getText().isEmpty()) { if(nostrRelayTextField.getText() == null || nostrRelayTextField.getText().isEmpty()) {
nostrRelayTextField.setText("wss://nostr.fmt.wiz.biz"); nostrRelayTextField.setText("wss://nostr.fmt.wiz.biz");
} }
} }

View file

@ -1,6 +1,6 @@
package com.sparrowwallet.sparrow.joinstr.control; package com.sparrowwallet.sparrow.joinstr.control;
import com.sparrowwallet.sparrow.joinstr.OtherPoolsController.JoinstrPool; import com.sparrowwallet.sparrow.joinstr.JoinstrPool;
import javafx.geometry.Insets; import javafx.geometry.Insets;
import javafx.scene.control.Label; import javafx.scene.control.Label;

View file

@ -1,6 +1,6 @@
package com.sparrowwallet.sparrow.joinstr.control; package com.sparrowwallet.sparrow.joinstr.control;
import com.sparrowwallet.sparrow.joinstr.OtherPoolsController.JoinstrPool; import com.sparrowwallet.sparrow.joinstr.JoinstrPool;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;

View file

@ -13,7 +13,7 @@
<left> <left>
<VBox fx:id="joinstrMenuBox" styleClass="list-menu"> <VBox fx:id="joinstrMenuBox" styleClass="list-menu">
<Pane styleClass="spacerV50" /> <Pane styleClass="spacerV50" />
<ToggleButton VBox.vgrow="ALWAYS" text="New pool" contentDisplay="CENTER" styleClass="list-item" maxHeight="Infinity"> <ToggleButton VBox.vgrow="ALWAYS" text="New pool" contentDisplay="CENTER" styleClass="list-item" maxHeight="Infinity" toggleGroup="$joinstrMenu">
<toggleGroup> <toggleGroup>
<ToggleGroup fx:id="joinstrMenu" /> <ToggleGroup fx:id="joinstrMenu" />
</toggleGroup> </toggleGroup>

View file

@ -19,37 +19,15 @@
</padding> </padding>
<center> <center>
<VBox maxWidth="Infinity" fx:id="contentVBox" spacing="20"> <VBox maxWidth="Infinity" fx:id="contentVBox" spacing="20">
<Label styleClass="sub-title">Create a new pool</Label> <Label styleClass="title">Create a new pool</Label>
<Form maxWidth="Infinity" style="-fx-max-width: 600px;"> <Form maxWidth="Infinity" style="-fx-max-width: 600px;">
<Fieldset inputGrow="ALWAYS"> <Fieldset inputGrow="ALWAYS">
<Field text="Pay to:">
<Label fx:id="addressLabel" />
</Field>
<Field text="Label:">
<TextField fx:id="labelField" promptText="Required" style="-fx-max-width: 250px;">
<tooltip>
<Tooltip text="Required to label the transaction (privately in this wallet)"/>
</tooltip>
</TextField>
</Field>
<Field text="UTXO:">
<ComboBox fx:id="utxosComboBox" styleClass="amount-unit" style="-fx-max-width: 150px;" onAction="#setUtxoAmount" />
<TextField fx:id="amountField" disable="true" style="-fx-max-width: 100px;-fx-text-fill: white;" />
</Field>
<Field text="Denomination:" style="-fx-text-fill: #aaaaaa;"> <Field text="Denomination:" style="-fx-text-fill: #aaaaaa;">
<TextField fx:id="denominationField" promptText="Required" style="-fx-max-width: 100px;-fx-background-color: #444444; -fx-text-fill: white; -fx-prompt-text-fill: #888888;"> <TextField fx:id="denominationField" promptText="Required" style="-fx-max-width: 100px;-fx-background-color: #444444; -fx-text-fill: white; -fx-prompt-text-fill: #888888;">
<tooltip> <tooltip>
<Tooltip text="Required to create coinjoin pool"/> <Tooltip text="Required to create coinjoin pool"/>
</tooltip> </tooltip>
</TextField> </TextField>
<ComboBox fx:id="denominationUnit" styleClass="amount-unit" style="-fx-min-width: 60px;" onAction="#handleDenominationUnitChange">
<items>
<FXCollections fx:factory="observableArrayList">
<BitcoinUnit fx:constant="BTC" />
<BitcoinUnit fx:constant="SATOSHIS" />
</FXCollections>
</items>
</ComboBox>
</Field> </Field>
<Field text="Number of Peers:" style="-fx-text-fill: #aaaaaa;"> <Field text="Number of Peers:" style="-fx-text-fill: #aaaaaa;">
<TextField fx:id="peersField" promptText="Req." style="-fx-max-width: 50px;-fx-background-color: #444444; -fx-text-fill: white; -fx-prompt-text-fill: #888888;" /> <TextField fx:id="peersField" promptText="Req." style="-fx-max-width: 50px;-fx-background-color: #444444; -fx-text-fill: white; -fx-prompt-text-fill: #888888;" />