mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-05 05:46:44 +00:00
show entered labels in transaction view diagram when sending to multiple recipients
This commit is contained in:
parent
b530ced9ed
commit
cd91aff3bb
4 changed files with 38 additions and 9 deletions
|
@ -9,8 +9,10 @@ import com.sparrowwallet.drongo.protocol.ScriptType;
|
||||||
import com.sparrowwallet.drongo.protocol.Transaction;
|
import com.sparrowwallet.drongo.protocol.Transaction;
|
||||||
import com.sparrowwallet.drongo.psbt.PSBT;
|
import com.sparrowwallet.drongo.psbt.PSBT;
|
||||||
import com.sparrowwallet.drongo.uri.BitcoinURI;
|
import com.sparrowwallet.drongo.uri.BitcoinURI;
|
||||||
|
import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex;
|
||||||
import com.sparrowwallet.drongo.wallet.KeystoreSource;
|
import com.sparrowwallet.drongo.wallet.KeystoreSource;
|
||||||
import com.sparrowwallet.drongo.wallet.Wallet;
|
import com.sparrowwallet.drongo.wallet.Wallet;
|
||||||
|
import com.sparrowwallet.drongo.wallet.WalletTransaction;
|
||||||
import com.sparrowwallet.sparrow.control.TextUtils;
|
import com.sparrowwallet.sparrow.control.TextUtils;
|
||||||
import com.sparrowwallet.sparrow.control.TrayManager;
|
import com.sparrowwallet.sparrow.control.TrayManager;
|
||||||
import com.sparrowwallet.sparrow.event.*;
|
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);
|
return getOpenWallets().entrySet().stream().filter(entry -> entry.getValue().getWalletId(entry.getKey()).equals(walletId)).map(Map.Entry::getKey).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WalletTransaction getCreatedTransaction(Set<BlockTransactionHashIndex> utxos) {
|
||||||
|
for(List<WalletTabData> 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) {
|
public Window getWindowForWallet(String walletId) {
|
||||||
Optional<Window> optWindow = walletWindows.entrySet().stream().filter(entry -> entry.getValue().stream().anyMatch(walletTabData -> walletTabData.getWalletForm().getWalletId().equals(walletId))).map(Map.Entry::getKey).findFirst();
|
Optional<Window> 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);
|
return optWindow.orElse(null);
|
||||||
|
|
|
@ -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);
|
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();
|
String label = headersForm.getName() == null || (headersForm.getName().startsWith("[") && headersForm.getName().endsWith("]") && headersForm.getName().length() == 8) ? null : headersForm.getName();
|
||||||
try {
|
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<Payment> 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) {
|
} catch(Exception e) {
|
||||||
//ignore
|
//ignore
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,8 +158,6 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
|
|
||||||
private final ObjectProperty<WalletTransaction> walletTransactionProperty = new SimpleObjectProperty<>(null);
|
private final ObjectProperty<WalletTransaction> walletTransactionProperty = new SimpleObjectProperty<>(null);
|
||||||
|
|
||||||
private final ObjectProperty<WalletTransaction> createdWalletTransactionProperty = new SimpleObjectProperty<>(null);
|
|
||||||
|
|
||||||
private final BooleanProperty insufficientInputsProperty = new SimpleBooleanProperty(false);
|
private final BooleanProperty insufficientInputsProperty = new SimpleBooleanProperty(false);
|
||||||
|
|
||||||
private final StringProperty utxoLabelSelectionProperty = new SimpleStringProperty("");
|
private final StringProperty utxoLabelSelectionProperty = new SimpleStringProperty("");
|
||||||
|
@ -1044,7 +1042,7 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
opReturnsList.clear();
|
opReturnsList.clear();
|
||||||
excludedChangeNodes.clear();
|
excludedChangeNodes.clear();
|
||||||
walletTransactionProperty.setValue(null);
|
walletTransactionProperty.setValue(null);
|
||||||
createdWalletTransactionProperty.set(null);
|
walletForm.setCreatedWalletTransaction(null);
|
||||||
insufficientInputsProperty.set(false);
|
insufficientInputsProperty.set(false);
|
||||||
|
|
||||||
validationSupport.setErrorDecorationEnabled(false);
|
validationSupport.setErrorDecorationEnabled(false);
|
||||||
|
@ -1124,7 +1122,7 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
}
|
}
|
||||||
|
|
||||||
addWalletTransactionNodes();
|
addWalletTransactionNodes();
|
||||||
createdWalletTransactionProperty.set(walletTransaction);
|
walletForm.setCreatedWalletTransaction(walletTransaction);
|
||||||
PSBT psbt = walletTransaction.createPSBT();
|
PSBT psbt = walletTransaction.createPSBT();
|
||||||
EventManager.get().post(new ViewPSBTEvent(createButton.getScene().getWindow(), walletTransaction.getPayments().get(0).getLabel(), null, psbt));
|
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
|
@Subscribe
|
||||||
public void walletHistoryChanged(WalletHistoryChangedEvent event) {
|
public void walletHistoryChanged(WalletHistoryChangedEvent event) {
|
||||||
if(event.getWallet().equals(walletForm.getWallet()) && createdWalletTransactionProperty.get() != null) {
|
if(event.getWallet().equals(walletForm.getWallet()) && walletForm.getCreatedWalletTransaction() != null) {
|
||||||
if(createdWalletTransactionProperty.get().getSelectedUtxos() != null && allSelectedUtxosSpent(event.getHistoryChangedNodes())) {
|
if(walletForm.getCreatedWalletTransaction().getSelectedUtxos() != null && allSelectedUtxosSpent(event.getHistoryChangedNodes())) {
|
||||||
clear(null);
|
clear(null);
|
||||||
} else {
|
} else {
|
||||||
updateTransaction();
|
updateTransaction();
|
||||||
|
@ -1214,9 +1212,9 @@ public class SendController extends WalletFormController implements Initializabl
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean allSelectedUtxosSpent(List<WalletNode> historyChangedNodes) {
|
private boolean allSelectedUtxosSpent(List<WalletNode> historyChangedNodes) {
|
||||||
Set<BlockTransactionHashIndex> unspentUtxos = new HashSet<>(createdWalletTransactionProperty.get().getSelectedUtxos().keySet());
|
Set<BlockTransactionHashIndex> unspentUtxos = new HashSet<>(walletForm.getCreatedWalletTransaction().getSelectedUtxos().keySet());
|
||||||
|
|
||||||
for(Map.Entry<BlockTransactionHashIndex, WalletNode> selectedUtxoEntry : createdWalletTransactionProperty.get().getSelectedUtxos().entrySet()) {
|
for(Map.Entry<BlockTransactionHashIndex, WalletNode> selectedUtxoEntry : walletForm.getCreatedWalletTransaction().getSelectedUtxos().entrySet()) {
|
||||||
BlockTransactionHashIndex utxo = selectedUtxoEntry.getKey();
|
BlockTransactionHashIndex utxo = selectedUtxoEntry.getKey();
|
||||||
WalletNode utxoWalletNode = selectedUtxoEntry.getValue();
|
WalletNode utxoWalletNode = selectedUtxoEntry.getValue();
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,9 @@ import com.sparrowwallet.sparrow.io.Storage;
|
||||||
import com.sparrowwallet.sparrow.net.ServerType;
|
import com.sparrowwallet.sparrow.net.ServerType;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.beans.property.BooleanProperty;
|
import javafx.beans.property.BooleanProperty;
|
||||||
|
import javafx.beans.property.ObjectProperty;
|
||||||
import javafx.beans.property.SimpleBooleanProperty;
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -39,6 +41,7 @@ public class WalletForm {
|
||||||
private WalletUtxosEntry walletUtxosEntry;
|
private WalletUtxosEntry walletUtxosEntry;
|
||||||
private final List<NodeEntry> accountEntries = new ArrayList<>();
|
private final List<NodeEntry> accountEntries = new ArrayList<>();
|
||||||
private final List<Set<WalletNode>> walletTransactionNodes = new ArrayList<>();
|
private final List<Set<WalletNode>> walletTransactionNodes = new ArrayList<>();
|
||||||
|
private final ObjectProperty<WalletTransaction> createdWalletTransactionProperty = new SimpleObjectProperty<>(null);
|
||||||
|
|
||||||
private ElectrumServer.TransactionMempoolService transactionMempoolService;
|
private ElectrumServer.TransactionMempoolService transactionMempoolService;
|
||||||
|
|
||||||
|
@ -286,6 +289,14 @@ public class WalletForm {
|
||||||
return allNodes.isEmpty() ? walletNodes : allNodes;
|
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) {
|
public NodeEntry getNodeEntry(KeyPurpose keyPurpose) {
|
||||||
NodeEntry purposeEntry;
|
NodeEntry purposeEntry;
|
||||||
Optional<NodeEntry> optionalPurposeEntry = accountEntries.stream().filter(entry -> entry.getNode().getKeyPurpose().equals(keyPurpose)).findFirst();
|
Optional<NodeEntry> optionalPurposeEntry = accountEntries.stream().filter(entry -> entry.getNode().getKeyPurpose().equals(keyPurpose)).findFirst();
|
||||||
|
|
Loading…
Reference in a new issue