mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-22 19:49:32 +00:00
trade appears after deposit published
This commit is contained in:
parent
9062bc9159
commit
b6a113b742
1 changed files with 36 additions and 4 deletions
|
@ -66,6 +66,8 @@ import haveno.desktop.util.GUIUtil;
|
|||
import haveno.network.p2p.P2PService;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import javafx.beans.property.ObjectProperty;
|
||||
import javafx.beans.property.SimpleObjectProperty;
|
||||
|
@ -114,6 +116,11 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
|||
private final PubKeyRingProvider pubKeyRingProvider;
|
||||
private final CoreDisputesService disputesService;
|
||||
|
||||
private final Set<Trade> hiddenTrades = new HashSet<Trade>();
|
||||
private final ChangeListener<Trade.State> hiddenStateChangeListener = (observable, oldValue, newValue) -> {
|
||||
onListChanged();
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Constructor, initialization
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -168,6 +175,7 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
|||
|
||||
@Override
|
||||
protected void deactivate() {
|
||||
for (Trade trade : hiddenTrades) trade.stateProperty().removeListener(hiddenStateChangeListener);
|
||||
tradeManager.getObservableList().removeListener(tradesListChangeListener);
|
||||
notificationCenter.setSelectedTradeId(null);
|
||||
activated = false;
|
||||
|
@ -306,10 +314,30 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
|||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void onListChanged() {
|
||||
list.clear();
|
||||
list.addAll(tradeManager.getObservableList().stream()
|
||||
.map(trade -> new PendingTradesListItem(trade, btcFormatter))
|
||||
.collect(Collectors.toList()));
|
||||
synchronized (tradeManager.getObservableList()) {
|
||||
|
||||
// add or remove listener for hidden trades
|
||||
for (Trade trade : tradeManager.getObservableList()) {
|
||||
if (isTradeShown(trade)) {
|
||||
if (hiddenTrades.contains(trade)) {
|
||||
trade.stateProperty().removeListener(hiddenStateChangeListener);
|
||||
hiddenTrades.remove(trade);
|
||||
}
|
||||
} else {
|
||||
if (!hiddenTrades.contains(trade)) {
|
||||
trade.stateProperty().addListener(hiddenStateChangeListener);
|
||||
hiddenTrades.add(trade);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add shown trades to list
|
||||
list.clear();
|
||||
list.addAll(tradeManager.getObservableList().stream()
|
||||
.filter(trade -> isTradeShown(trade))
|
||||
.map(trade -> new PendingTradesListItem(trade, btcFormatter))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
// we sort by date, earliest first
|
||||
list.sort((o1, o2) -> o2.getTrade().getDate().compareTo(o1.getTrade().getDate()));
|
||||
|
@ -317,6 +345,10 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
|||
selectBestItem();
|
||||
}
|
||||
|
||||
private boolean isTradeShown(Trade trade) {
|
||||
return trade.isDepositsPublished();
|
||||
}
|
||||
|
||||
private void selectBestItem() {
|
||||
if (list.size() == 1)
|
||||
doSelectItem(list.get(0));
|
||||
|
|
Loading…
Reference in a new issue