From 9280504f709a7c2867ea8fc281b02e4fc0164027 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Thu, 12 Oct 2023 12:37:41 +0200 Subject: [PATCH] add duplicate payment address warning to transaction diagram --- .../sparrow/control/TransactionDiagram.java | 16 +++++++++++++++- .../sparrow/transaction/headers.css | 2 +- .../com/sparrowwallet/sparrow/wallet/send.css | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java index 693efb61..67641ff0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TransactionDiagram.java @@ -697,7 +697,8 @@ public class TransactionDiagram extends GridPane { Wallet toBip47Wallet = getBip47SendWallet(payment); Tooltip recipientTooltip = new Tooltip((toWallet == null ? (toNode != null ? "Consolidate " : "Pay ") : "Receive ") + getSatsValue(payment.getAmount()) + " sats to " - + (payment instanceof AdditionalPayment ? (isExpanded() ? "\n" : "(click to expand)\n") + payment : (toWallet == null ? (payment.getLabel() == null ? (toNode != null ? toNode : (toBip47Wallet == null ? "external address" : toBip47Wallet.getDisplayName())) : payment.getLabel()) : toWallet.getFullDisplayName()) + "\n" + payment.getAddress().toString())); + + (payment instanceof AdditionalPayment ? (isExpanded() ? "\n" : "(click to expand)\n") + payment : (toWallet == null ? (payment.getLabel() == null ? (toNode != null ? toNode : (toBip47Wallet == null ? "external address" : toBip47Wallet.getDisplayName())) : payment.getLabel()) : toWallet.getFullDisplayName()) + "\n" + payment.getAddress().toString()) + + (isDuplicateAddress(payment) ? " (Duplicate)" : "")); recipientTooltip.getStyleClass().add("recipient-label"); recipientTooltip.setShowDelay(new Duration(TOOLTIP_SHOW_DELAY)); recipientTooltip.setShowDuration(Duration.INDEFINITE); @@ -990,11 +991,17 @@ public class TransactionDiagram extends GridPane { return ((AdditionalPayment)payment).getOutputGlyph(this); } else if(getToWallet(payment) != null) { return getDepositGlyph(); + } else if(isDuplicateAddress(payment)) { + return getPaymentWarningGlyph(); } return getPaymentGlyph(); } + private boolean isDuplicateAddress(Payment payment) { + return walletTx.getPayments().stream().filter(p -> payment != p).anyMatch(p -> payment.getAddress().equals(p.getAddress())); + } + public static Glyph getExcludeGlyph() { Glyph excludeGlyph = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.TIMES_CIRCLE); excludeGlyph.getStyleClass().add("exclude-utxo"); @@ -1009,6 +1016,13 @@ public class TransactionDiagram extends GridPane { return paymentGlyph; } + public static Glyph getPaymentWarningGlyph() { + Glyph paymentWarningGlyph = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.EXCLAMATION_TRIANGLE); + paymentWarningGlyph.getStyleClass().add("payment-warning-icon"); + paymentWarningGlyph.setFontSize(12); + return paymentWarningGlyph; + } + public static Glyph getConsolidationGlyph() { Glyph consolidationGlyph = new Glyph(FontAwesome5.FONT_NAME, FontAwesome5.Glyph.REPLY_ALL); consolidationGlyph.getStyleClass().add("consolidation-icon"); diff --git a/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css b/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css index cc2dc6b5..2687daca 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css +++ b/src/main/resources/com/sparrowwallet/sparrow/transaction/headers.css @@ -78,7 +78,7 @@ -fx-fill: -fx-text-base-color; } -#transactionDiagram .change-warning-icon { +#transactionDiagram .change-warning-icon, #transactionDiagram .payment-warning-icon { -fx-text-fill: rgb(238, 210, 2); } diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/send.css b/src/main/resources/com/sparrowwallet/sparrow/wallet/send.css index 89a7958e..c0f4f67e 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/send.css +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/send.css @@ -109,7 +109,7 @@ -fx-fill: -fx-text-base-color; } -#transactionDiagram .change-warning-icon { +#transactionDiagram .change-warning-icon, #transactionDiagram .payment-warning-icon { -fx-text-fill: rgb(238, 210, 2); }