mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
handle multiple selection when freezing and unfreezing utxos
This commit is contained in:
parent
8033e5fd88
commit
4b028af123
4 changed files with 32 additions and 16 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue