Craig Raw
3 years ago
14 changed files with 454 additions and 36 deletions
@ -1 +1 @@ |
|||||
Subproject commit 67836b2b557839317316a3e1c8d18b98a51d0e29 |
Subproject commit b4f4cc8726de3e7b5f875816affe1e0f78f2fa25 |
@ -0,0 +1,85 @@ |
|||||
|
package com.sparrowwallet.sparrow.wallet; |
||||
|
|
||||
|
import com.sparrowwallet.drongo.policy.PolicyType; |
||||
|
import com.sparrowwallet.drongo.wallet.MixConfig; |
||||
|
import com.sparrowwallet.drongo.wallet.StandardAccount; |
||||
|
import com.sparrowwallet.drongo.wallet.Wallet; |
||||
|
import com.sparrowwallet.sparrow.AppServices; |
||||
|
import com.sparrowwallet.sparrow.EventManager; |
||||
|
import com.sparrowwallet.sparrow.event.WalletMixConfigChangedEvent; |
||||
|
import com.sparrowwallet.sparrow.whirlpool.Whirlpool; |
||||
|
import javafx.collections.FXCollections; |
||||
|
import javafx.fxml.FXML; |
||||
|
import javafx.fxml.Initializable; |
||||
|
import javafx.scene.control.ComboBox; |
||||
|
import javafx.scene.control.Spinner; |
||||
|
import javafx.scene.control.SpinnerValueFactory; |
||||
|
|
||||
|
import java.net.URL; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
import java.util.NoSuchElementException; |
||||
|
import java.util.ResourceBundle; |
||||
|
import java.util.stream.Collectors; |
||||
|
|
||||
|
public class MixToController implements Initializable { |
||||
|
private static final Wallet NONE_WALLET = new Wallet("None"); |
||||
|
|
||||
|
@FXML |
||||
|
private ComboBox<Wallet> mixToWallets; |
||||
|
|
||||
|
@FXML |
||||
|
private Spinner<Integer> minMixes; |
||||
|
|
||||
|
@Override |
||||
|
public void initialize(URL location, ResourceBundle resources) { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public void initializeView(Wallet wallet) { |
||||
|
MixConfig mixConfig = wallet.getMasterMixConfig(); |
||||
|
|
||||
|
List<Wallet> allWallets = new ArrayList<>(); |
||||
|
allWallets.add(NONE_WALLET); |
||||
|
|
||||
|
List<Wallet> destinationWallets = AppServices.get().getOpenWallets().keySet().stream().filter(openWallet -> openWallet.isValid() |
||||
|
&& openWallet != wallet && openWallet != wallet.getMasterWallet() |
||||
|
&& openWallet.getPolicyType().equals(PolicyType.SINGLE) |
||||
|
&& !StandardAccount.WHIRLPOOL_ACCOUNTS.contains(openWallet.getStandardAccountType())).collect(Collectors.toList()); |
||||
|
allWallets.addAll(destinationWallets); |
||||
|
|
||||
|
mixToWallets.setItems(FXCollections.observableList(allWallets)); |
||||
|
|
||||
|
String mixToWalletId = null; |
||||
|
try { |
||||
|
mixToWalletId = AppServices.get().getWhirlpoolMixToWalletId(mixConfig); |
||||
|
} catch(NoSuchElementException e) { |
||||
|
//ignore, mix to wallet is not open
|
||||
|
} |
||||
|
|
||||
|
if(mixToWalletId != null) { |
||||
|
mixToWallets.setValue(AppServices.get().getWallet(mixToWalletId)); |
||||
|
} else { |
||||
|
mixToWallets.setValue(NONE_WALLET); |
||||
|
} |
||||
|
|
||||
|
mixToWallets.valueProperty().addListener((observable, oldValue, newValue) -> { |
||||
|
if(newValue == NONE_WALLET) { |
||||
|
mixConfig.setMixToWalletName(null); |
||||
|
mixConfig.setMixToWalletFile(null); |
||||
|
} else { |
||||
|
mixConfig.setMixToWalletName(newValue.getName()); |
||||
|
mixConfig.setMixToWalletFile(AppServices.get().getOpenWallets().get(newValue).getWalletFile()); |
||||
|
} |
||||
|
|
||||
|
EventManager.get().post(new WalletMixConfigChangedEvent(wallet)); |
||||
|
}); |
||||
|
|
||||
|
int initialMinMixes = mixConfig.getMinMixes() == null ? Whirlpool.DEFAULT_MIXTO_MIN_MIXES : mixConfig.getMinMixes(); |
||||
|
minMixes.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 10000, initialMinMixes)); |
||||
|
minMixes.valueProperty().addListener((observable, oldValue, newValue) -> { |
||||
|
mixConfig.setMinMixes(newValue); |
||||
|
EventManager.get().post(new WalletMixConfigChangedEvent(wallet)); |
||||
|
}); |
||||
|
} |
||||
|
} |
@ -0,0 +1,68 @@ |
|||||
|
package com.sparrowwallet.sparrow.wallet; |
||||
|
|
||||
|
import com.google.common.eventbus.Subscribe; |
||||
|
import com.sparrowwallet.drongo.wallet.Wallet; |
||||
|
import com.sparrowwallet.sparrow.AppServices; |
||||
|
import com.sparrowwallet.sparrow.EventManager; |
||||
|
import com.sparrowwallet.sparrow.event.WalletMixConfigChangedEvent; |
||||
|
import com.sparrowwallet.sparrow.whirlpool.Whirlpool; |
||||
|
import javafx.fxml.FXMLLoader; |
||||
|
import javafx.scene.control.*; |
||||
|
import org.controlsfx.tools.Borders; |
||||
|
|
||||
|
import java.io.IOException; |
||||
|
import java.util.NoSuchElementException; |
||||
|
|
||||
|
public class MixToDialog extends Dialog<Boolean> { |
||||
|
private final Wallet wallet; |
||||
|
private final Button applyButton; |
||||
|
|
||||
|
public MixToDialog(Wallet wallet) { |
||||
|
final DialogPane dialogPane = getDialogPane(); |
||||
|
AppServices.setStageIcon(dialogPane.getScene().getWindow()); |
||||
|
this.wallet = wallet; |
||||
|
|
||||
|
try { |
||||
|
FXMLLoader mixToLoader = new FXMLLoader(AppServices.class.getResource("wallet/mixto.fxml")); |
||||
|
dialogPane.setContent(Borders.wrap(mixToLoader.load()).emptyBorder().buildAll()); |
||||
|
MixToController mixToController = mixToLoader.getController(); |
||||
|
mixToController.initializeView(wallet); |
||||
|
|
||||
|
Whirlpool whirlpool = AppServices.get().getWhirlpool(wallet); |
||||
|
final ButtonType closeButtonType = new javafx.scene.control.ButtonType("Close", ButtonBar.ButtonData.CANCEL_CLOSE); |
||||
|
final ButtonType applyButtonType = new javafx.scene.control.ButtonType(whirlpool.isStarted() ? "Restart Whirlpool" : "Apply", ButtonBar.ButtonData.APPLY); |
||||
|
dialogPane.getButtonTypes().addAll(closeButtonType, applyButtonType); |
||||
|
|
||||
|
applyButton = (Button)dialogPane.lookupButton(applyButtonType); |
||||
|
applyButton.setDisable(true); |
||||
|
applyButton.setDefaultButton(true); |
||||
|
|
||||
|
try { |
||||
|
AppServices.get().getWhirlpoolMixToWalletId(wallet.getMasterMixConfig()); |
||||
|
} catch(NoSuchElementException e) { |
||||
|
applyButton.setDisable(false); |
||||
|
} |
||||
|
|
||||
|
dialogPane.setPrefWidth(400); |
||||
|
dialogPane.setPrefHeight(300); |
||||
|
AppServices.moveToActiveWindowScreen(this); |
||||
|
|
||||
|
setResultConverter(dialogButton -> dialogButton == applyButtonType); |
||||
|
|
||||
|
setOnCloseRequest(event -> { |
||||
|
EventManager.get().unregister(this); |
||||
|
}); |
||||
|
EventManager.get().register(this); |
||||
|
} |
||||
|
catch(IOException e) { |
||||
|
throw new RuntimeException(e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Subscribe |
||||
|
public void walletMixConfigChanged(WalletMixConfigChangedEvent event) { |
||||
|
if(event.getWallet() == (wallet.isMasterWallet() ? wallet : wallet.getMasterWallet())) { |
||||
|
applyButton.setDisable(false); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -0,0 +1,42 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
|
||||
|
<?import java.lang.*?> |
||||
|
<?import java.util.*?> |
||||
|
<?import javafx.scene.*?> |
||||
|
<?import javafx.scene.control.*?> |
||||
|
<?import javafx.scene.layout.*?> |
||||
|
<?import tornadofx.control.Form?> |
||||
|
<?import tornadofx.control.Fieldset?> |
||||
|
<?import tornadofx.control.Field?> |
||||
|
<?import com.sparrowwallet.sparrow.control.HelpLabel?> |
||||
|
<?import javafx.geometry.Insets?> |
||||
|
|
||||
|
<BorderPane stylesheets="@../general.css" styleClass="line-border" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml" fx:controller="com.sparrowwallet.sparrow.wallet.MixToController"> |
||||
|
<center> |
||||
|
<GridPane hgap="10.0" vgap="10.0"> |
||||
|
<padding> |
||||
|
<Insets left="25.0" right="25.0" top="25.0" /> |
||||
|
</padding> |
||||
|
<columnConstraints> |
||||
|
<ColumnConstraints percentWidth="100" /> |
||||
|
</columnConstraints> |
||||
|
<rowConstraints> |
||||
|
<RowConstraints /> |
||||
|
</rowConstraints> |
||||
|
|
||||
|
<Form GridPane.columnIndex="0" GridPane.rowIndex="0"> |
||||
|
<Fieldset inputGrow="SOMETIMES" text="Mix To Settings"> |
||||
|
<Field text="Mix to wallet:"> |
||||
|
<ComboBox fx:id="mixToWallets" prefWidth="140" promptText="None available" /> |
||||
|
<HelpLabel helpText="Select a single signature wallet that is already open to mix to."/> |
||||
|
</Field> |
||||
|
<Field text="Minimum mixes:"> |
||||
|
<Spinner fx:id="minMixes" editable="true" prefWidth="90" /> |
||||
|
<HelpLabel helpText="The minimum number of mixes required before mixing to the selected wallet.\nTo ensure privacy, each mix beyond this number will have a 25% probability to mix to the selected wallet."/> |
||||
|
</Field> |
||||
|
</Fieldset> |
||||
|
</Form> |
||||
|
</GridPane> |
||||
|
</center> |
||||
|
</BorderPane> |
||||
|
|
Loading…
Reference in new issue