From 218c2720e0df73ebb4c2eccb917e38a077c27ab5 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 15 Jan 2025 08:21:48 +0200 Subject: [PATCH] always select a new address when sending multiple payments to the same open wallet --- .../sparrow/wallet/PaymentController.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java index 21622a8d..ca0729ba 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/PaymentController.java @@ -174,8 +174,13 @@ public class PaymentController extends WalletFormController implements Initializ label.requestFocus(); } } else if(newValue != null) { + List
existingAddresses = getOtherAddresses(); WalletNode freshNode = newValue.getFreshNode(KeyPurpose.RECEIVE); Address freshAddress = freshNode.getAddress(); + while(existingAddresses.contains(freshAddress)) { + freshNode = newValue.getFreshNode(KeyPurpose.RECEIVE, freshNode); + freshAddress = freshNode.getAddress(); + } address.setText(freshAddress.toString()); label.requestFocus(); } @@ -626,6 +631,22 @@ public class PaymentController extends WalletFormController implements Initializ sendController.updateTransaction(); } + private List
getOtherAddresses() { + List
otherAddresses = new ArrayList<>(); + for(Tab tab : sendController.getPaymentTabs().getTabs()) { + PaymentController controller = (PaymentController)tab.getUserData(); + if(controller != this) { + try { + otherAddresses.add(controller.getRecipientAddress()); + } catch(InvalidAddressException e) { + //ignore + } + } + } + + return otherAddresses; + } + public void addPayment(ActionEvent event) { sendController.addPaymentTab(); }