mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 15:00:30 +01:00
Only add offers if it is not in list
This commit is contained in:
parent
02f04d3129
commit
8b98429341
1 changed files with 24 additions and 13 deletions
|
@ -53,20 +53,31 @@ public class OfferBook {
|
||||||
offerBookService.addOfferBookChangedListener(new OfferBookService.OfferBookChangedListener() {
|
offerBookService.addOfferBookChangedListener(new OfferBookService.OfferBookChangedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAdded(Offer offer) {
|
public void onAdded(Offer offer) {
|
||||||
OfferBookListItem offerBookListItem = new OfferBookListItem(offer);
|
// We get onAdded called every time a new ProtectedStorageEntry is received.
|
||||||
// We don't use the contains method as the equals method in Offer takes state and errorMessage into account.
|
// Mostly it is the same OfferPayload but the ProtectedStorageEntry is different.
|
||||||
// If we have an offer with same ID we remove it and add the new offer as it might have a changed state.
|
// We filter here to only add new offers if the same offer (using equals) was not already added.
|
||||||
Optional<OfferBookListItem> candidateToRemove = offerBookListItems.stream()
|
boolean hasSameOffer = offerBookListItems.stream()
|
||||||
.filter(item -> item.getOffer().getId().equals(offer.getId()))
|
.filter(item -> item.getOffer().equals(offer))
|
||||||
.findAny();
|
.findAny()
|
||||||
if (candidateToRemove.isPresent()) {
|
.isPresent();
|
||||||
log.info("We had an old offer in the list with the same Offer ID. Might be that the state or errorMessage was different. " +
|
if (!hasSameOffer) {
|
||||||
"old offerBookListItem={}, new offerBookListItem={}", candidateToRemove.get(), offerBookListItem);
|
OfferBookListItem offerBookListItem = new OfferBookListItem(offer);
|
||||||
offerBookListItems.remove(candidateToRemove.get());
|
// We don't use the contains method as the equals method in Offer takes state and errorMessage into account.
|
||||||
}
|
// If we have an offer with same ID we remove it and add the new offer as it might have a changed state.
|
||||||
|
Optional<OfferBookListItem> candidateWithSameId = offerBookListItems.stream()
|
||||||
|
.filter(item -> item.getOffer().getId().equals(offer.getId()))
|
||||||
|
.findAny();
|
||||||
|
if (candidateWithSameId.isPresent()) {
|
||||||
|
log.warn("We had an old offer in the list with the same Offer ID. Might be that the state or errorMessage was different. " +
|
||||||
|
"old offerBookListItem={}, new offerBookListItem={}", candidateWithSameId.get(), offerBookListItem);
|
||||||
|
offerBookListItems.remove(candidateWithSameId.get());
|
||||||
|
}
|
||||||
|
|
||||||
offerBookListItems.add(offerBookListItem);
|
offerBookListItems.add(offerBookListItem);
|
||||||
Log.logIfStressTests("OfferPayload added: No. of offers = " + offerBookListItems.size());
|
Log.logIfStressTests("OfferPayload added: No. of offers = " + offerBookListItems.size());
|
||||||
|
}else{
|
||||||
|
log.debug("We have the exact same offer already in our list and ignore the onAdded call. ID={}", offer.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Reference in a new issue