From 67ed382f3d8618aea86c3881c5686723feb3adca Mon Sep 17 00:00:00 2001 From: main Date: Sun, 22 Sep 2024 16:28:31 -0700 Subject: [PATCH] Add input labels into TransactionDiagram along with transaction notes --- .../sparrow/control/TransactionDiagram.java | 16 +++++++++++++--- .../sparrow/transaction/HeadersController.java | 15 ++++++++++++++- .../sparrow/transaction/headers.fxml | 3 +++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java index 72c5b239..673dda81 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java @@ -429,11 +429,18 @@ public class TransactionDiagram extends GridPane { Tooltip tooltip = new Tooltip(); Long inputValue = null; + String inputLabel = input.getLabel(); if(walletNode != null) { inputValue = input.getValue(); Wallet nodeWallet = walletNode.getWallet(); - tooltip.setText("Spending " + getSatsValue(inputValue) + " sats from " + (isFinal() ? nodeWallet.getFullDisplayName() : (nodeWallet.isNested() ? nodeWallet.getDisplayName() : "")) + " " + walletNode + "\n" + - input.getHashAsString() + ":" + input.getIndex() + "\n" + walletNode.getAddress()); + StringJoiner joiner = new StringJoiner("\n"); + joiner.add("Spending " + getSatsValue(inputValue) + " sats from " + (isFinal() ? nodeWallet.getFullDisplayName() : (nodeWallet.isNested() ? nodeWallet.getDisplayName() : "")) + " " + walletNode); + joiner.add(input.getHashAsString() + ":" + input.getIndex()); + joiner.add(walletNode.getAddress().toString()); + if (inputLabel != null) { + joiner.add(inputLabel); + } + tooltip.setText(joiner.toString()); tooltip.getStyleClass().add("input-label"); if(input.getLabel() == null || input.getLabel().isEmpty()) { @@ -448,12 +455,15 @@ public class TransactionDiagram extends GridPane { ContextMenu contextMenu = new LabelContextMenu(walletNode.getAddress(), inputValue); label.setContextMenu(contextMenu); } else { - if(input instanceof PayjoinBlockTransactionHashIndex) { + if (input instanceof PayjoinBlockTransactionHashIndex) { tooltip.setText("Added once transaction is signed and sent to the payjoin server"); } else if(input instanceof AdditionalBlockTransactionHashIndex additionalReference) { inputValue = input.getValue(); StringJoiner joiner = new StringJoiner("\n"); joiner.add("Spending " + getSatsValue(inputValue) + " sats from" + (isExpanded() ? ":" : " (click to expand):")); + if (inputLabel != null) { + joiner.add(inputLabel); + } for(BlockTransactionHashIndex additionalInput : additionalReference.getAdditionalInputs()) { joiner.add(getInputDescription(additionalInput)); } diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index cb3bed45..ae20fdf2 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -89,6 +89,9 @@ public class HeadersController extends TransactionFormController implements Init @FXML private IdLabel id; + @FXML + private IdLabel txNotes; + @FXML private ToggleButton copyTxid; @@ -860,7 +863,17 @@ public class HeadersController extends TransactionFormController implements Init } private void updateTxId() { - id.setText(headersForm.getTransaction().calculateTxId(false).toString()); + Sha256Hash txid = headersForm.getTransaction().calculateTxId(false); + id.setText(txid.toString()); + txNotes.setText(headersForm.getName()); + + Wallet w = getWalletFromTransactionInputs(); + if (w != null) { + BlockTransaction txn = w.getWalletTransaction(txid); + if (txn != null) { + txNotes.setText(txn.getLabel()); + } + } if(!headersForm.isTransactionFinalized()) { addStyleClass(id, UNFINALIZED_TXID_CLASS); addStyleClass(size, UNFINALIZED_TXID_CLASS); diff --git a/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml b/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml index b6b92ac6..01bf0c89 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.fxml @@ -67,6 +67,9 @@ + + +