mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-03 11:35:52 -04:00
synchronize access to pending trades data model
Co-authored-by: XMRZombie <monerozombie@proton.me>
This commit is contained in:
parent
cd71bcdde7
commit
b72159fcf8
@ -332,15 +332,17 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
||||
}
|
||||
|
||||
// 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()));
|
||||
}
|
||||
synchronized (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()));
|
||||
// we sort by date, earliest first
|
||||
list.sort((o1, o2) -> o2.getTrade().getDate().compareTo(o1.getTrade().getDate()));
|
||||
}
|
||||
}
|
||||
|
||||
selectBestItem();
|
||||
}
|
||||
@ -350,17 +352,21 @@ public class PendingTradesDataModel extends ActivatableDataModel {
|
||||
}
|
||||
|
||||
private void selectBestItem() {
|
||||
if (list.size() == 1)
|
||||
doSelectItem(list.get(0));
|
||||
else if (list.size() > 1 && (selectedItemProperty.get() == null || !list.contains(selectedItemProperty.get())))
|
||||
doSelectItem(list.get(0));
|
||||
else if (list.size() == 0)
|
||||
doSelectItem(null);
|
||||
synchronized (list) {
|
||||
if (list.size() == 1)
|
||||
doSelectItem(list.get(0));
|
||||
else if (list.size() > 1 && (selectedItemProperty.get() == null || !list.contains(selectedItemProperty.get())))
|
||||
doSelectItem(list.get(0));
|
||||
else if (list.size() == 0)
|
||||
doSelectItem(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void selectItemByTradeId(String tradeId) {
|
||||
if (activated) {
|
||||
list.stream().filter(e -> e.getTrade().getId().equals(tradeId)).findAny().ifPresent(this::doSelectItem);
|
||||
synchronized (list) {
|
||||
list.stream().filter(e -> e.getTrade().getId().equals(tradeId)).findAny().ifPresent(this::doSelectItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -363,7 +363,11 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
||||
}
|
||||
|
||||
private void updateMoveTradeToFailedColumnState() {
|
||||
UserThread.execute(() -> moveTradeToFailedColumn.setVisible(model.dataModel.list.stream().anyMatch(item -> isMaybeInvalidTrade(item.getTrade()))));
|
||||
UserThread.execute(() -> {
|
||||
synchronized (model.dataModel.list) {
|
||||
moveTradeToFailedColumn.setVisible(model.dataModel.list.stream().anyMatch(item -> isMaybeInvalidTrade(item.getTrade())));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean isMaybeInvalidTrade(Trade trade) {
|
||||
@ -420,16 +424,18 @@ public class PendingTradesView extends ActivatableViewAndModel<VBox, PendingTrad
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void updateNewChatMessagesByTradeMap() {
|
||||
model.dataModel.list.forEach(t -> {
|
||||
Trade trade = t.getTrade();
|
||||
synchronized (trade.getChatMessages()) {
|
||||
newChatMessagesByTradeMap.put(trade.getId(),
|
||||
trade.getChatMessages().stream()
|
||||
.filter(m -> !m.isWasDisplayed())
|
||||
.filter(m -> !m.isSystemMessage())
|
||||
.count());
|
||||
}
|
||||
});
|
||||
synchronized (model.dataModel.list) {
|
||||
model.dataModel.list.forEach(t -> {
|
||||
Trade trade = t.getTrade();
|
||||
synchronized (trade.getChatMessages()) {
|
||||
newChatMessagesByTradeMap.put(trade.getId(),
|
||||
trade.getChatMessages().stream()
|
||||
.filter(m -> !m.isWasDisplayed())
|
||||
.filter(m -> !m.isSystemMessage())
|
||||
.count());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void openChat(Trade trade) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user