handle multiple selection when freezing and unfreezing utxos

This commit is contained in:
Craig Raw 2021-06-30 09:18:14 +02:00
parent 8033e5fd88
commit 4b028af123
4 changed files with 32 additions and 16 deletions

View file

@ -292,14 +292,28 @@ public class EntryCell extends TreeTableCell<Entry, Entry> {
Platform.runLater(() -> EventManager.get().post(new SpendUtxoEvent(hashIndexEntry.getWallet(), spendingUtxos))); Platform.runLater(() -> EventManager.get().post(new SpendUtxoEvent(hashIndexEntry.getWallet(), spendingUtxos)));
} }
private static void freezeUtxo(HashIndexEntry hashIndexEntry) { private static void freezeUtxo(TreeTableView<Entry> treeTableView, HashIndexEntry hashIndexEntry) {
hashIndexEntry.getHashIndex().setStatus(Status.FROZEN); List<BlockTransactionHashIndex> utxos = treeTableView.getSelectionModel().getSelectedCells().stream()
EventManager.get().post(new WalletUtxoStatusChangedEvent(hashIndexEntry.getWallet(), hashIndexEntry.getHashIndex())); .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) { private static void unfreezeUtxo(TreeTableView<Entry> treeTableView, HashIndexEntry hashIndexEntry) {
hashIndexEntry.getHashIndex().setStatus(null); List<BlockTransactionHashIndex> utxos = treeTableView.getSelectionModel().getSelectedCells().stream()
EventManager.get().post(new WalletUtxoStatusChangedEvent(hashIndexEntry.getWallet(), hashIndexEntry.getHashIndex())); .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() { private static Glyph getViewTransactionGlyph() {
@ -514,7 +528,7 @@ public class EntryCell extends TreeTableCell<Entry, Entry> {
freezeUtxo.setGraphic(getFreezeGlyph()); freezeUtxo.setGraphic(getFreezeGlyph());
freezeUtxo.setOnAction(AE -> { freezeUtxo.setOnAction(AE -> {
hide(); hide();
freezeUtxo(hashIndexEntry); freezeUtxo(treeTableView, hashIndexEntry);
}); });
getItems().add(freezeUtxo); getItems().add(freezeUtxo);
} else { } else {
@ -522,7 +536,7 @@ public class EntryCell extends TreeTableCell<Entry, Entry> {
unfreezeUtxo.setGraphic(getUnfreezeGlyph()); unfreezeUtxo.setGraphic(getUnfreezeGlyph());
unfreezeUtxo.setOnAction(AE -> { unfreezeUtxo.setOnAction(AE -> {
hide(); hide();
unfreezeUtxo(hashIndexEntry); unfreezeUtxo(treeTableView, hashIndexEntry);
}); });
getItems().add(unfreezeUtxo); getItems().add(unfreezeUtxo);
} }

View file

@ -3,15 +3,17 @@ package com.sparrowwallet.sparrow.event;
import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex; import com.sparrowwallet.drongo.wallet.BlockTransactionHashIndex;
import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.Wallet;
public class WalletUtxoStatusChangedEvent extends WalletChangedEvent { import java.util.List;
private final BlockTransactionHashIndex utxo;
public WalletUtxoStatusChangedEvent(Wallet wallet, BlockTransactionHashIndex utxo) { public class WalletUtxoStatusChangedEvent extends WalletChangedEvent {
private final List<BlockTransactionHashIndex> utxos;
public WalletUtxoStatusChangedEvent(Wallet wallet, List<BlockTransactionHashIndex> utxos) {
super(wallet); super(wallet);
this.utxo = utxo; this.utxos = utxos;
} }
public BlockTransactionHashIndex getUtxo() { public List<BlockTransactionHashIndex> getUtxos() {
return utxo; return utxos;
} }
} }

View file

@ -610,7 +610,7 @@ public class DbPersistence implements Persistence {
@Subscribe @Subscribe
public void walletUtxoStatusChanged(WalletUtxoStatusChangedEvent event) { public void walletUtxoStatusChanged(WalletUtxoStatusChangedEvent event) {
if(persistsFor(event.getWallet())) { 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());
} }
} }

View file

@ -1164,7 +1164,7 @@ public class SendController extends WalletFormController implements Initializabl
updateTransaction(true); updateTransaction(true);
} else if(utxoSelectorProperty().get() instanceof PresetUtxoSelector) { } else if(utxoSelectorProperty().get() instanceof PresetUtxoSelector) {
PresetUtxoSelector presetUtxoSelector = new PresetUtxoSelector(((PresetUtxoSelector)utxoSelector).getPresetUtxos()); PresetUtxoSelector presetUtxoSelector = new PresetUtxoSelector(((PresetUtxoSelector)utxoSelector).getPresetUtxos());
presetUtxoSelector.getPresetUtxos().remove(event.getUtxo()); presetUtxoSelector.getPresetUtxos().removeAll(event.getUtxos());
utxoSelectorProperty.set(presetUtxoSelector); utxoSelectorProperty.set(presetUtxoSelector);
updateTransaction(true); updateTransaction(true);
} else { } else {