diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index 76c334d4..7e46a744 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -331,7 +331,7 @@ public class AppController implements Initializable { sendToMany.disableProperty().bind(exportWallet.disableProperty()); findMixingPartner.setDisable(true); AppServices.onlineProperty().addListener((observable, oldValue, newValue) -> { - findMixingPartner.setDisable(exportWallet.isDisable() || !SorobanServices.canWalletMix(getSelectedWalletForm().getWallet()) || !newValue); + findMixingPartner.setDisable(exportWallet.isDisable() || getSelectedWalletForm() == null || !SorobanServices.canWalletMix(getSelectedWalletForm().getWallet()) || !newValue); }); setServerType(Config.get().getServerType()); @@ -1495,12 +1495,14 @@ public class AppController implements Initializable { public WalletForm getSelectedWalletForm() { Tab selectedTab = tabs.getSelectionModel().getSelectedItem(); - TabData tabData = (TabData)selectedTab.getUserData(); - if(tabData instanceof WalletTabData) { - TabPane subTabs = (TabPane)selectedTab.getContent(); - Tab selectedSubTab = subTabs.getSelectionModel().getSelectedItem(); - WalletTabData subWalletTabData = (WalletTabData)selectedSubTab.getUserData(); - return subWalletTabData.getWalletForm(); + if(selectedTab != null) { + TabData tabData = (TabData)selectedTab.getUserData(); + if(tabData instanceof WalletTabData) { + TabPane subTabs = (TabPane)selectedTab.getContent(); + Tab selectedSubTab = subTabs.getSelectionModel().getSelectedItem(); + WalletTabData subWalletTabData = (WalletTabData)selectedSubTab.getUserData(); + return subWalletTabData.getWalletForm(); + } } return null; diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java index e189a660..bcf3fb77 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java @@ -507,7 +507,7 @@ public class TransactionDiagram extends GridPane { recipientTooltip.setShowDelay(new Duration(TOOLTIP_SHOW_DELAY)); recipientTooltip.setShowDuration(Duration.INDEFINITE); recipientLabel.setTooltip(recipientTooltip); - outputNodes.add(new OutputNode(recipientLabel, payment.getAddress())); + outputNodes.add(new OutputNode(recipientLabel, payment.getAddress(), payment.getAmount())); } for(Map.Entry changeEntry : walletTx.getChangeMap().entrySet()) { @@ -543,7 +543,7 @@ public class TransactionDiagram extends GridPane { actionBox.getChildren().add(replaceChangeLabel); } - outputNodes.add(new OutputNode(actionBox, changeAddress)); + outputNodes.add(new OutputNode(actionBox, changeAddress, changeEntry.getValue())); } if(isFinal()) { @@ -634,7 +634,7 @@ public class TransactionDiagram extends GridPane { if(payment.getType() == Payment.Type.WHIRLPOOL_FEE) { return "Whirlpool Fee"; } else if(walletTx.isPremixSend(payment)) { - int premixIndex = getOutputIndex(payment.getAddress()) - 2; + int premixIndex = getOutputIndex(payment.getAddress(), payment.getAmount()) - 2; return "Premix #" + premixIndex; } else if(walletTx.isBadbankSend(payment)) { return "Badbank Change"; @@ -643,8 +643,8 @@ public class TransactionDiagram extends GridPane { return null; } - private int getOutputIndex(Address address) { - return walletTx.getTransaction().getOutputs().stream().filter(txOutput -> address.equals(txOutput.getScript().getToAddress())).mapToInt(TransactionOutput::getIndex).findFirst().orElseThrow(); + private int getOutputIndex(Address address, long amount) { + return walletTx.getTransaction().getOutputs().stream().filter(txOutput -> address.equals(txOutput.getScript().getToAddress()) && txOutput.getValue() == amount).mapToInt(TransactionOutput::getIndex).findFirst().orElseThrow(); } private Wallet getToWallet(Payment payment) { @@ -949,16 +949,18 @@ public class TransactionDiagram extends GridPane { private class OutputNode implements Comparable { public Node outputLabel; public Address address; + public long amount; - public OutputNode(Node outputLabel, Address address) { + public OutputNode(Node outputLabel, Address address, long amount) { this.outputLabel = outputLabel; this.address = address; + this.amount = amount; } @Override public int compareTo(TransactionDiagram.OutputNode o) { try { - return getOutputIndex(address) - getOutputIndex(o.address); + return getOutputIndex(address, amount) - getOutputIndex(o.address, o.amount); } catch(Exception e) { return 0; } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index cb899b82..eb2dbaf1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -1288,7 +1288,7 @@ public class SendController extends WalletFormController implements Initializabl whirlpoolProperty.set(event.getPool()); updateTransaction(event.getPayments() == null || event.getPayments().stream().anyMatch(Payment::isSendMax)); - boolean isWhirlpoolPremix = (event.getPayments() != null && event.getPayments().stream().anyMatch(payment -> payment.getType().equals(Payment.Type.WHIRLPOOL_FEE))); + boolean isWhirlpoolPremix = (event.getPool() != null); setInputFieldsDisabled(isWhirlpoolPremix); premixButton.setVisible(isWhirlpoolPremix); premixButton.setDefaultButton(isWhirlpoolPremix); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java index bc2914c0..6b40ee07 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/UtxosController.java @@ -328,13 +328,15 @@ public class UtxosController extends WalletFormController implements Initializab Wallet badbankWallet = masterWallet.getChildWallet(StandardAccount.WHIRLPOOL_BADBANK); List payments = new ArrayList<>(); - try { - Address whirlpoolFeeAddress = Address.fromString(tx0Preview.getTx0Data().getFeeAddress()); - Payment whirlpoolFeePayment = new Payment(whirlpoolFeeAddress, "Whirlpool Fee", tx0Preview.getFeeValue(), false); - whirlpoolFeePayment.setType(Payment.Type.WHIRLPOOL_FEE); - payments.add(whirlpoolFeePayment); - } catch(InvalidAddressException e) { - throw new IllegalStateException("Cannot parse whirlpool fee address " + tx0Preview.getTx0Data().getFeeAddress(), e); + if(tx0Preview.getTx0Data().getFeeAddress() != null) { + try { + Address whirlpoolFeeAddress = Address.fromString(tx0Preview.getTx0Data().getFeeAddress()); + Payment whirlpoolFeePayment = new Payment(whirlpoolFeeAddress, "Whirlpool Fee", tx0Preview.getFeeValue(), false); + whirlpoolFeePayment.setType(Payment.Type.WHIRLPOOL_FEE); + payments.add(whirlpoolFeePayment); + } catch(InvalidAddressException e) { + throw new IllegalStateException("Cannot parse whirlpool fee address " + tx0Preview.getTx0Data().getFeeAddress(), e); + } } WalletNode badbankNode = badbankWallet.getFreshNode(KeyPurpose.RECEIVE);