diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index 1d5e4456..7fe353ac 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -9,8 +9,10 @@ import com.sparrowwallet.drongo.protocol.ScriptType; import com.sparrowwallet.drongo.protocol.Transaction; import com.sparrowwallet.drongo.psbt.PSBT; import com.sparrowwallet.drongo.uri.BitcoinURI; +import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex; import com.sparrowwallet.drongo.wallet.KeystoreSource; import com.sparrowwallet.drongo.wallet.Wallet; +import com.sparrowwallet.drongo.wallet.WalletTransaction; import com.sparrowwallet.sparrow.control.TextUtils; import com.sparrowwallet.sparrow.control.TrayManager; import com.sparrowwallet.sparrow.event.*; @@ -543,6 +545,18 @@ public class AppServices { return getOpenWallets().entrySet().stream().filter(entry -> entry.getValue().getWalletId(entry.getKey()).equals(walletId)).map(Map.Entry::getKey).findFirst().orElse(null); } + public WalletTransaction getCreatedTransaction(Set utxos) { + for(List walletTabDataList : walletWindows.values()) { + for(WalletTabData walletTabData : walletTabDataList) { + if(walletTabData.getWalletForm().getCreatedWalletTransaction() != null && utxos.equals(walletTabData.getWalletForm().getCreatedWalletTransaction().getSelectedUtxos().keySet())) { + return walletTabData.getWalletForm().getCreatedWalletTransaction(); + } + } + } + + return null; + } + public Window getWindowForWallet(String walletId) { Optional optWindow = walletWindows.entrySet().stream().filter(entry -> entry.getValue().stream().anyMatch(walletTabData -> walletTabData.getWalletForm().getWalletId().equals(walletId))).map(Map.Entry::getKey).findFirst(); return optWindow.orElse(null); diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index 1245b736..d6a2b3ab 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -589,7 +589,13 @@ public class HeadersController extends TransactionFormController implements Init BlockTransactionHashIndex receivedTxo = walletTxos.keySet().stream().filter(txo -> txo.getHash().equals(txOutput.getHash()) && txo.getIndex() == txOutput.getIndex()).findFirst().orElse(null); String label = headersForm.getName() == null || (headersForm.getName().startsWith("[") && headersForm.getName().endsWith("]") && headersForm.getName().length() == 8) ? null : headersForm.getName(); try { - payments.add(new Payment(txOutput.getScript().getToAddresses()[0], receivedTxo != null ? receivedTxo.getLabel() : label, txOutput.getValue(), false, paymentType)); + Payment payment = new Payment(txOutput.getScript().getToAddresses()[0], receivedTxo != null ? receivedTxo.getLabel() : label, txOutput.getValue(), false, paymentType); + WalletTransaction createdTx = AppServices.get().getCreatedTransaction(selectedTxos.keySet()); + if(createdTx != null) { + Optional optPymt = createdTx.getPayments().stream().filter(pymt -> pymt.getAddress().equals(payment.getAddress()) && pymt.getAmount() == payment.getAmount()).findFirst(); + optPymt.ifPresent(pymt -> payment.setLabel(pymt.getLabel())); + } + payments.add(payment); } catch(Exception e) { //ignore } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index eb2dbaf1..2238e21f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -158,8 +158,6 @@ public class SendController extends WalletFormController implements Initializabl private final ObjectProperty walletTransactionProperty = new SimpleObjectProperty<>(null); - private final ObjectProperty createdWalletTransactionProperty = new SimpleObjectProperty<>(null); - private final BooleanProperty insufficientInputsProperty = new SimpleBooleanProperty(false); private final StringProperty utxoLabelSelectionProperty = new SimpleStringProperty(""); @@ -1044,7 +1042,7 @@ public class SendController extends WalletFormController implements Initializabl opReturnsList.clear(); excludedChangeNodes.clear(); walletTransactionProperty.setValue(null); - createdWalletTransactionProperty.set(null); + walletForm.setCreatedWalletTransaction(null); insufficientInputsProperty.set(false); validationSupport.setErrorDecorationEnabled(false); @@ -1124,7 +1122,7 @@ public class SendController extends WalletFormController implements Initializabl } addWalletTransactionNodes(); - createdWalletTransactionProperty.set(walletTransaction); + walletForm.setCreatedWalletTransaction(walletTransaction); PSBT psbt = walletTransaction.createPSBT(); EventManager.get().post(new ViewPSBTEvent(createButton.getScene().getWindow(), walletTransaction.getPayments().get(0).getLabel(), null, psbt)); } @@ -1204,8 +1202,8 @@ public class SendController extends WalletFormController implements Initializabl @Subscribe public void walletHistoryChanged(WalletHistoryChangedEvent event) { - if(event.getWallet().equals(walletForm.getWallet()) && createdWalletTransactionProperty.get() != null) { - if(createdWalletTransactionProperty.get().getSelectedUtxos() != null && allSelectedUtxosSpent(event.getHistoryChangedNodes())) { + if(event.getWallet().equals(walletForm.getWallet()) && walletForm.getCreatedWalletTransaction() != null) { + if(walletForm.getCreatedWalletTransaction().getSelectedUtxos() != null && allSelectedUtxosSpent(event.getHistoryChangedNodes())) { clear(null); } else { updateTransaction(); @@ -1214,9 +1212,9 @@ public class SendController extends WalletFormController implements Initializabl } private boolean allSelectedUtxosSpent(List historyChangedNodes) { - Set unspentUtxos = new HashSet<>(createdWalletTransactionProperty.get().getSelectedUtxos().keySet()); + Set unspentUtxos = new HashSet<>(walletForm.getCreatedWalletTransaction().getSelectedUtxos().keySet()); - for(Map.Entry selectedUtxoEntry : createdWalletTransactionProperty.get().getSelectedUtxos().entrySet()) { + for(Map.Entry selectedUtxoEntry : walletForm.getCreatedWalletTransaction().getSelectedUtxos().entrySet()) { BlockTransactionHashIndex utxo = selectedUtxoEntry.getKey(); WalletNode utxoWalletNode = selectedUtxoEntry.getValue(); diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java index 72ecab76..90bce949 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/WalletForm.java @@ -16,7 +16,9 @@ import com.sparrowwallet.sparrow.io.Storage; import com.sparrowwallet.sparrow.net.ServerType; import javafx.application.Platform; import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleObjectProperty; import javafx.util.Duration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,6 +41,7 @@ public class WalletForm { private WalletUtxosEntry walletUtxosEntry; private final List accountEntries = new ArrayList<>(); private final List> walletTransactionNodes = new ArrayList<>(); + private final ObjectProperty createdWalletTransactionProperty = new SimpleObjectProperty<>(null); private ElectrumServer.TransactionMempoolService transactionMempoolService; @@ -286,6 +289,14 @@ public class WalletForm { return allNodes.isEmpty() ? walletNodes : allNodes; } + public WalletTransaction getCreatedWalletTransaction() { + return createdWalletTransactionProperty.get(); + } + + public void setCreatedWalletTransaction(WalletTransaction createdWalletTransaction) { + this.createdWalletTransactionProperty.set(createdWalletTransaction); + } + public NodeEntry getNodeEntry(KeyPurpose keyPurpose) { NodeEntry purposeEntry; Optional optionalPurposeEntry = accountEntries.stream().filter(entry -> entry.getNode().getKeyPurpose().equals(keyPurpose)).findFirst();