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