diff --git a/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java b/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java index 7b544d6e..b732f566 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/EntryCell.java @@ -292,14 +292,28 @@ public class EntryCell extends TreeTableCell { Platform.runLater(() -> EventManager.get().post(new SpendUtxoEvent(hashIndexEntry.getWallet(), spendingUtxos))); } - private static void freezeUtxo(HashIndexEntry hashIndexEntry) { - hashIndexEntry.getHashIndex().setStatus(Status.FROZEN); - EventManager.get().post(new WalletUtxoStatusChangedEvent(hashIndexEntry.getWallet(), hashIndexEntry.getHashIndex())); + private static void freezeUtxo(TreeTableView treeTableView, HashIndexEntry hashIndexEntry) { + List utxos = treeTableView.getSelectionModel().getSelectedCells().stream() + .map(tp -> tp.getTreeItem().getValue()) + .filter(e -> e instanceof HashIndexEntry && ((HashIndexEntry)e).getType().equals(HashIndexEntry.Type.OUTPUT)) + .map(e -> ((HashIndexEntry)e).getHashIndex()) + .filter(ref -> ref.getStatus() != Status.FROZEN) + .collect(Collectors.toList()); + + utxos.forEach(ref -> ref.setStatus(Status.FROZEN)); + EventManager.get().post(new WalletUtxoStatusChangedEvent(hashIndexEntry.getWallet(), utxos)); } - private static void unfreezeUtxo(HashIndexEntry hashIndexEntry) { - hashIndexEntry.getHashIndex().setStatus(null); - EventManager.get().post(new WalletUtxoStatusChangedEvent(hashIndexEntry.getWallet(), hashIndexEntry.getHashIndex())); + private static void unfreezeUtxo(TreeTableView treeTableView, HashIndexEntry hashIndexEntry) { + List utxos = treeTableView.getSelectionModel().getSelectedCells().stream() + .map(tp -> tp.getTreeItem().getValue()) + .filter(e -> e instanceof HashIndexEntry && ((HashIndexEntry)e).getType().equals(HashIndexEntry.Type.OUTPUT)) + .map(e -> ((HashIndexEntry)e).getHashIndex()) + .filter(ref -> ref.getStatus() == Status.FROZEN) + .collect(Collectors.toList()); + + utxos.forEach(ref -> ref.setStatus(null)); + EventManager.get().post(new WalletUtxoStatusChangedEvent(hashIndexEntry.getWallet(), utxos)); } private static Glyph getViewTransactionGlyph() { @@ -514,7 +528,7 @@ public class EntryCell extends TreeTableCell { freezeUtxo.setGraphic(getFreezeGlyph()); freezeUtxo.setOnAction(AE -> { hide(); - freezeUtxo(hashIndexEntry); + freezeUtxo(treeTableView, hashIndexEntry); }); getItems().add(freezeUtxo); } else { @@ -522,7 +536,7 @@ public class EntryCell extends TreeTableCell { unfreezeUtxo.setGraphic(getUnfreezeGlyph()); unfreezeUtxo.setOnAction(AE -> { hide(); - unfreezeUtxo(hashIndexEntry); + unfreezeUtxo(treeTableView, hashIndexEntry); }); getItems().add(unfreezeUtxo); } diff --git a/src/main/java/com/sparrowwallet/sparrow/event/WalletUtxoStatusChangedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/WalletUtxoStatusChangedEvent.java index ceb67cf4..c1e09ea8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/event/WalletUtxoStatusChangedEvent.java +++ b/src/main/java/com/sparrowwallet/sparrow/event/WalletUtxoStatusChangedEvent.java @@ -3,15 +3,17 @@ package com.sparrowwallet.sparrow.event; import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex; import com.sparrowwallet.drongo.wallet.Wallet; -public class WalletUtxoStatusChangedEvent extends WalletChangedEvent { - private final BlockTransactionHashIndex utxo; +import java.util.List; - public WalletUtxoStatusChangedEvent(Wallet wallet, BlockTransactionHashIndex utxo) { +public class WalletUtxoStatusChangedEvent extends WalletChangedEvent { + private final List utxos; + + public WalletUtxoStatusChangedEvent(Wallet wallet, List utxos) { super(wallet); - this.utxo = utxo; + this.utxos = utxos; } - public BlockTransactionHashIndex getUtxo() { - return utxo; + public List getUtxos() { + return utxos; } } diff --git a/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java b/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java index 7aa6a214..29771f60 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/db/DbPersistence.java @@ -610,7 +610,7 @@ public class DbPersistence implements Persistence { @Subscribe public void walletUtxoStatusChanged(WalletUtxoStatusChangedEvent event) { if(persistsFor(event.getWallet())) { - dirtyPersistablesMap.computeIfAbsent(event.getWallet(), key -> new DirtyPersistables()).utxoStatuses.add(event.getUtxo()); + dirtyPersistablesMap.computeIfAbsent(event.getWallet(), key -> new DirtyPersistables()).utxoStatuses.addAll(event.getUtxos()); } } diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java index ee057d56..29513ab2 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SendController.java @@ -1164,7 +1164,7 @@ public class SendController extends WalletFormController implements Initializabl updateTransaction(true); } else if(utxoSelectorProperty().get() instanceof PresetUtxoSelector) { PresetUtxoSelector presetUtxoSelector = new PresetUtxoSelector(((PresetUtxoSelector)utxoSelector).getPresetUtxos()); - presetUtxoSelector.getPresetUtxos().remove(event.getUtxo()); + presetUtxoSelector.getPresetUtxos().removeAll(event.getUtxos()); utxoSelectorProperty.set(presetUtxoSelector); updateTransaction(true); } else {