mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-21 04:38:51 -04:00
Add btc network selector to preferences
This commit is contained in:
parent
c1e0524090
commit
844a6dd66c
17 changed files with 248 additions and 82 deletions
|
@ -69,6 +69,8 @@ public class BitsquareApp extends Application {
|
|||
private List<String> corruptedDatabaseFiles = new ArrayList<>();
|
||||
private MainView mainView;
|
||||
|
||||
public static Runnable shutDownHandler;
|
||||
|
||||
public static void setEnvironment(Environment env) {
|
||||
BitsquareApp.env = env;
|
||||
}
|
||||
|
@ -77,6 +79,8 @@ public class BitsquareApp extends Application {
|
|||
public void start(Stage primaryStage) throws IOException {
|
||||
this.primaryStage = primaryStage;
|
||||
|
||||
shutDownHandler = this::stop;
|
||||
|
||||
// setup UncaughtExceptionHandler
|
||||
Thread.UncaughtExceptionHandler handler = (thread, throwable) -> {
|
||||
// Might come from another thread
|
||||
|
|
|
@ -20,7 +20,6 @@ package io.bitsquare.gui.main;
|
|||
import io.bitsquare.app.UpdateProcess;
|
||||
import io.bitsquare.app.Version;
|
||||
import io.bitsquare.arbitration.ArbitrationRepository;
|
||||
import io.bitsquare.btc.BitcoinNetwork;
|
||||
import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.crypto.KeyRing;
|
||||
import io.bitsquare.fiat.FiatAccount;
|
||||
|
@ -33,6 +32,7 @@ import io.bitsquare.p2p.tomp2p.BootstrappedPeerBuilder;
|
|||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
import io.bitsquare.trade.offer.OpenOfferManager;
|
||||
import io.bitsquare.user.Preferences;
|
||||
import io.bitsquare.user.User;
|
||||
import io.bitsquare.util.Utilities;
|
||||
|
||||
|
@ -117,7 +117,7 @@ class MainViewModel implements ViewModel {
|
|||
|
||||
@Inject
|
||||
public MainViewModel(User user, KeyRing keyRing, WalletService walletService, ArbitrationRepository arbitrationRepository, ClientNode clientNode,
|
||||
TradeManager tradeManager, OpenOfferManager openOfferManager, BitcoinNetwork bitcoinNetwork, UpdateProcess updateProcess,
|
||||
TradeManager tradeManager, OpenOfferManager openOfferManager, Preferences preferences, UpdateProcess updateProcess,
|
||||
BSFormatter formatter) {
|
||||
this.user = user;
|
||||
this.keyRing = keyRing;
|
||||
|
@ -129,8 +129,8 @@ class MainViewModel implements ViewModel {
|
|||
this.updateProcess = updateProcess;
|
||||
this.formatter = formatter;
|
||||
|
||||
bitcoinNetworkAsString = formatter.formatBitcoinNetwork(bitcoinNetwork);
|
||||
networkId = bitcoinNetwork.ordinal();
|
||||
bitcoinNetworkAsString = formatter.formatBitcoinNetwork(preferences.getBitcoinNetwork());
|
||||
networkId = preferences.getBitcoinNetwork().ordinal();
|
||||
|
||||
updateProcess.state.addListener((observableValue, oldValue, newValue) -> applyUpdateState(newValue));
|
||||
applyUpdateState(updateProcess.state.get());
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<Insets bottom="10.0" left="25.0" top="30.0" right="25"/>
|
||||
</padding>
|
||||
|
||||
<TitledGroupBg text="Network information" GridPane.rowSpan="8"/>
|
||||
<TitledGroupBg text="Bitcoin network" GridPane.rowSpan="3"/>
|
||||
|
||||
<Label text="Bitcoin network type:" GridPane.rowIndex="0">
|
||||
<GridPane.margin>
|
||||
|
@ -45,46 +45,54 @@
|
|||
</GridPane.margin>
|
||||
</TextField>
|
||||
|
||||
<Label text="Bitcoin network connected peers:" GridPane.rowIndex="1"/>
|
||||
<TextField fx:id="connectedPeersBTC" GridPane.rowIndex="1" GridPane.columnIndex="1"
|
||||
<Label text="Select Network:" GridPane.rowIndex="1"/>
|
||||
<ComboBox fx:id="netWorkComboBox" onAction="#onSelectNetwork" GridPane.rowIndex="1" GridPane.columnIndex="1"/>
|
||||
|
||||
<Label text="Bitcoin network connected peers:" GridPane.rowIndex="2"/>
|
||||
<TextField fx:id="connectedPeersBTC" GridPane.rowIndex="2" GridPane.columnIndex="1"
|
||||
mouseTransparent="true" focusTraversable="false"/>
|
||||
|
||||
|
||||
<Label text="P2P network connection:" GridPane.rowIndex="2"/>
|
||||
<TextField fx:id="connectionType" GridPane.rowIndex="2" GridPane.columnIndex="1"
|
||||
mouseTransparent="true" focusTraversable="false"/>
|
||||
|
||||
<Label text="P2P network connected peers:" GridPane.rowIndex="3"/>
|
||||
<TextField fx:id="connectedPeersP2P" GridPane.rowIndex="3" GridPane.columnIndex="1"
|
||||
mouseTransparent="true" focusTraversable="false"/>
|
||||
|
||||
<Label text="My external visible P2P network address:" GridPane.rowIndex="4"/>
|
||||
<TextField fx:id="nodeAddress" GridPane.rowIndex="4" GridPane.columnIndex="1"
|
||||
mouseTransparent="true" focusTraversable="false"/>
|
||||
|
||||
<Label text="P2P bootstrap node address:" GridPane.rowIndex="5">
|
||||
<TitledGroupBg text="P2P network" GridPane.rowIndex="3" GridPane.rowSpan="5">
|
||||
<padding>
|
||||
<Insets top="50.0"/>
|
||||
</padding>
|
||||
<GridPane.margin>
|
||||
<Insets bottom="-15"/>
|
||||
<Insets bottom="-10" left="-10" right="-10" top="30"/>
|
||||
</GridPane.margin>
|
||||
</TitledGroupBg>
|
||||
|
||||
<Label text="P2P network connection:" GridPane.rowIndex="3">
|
||||
<GridPane.margin>
|
||||
<Insets top="50.0"/>
|
||||
</GridPane.margin>
|
||||
</Label>
|
||||
<TextField fx:id="bootstrapNodeAddress" GridPane.rowIndex="5" GridPane.columnIndex="1"
|
||||
<TextField fx:id="connectionType" GridPane.rowIndex="3" GridPane.columnIndex="1"
|
||||
mouseTransparent="true" focusTraversable="false">
|
||||
<GridPane.margin>
|
||||
<Insets bottom="-15"/>
|
||||
<Insets top="50.0"/>
|
||||
</GridPane.margin>
|
||||
</TextField>
|
||||
|
||||
<Label text="Use UPnP:" GridPane.rowIndex="4"/>
|
||||
<CheckBox fx:id="useUPnP" onAction="#onSelectUPnP" GridPane.rowIndex="4" GridPane.columnIndex="1"/>
|
||||
|
||||
<Label text="P2P network connected peers:" GridPane.rowIndex="5"/>
|
||||
<TextField fx:id="connectedPeersP2P" GridPane.rowIndex="5" GridPane.columnIndex="1"
|
||||
mouseTransparent="true" focusTraversable="false"/>
|
||||
|
||||
<Label text="My external visible P2P network address:" GridPane.rowIndex="6"/>
|
||||
<TextField fx:id="nodeAddress" GridPane.rowIndex="6" GridPane.columnIndex="1"
|
||||
mouseTransparent="true" focusTraversable="false"/>
|
||||
|
||||
<Label text="P2P bootstrap node address:" GridPane.rowIndex="7"/>
|
||||
<TextField fx:id="bootstrapNodeAddress" GridPane.rowIndex="7" GridPane.columnIndex="1"
|
||||
mouseTransparent="true" focusTraversable="false"/>
|
||||
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" halignment="RIGHT" minWidth="200.0"/>
|
||||
<ColumnConstraints hgrow="ALWAYS" minWidth="300.0"/>
|
||||
</columnConstraints>
|
||||
|
||||
<rowConstraints>
|
||||
<RowConstraints vgrow="NEVER"/>
|
||||
<RowConstraints vgrow="NEVER"/>
|
||||
<RowConstraints vgrow="NEVER"/>
|
||||
</rowConstraints>
|
||||
|
||||
</GridPane>
|
||||
|
||||
|
||||
|
|
|
@ -17,18 +17,30 @@
|
|||
|
||||
package io.bitsquare.gui.main.settings.network;
|
||||
|
||||
import io.bitsquare.app.BitsquareApp;
|
||||
import io.bitsquare.btc.BitcoinNetwork;
|
||||
import io.bitsquare.btc.WalletService;
|
||||
import io.bitsquare.gui.common.view.FxmlView;
|
||||
import io.bitsquare.gui.common.view.InitializableView;
|
||||
import io.bitsquare.gui.components.Popups;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.p2p.ClientNode;
|
||||
import io.bitsquare.user.Preferences;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
|
||||
import org.controlsfx.control.action.AbstractAction;
|
||||
import org.controlsfx.control.action.Action;
|
||||
|
||||
import static javafx.beans.binding.Bindings.createStringBinding;
|
||||
|
||||
@FxmlView
|
||||
|
@ -36,14 +48,19 @@ public class NetworkSettingsView extends InitializableView {
|
|||
|
||||
private final String bitcoinNetworkString;
|
||||
private final WalletService walletService;
|
||||
private final Preferences preferences;
|
||||
private final ClientNode clientNode;
|
||||
|
||||
@FXML TextField bitcoinNetwork, connectionType, nodeAddress, bootstrapNodeAddress, connectedPeersBTC, connectedPeersP2P;
|
||||
@FXML CheckBox useUPnP;
|
||||
@FXML ComboBox<BitcoinNetwork> netWorkComboBox;
|
||||
|
||||
@Inject
|
||||
public NetworkSettingsView(BitcoinNetwork bitcoinNetwork, WalletService walletService, ClientNode clientNode, BSFormatter formatter) {
|
||||
public NetworkSettingsView(WalletService walletService, ClientNode clientNode, Preferences preferences, BSFormatter
|
||||
formatter) {
|
||||
this.walletService = walletService;
|
||||
this.bitcoinNetworkString = formatter.formatBitcoinNetwork(bitcoinNetwork);
|
||||
this.preferences = preferences;
|
||||
this.bitcoinNetworkString = formatter.formatBitcoinNetwork(preferences.getBitcoinNetwork());
|
||||
this.clientNode = clientNode;
|
||||
}
|
||||
|
||||
|
@ -56,6 +73,46 @@ public class NetworkSettingsView extends InitializableView {
|
|||
connectedPeersP2P.textProperty().bind(createStringBinding(() -> String.valueOf(clientNode.numPeersProperty().get()), clientNode.numPeersProperty()));
|
||||
nodeAddress.setText(clientNode.getAddress().toString());
|
||||
bootstrapNodeAddress.setText(clientNode.getBootstrapNodeAddress().toString());
|
||||
|
||||
useUPnP.setSelected(preferences.getUseUPnP());
|
||||
|
||||
netWorkComboBox.setItems(FXCollections.observableArrayList(BitcoinNetwork.values()));
|
||||
netWorkComboBox.getSelectionModel().select(preferences.getBitcoinNetwork());
|
||||
}
|
||||
|
||||
@FXML
|
||||
void onSelectUPnP() {
|
||||
preferences.setUseUPnP(useUPnP.isSelected());
|
||||
}
|
||||
|
||||
@FXML
|
||||
void onSelectNetwork() {
|
||||
preferences.setBitcoinNetwork(netWorkComboBox.getSelectionModel().getSelectedItem());
|
||||
|
||||
List<Action> actions = new ArrayList<>();
|
||||
actions.add(new AbstractAction(BSResources.get("shared.no")) {
|
||||
@Override
|
||||
public void handle(ActionEvent actionEvent) {
|
||||
getProperties().put("type", "NO");
|
||||
org.controlsfx.dialog.Dialog.Actions.NO.handle(actionEvent);
|
||||
}
|
||||
});
|
||||
|
||||
actions.add(new AbstractAction(BSResources.get("shared.yes")) {
|
||||
@Override
|
||||
public void handle(ActionEvent actionEvent) {
|
||||
getProperties().put("type", "YES");
|
||||
org.controlsfx.dialog.Dialog.Actions.YES.handle(actionEvent);
|
||||
}
|
||||
});
|
||||
|
||||
Action response = Popups.openConfirmPopup("Info", null,
|
||||
"You need to restart the application to apply the change of the Bitcoin network." +
|
||||
"\n\nDo you want to shutdown now?",
|
||||
actions);
|
||||
|
||||
if (Popups.isYes(response))
|
||||
BitsquareApp.shutDownHandler.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
package io.bitsquare.gui.util.validation;
|
||||
|
||||
import io.bitsquare.btc.BitcoinNetwork;
|
||||
import io.bitsquare.user.Preferences;
|
||||
|
||||
import org.bitcoinj.core.Address;
|
||||
import org.bitcoinj.core.AddressFormatException;
|
||||
|
@ -26,11 +26,11 @@ import javax.inject.Inject;
|
|||
|
||||
public final class BtcAddressValidator extends InputValidator {
|
||||
|
||||
private final BitcoinNetwork bitcoinNetwork;
|
||||
private Preferences preferences;
|
||||
|
||||
@Inject
|
||||
public BtcAddressValidator(BitcoinNetwork bitcoinNetwork) {
|
||||
this.bitcoinNetwork = bitcoinNetwork;
|
||||
public BtcAddressValidator(Preferences preferences) {
|
||||
this.preferences = preferences;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,7 +45,7 @@ public final class BtcAddressValidator extends InputValidator {
|
|||
|
||||
private ValidationResult validateBtcAddress(String input) {
|
||||
try {
|
||||
new Address(bitcoinNetwork.getParameters(), input);
|
||||
new Address(preferences.getBitcoinNetwork().getParameters(), input);
|
||||
return new ValidationResult(true);
|
||||
} catch (AddressFormatException e) {
|
||||
return new ValidationResult(false, "Bitcoin address is a valid format");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue