Skip to content

Commit 883e75c

Browse files
committed
add copy payment code to transaction diagram outputs context menu
1 parent cc908b0 commit 883e75c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.sparrowwallet.drongo.KeyPurpose;
44
import com.sparrowwallet.drongo.OsType;
55
import com.sparrowwallet.drongo.address.Address;
6+
import com.sparrowwallet.drongo.bip47.PaymentCode;
67
import com.sparrowwallet.drongo.protocol.Sha256Hash;
78
import com.sparrowwallet.drongo.protocol.TransactionOutput;
89
import com.sparrowwallet.drongo.uri.BitcoinURI;
@@ -702,7 +703,9 @@ private Pane getOutputsLabels(List<Payment> displayedPayments) {
702703
paymentBox.getChildren().addAll(region, amountLabel);
703704
}
704705

705-
outputNodes.add(new OutputNode(paymentBox, payment.getAddress(), payment.getAmount()));
706+
Wallet bip47Wallet = toWallet != null && toWallet.isBip47() ? toWallet : (toBip47Wallet != null && toBip47Wallet.isBip47() ? toBip47Wallet : null);
707+
PaymentCode paymentCode = bip47Wallet == null ? null : bip47Wallet.getKeystores().getFirst().getExternalPaymentCode();
708+
outputNodes.add(new OutputNode(paymentBox, payment.getAddress(), payment.getAmount(), paymentCode));
706709
}
707710

708711
Set<Integer> seenIndexes = new HashSet<>();
@@ -766,7 +769,7 @@ private Pane getOutputsLabels(List<Payment> displayedPayments) {
766769
outputsBox.getChildren().add(outputNode.outputLabel);
767770
outputsBox.getChildren().add(createSpacer());
768771

769-
ContextMenu contextMenu = new LabelContextMenu(outputNode.address, outputNode.amount);
772+
ContextMenu contextMenu = new LabelContextMenu(outputNode.address, outputNode.amount, outputNode.paymentCode);
770773
if(!outputNode.outputLabel.getChildren().isEmpty() && outputNode.outputLabel.getChildren().get(0) instanceof Label outputLabelControl) {
771774
outputLabelControl.setContextMenu(contextMenu);
772775
}
@@ -1073,16 +1076,26 @@ private static class OutputNode {
10731076
public Pane outputLabel;
10741077
public Address address;
10751078
public long amount;
1079+
public PaymentCode paymentCode;
10761080

10771081
public OutputNode(Pane outputLabel, Address address, long amount) {
1082+
this(outputLabel, address, amount, null);
1083+
}
1084+
1085+
public OutputNode(Pane outputLabel, Address address, long amount, PaymentCode paymentCode) {
10781086
this.outputLabel = outputLabel;
10791087
this.address = address;
10801088
this.amount = amount;
1089+
this.paymentCode = paymentCode;
10811090
}
10821091
}
10831092

10841093
private class LabelContextMenu extends ContextMenu {
10851094
public LabelContextMenu(Address address, long value) {
1095+
this(address, value, null);
1096+
}
1097+
1098+
public LabelContextMenu(Address address, long value, PaymentCode paymentCode) {
10861099
if(address != null) {
10871100
MenuItem copyAddress = new MenuItem("Copy Address");
10881101
copyAddress.setOnAction(event -> {
@@ -1119,6 +1132,17 @@ public LabelContextMenu(Address address, long value) {
11191132
Clipboard.getSystemClipboard().setContent(content);
11201133
});
11211134
getItems().addAll(copySatsValue, copyBtcValue);
1135+
1136+
if(paymentCode != null) {
1137+
MenuItem copyPaymentCode = new MenuItem("Copy Payment Code");
1138+
copyPaymentCode.setOnAction(AE -> {
1139+
hide();
1140+
ClipboardContent content = new ClipboardContent();
1141+
content.putString(paymentCode.toString());
1142+
Clipboard.getSystemClipboard().setContent(content);
1143+
});
1144+
getItems().add(copyPaymentCode);
1145+
}
11221146
}
11231147
}
11241148
}

0 commit comments

Comments
 (0)