show address where available on input and output tooltips in transaction tab tree

This commit is contained in:
Craig Raw 2025-04-10 17:01:18 +02:00
parent c9d7b8ef9a
commit c73ebdc8a2
5 changed files with 44 additions and 6 deletions

View file

@ -1,5 +1,7 @@
package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.address.Address;
public abstract class IndexedTransactionForm extends TransactionForm {
private int index;
@ -15,4 +17,6 @@ public abstract class IndexedTransactionForm extends TransactionForm {
public void setIndex(int index) {
this.index = index;
}
public abstract Address getAddress();
}

View file

@ -1,5 +1,6 @@
package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.address.Address;
import com.sparrowwallet.drongo.protocol.TransactionInput;
import com.sparrowwallet.drongo.protocol.TransactionOutPoint;
import com.sparrowwallet.drongo.protocol.TransactionOutput;
@ -57,6 +58,20 @@ public class InputForm extends IndexedTransactionForm {
return getWallet() != null && getWallet().isWalletTxo(txInput);
}
@Override
public Address getAddress() {
TransactionInput txInput = getTransactionInput();
if(txInput != null && !txInput.isCoinBase() && getInputTransactions() != null) {
BlockTransaction blockTransaction = getInputTransactions().get(txInput.getOutpoint().getHash());
if(blockTransaction != null) {
TransactionOutput output = blockTransaction.getTransaction().getOutputs().get((int)txInput.getOutpoint().getIndex());
return output.getScript().getToAddress();
}
}
return null;
}
@Override
public Node getContents() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("input.fxml"));

View file

@ -45,6 +45,15 @@ public class OutputForm extends IndexedTransactionForm {
return getWallet() != null;
}
@Override
public Address getAddress() {
if(getTransactionOutput() != null) {
return getTransactionOutput().getScript().getToAddress();
}
return null;
}
@Override
public Node getContents() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("output.fxml"));
@ -61,7 +70,7 @@ public class OutputForm extends IndexedTransactionForm {
}
public String toString() {
Address address = getTransactionOutput().getScript().getToAddress();
Address address = getAddress();
return address != null ? address.toString() : "Output #" + getIndex();
}

View file

@ -1,5 +1,6 @@
package com.sparrowwallet.sparrow.transaction;
import com.sparrowwallet.drongo.address.Address;
import com.sparrowwallet.sparrow.net.ElectrumServer;
import javafx.scene.Node;
@ -29,6 +30,11 @@ public class PageForm extends IndexedTransactionForm {
return view;
}
@Override
public Address getAddress() {
return null;
}
public int getPageStart() {
return pageStart;
}

View file

@ -1,6 +1,7 @@
package com.sparrowwallet.sparrow.transaction;
import com.google.common.eventbus.Subscribe;
import com.sparrowwallet.drongo.address.Address;
import com.sparrowwallet.drongo.protocol.*;
import com.sparrowwallet.drongo.psbt.PSBT;
import com.sparrowwallet.drongo.psbt.PSBTInput;
@ -9,7 +10,6 @@ import com.sparrowwallet.drongo.wallet.*;
import com.sparrowwallet.sparrow.AppServices;
import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.TransactionTabData;
import com.sparrowwallet.sparrow.control.TextUtils;
import com.sparrowwallet.sparrow.control.TransactionHexArea;
import com.sparrowwallet.sparrow.event.*;
import com.sparrowwallet.sparrow.io.Config;
@ -166,12 +166,16 @@ public class TransactionController implements Initializable {
if(form != null) {
Label label = form.getLabel();
label.maxWidthProperty().bind(txTreeWidthProperty.subtract(70));
label.maxWidthProperty().bind(txTreeWidthProperty.subtract(62));
setGraphic(label);
double width = TextUtils.computeTextWidth(label.getFont(), label.getText(), 0.0D);
if(width > label.getMaxWidth()) {
Tooltip tooltip = new Tooltip(label.getText());
Address address = null;
if(form instanceof IndexedTransactionForm indexedForm) {
address = indexedForm.getAddress();
}
if(address != null) {
Tooltip tooltip = new Tooltip(label.getText() + (label.getText().equals(address.toString()) ? "" : "\n" + address));
tooltip.setMaxWidth(transactionMasterDetail.getWidth());
tooltip.setWrapText(true);
label.setTooltip(tooltip);