Skip to content

Commit

Permalink
Fix offer list filter bug due to direction flip
Browse files Browse the repository at this point in the history
Respect the direction parmeter;  do not give it meaning it does not
have.  If the user passes a 'buy' parameter, return buy offers.  Do
not misinterpret the param's intent.  The direction parameter's value
does not imply "buy=I'm a buyer, show me sell offers" or
"sell=I'm a seller, show me buy offers".

I got mixed up by looking at the UI.  If I want to sell BTC, I click
the SELL tab to view buy offers (maker as buyer).  If I want to buy
BTC, I click the BUY tab to view sell offers (maker as seller).

This change also fixes an offer list sorting bug.

The commit is in response to a requested changes in PR 4329:
bisq-network#4329 (review)
  • Loading branch information
ghubstan authored and eigentsmis committed Jun 26, 2020
1 parent 8bdbf79 commit 011f531
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cli/src/main/java/bisq/cli/TableFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static String formatOfferTable(List<OfferInfo> offerInfo, String fiatCurrency) {
return headerLine
+ offerInfo.stream()
.map(o -> format(colDataFormat,
o.getDirection().equals("BUY") ? "SELL" : "BUY",
o.getDirection(),
formatOfferPrice(o.getPrice()),
formatAmountRange(o.getMinAmount(), o.getAmount()),
formatVolumeRange(o.getMinVolume(), o.getVolume()),
Expand Down
15 changes: 10 additions & 5 deletions core/src/main/java/bisq/core/grpc/CoreOffersService.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,19 @@ public CoreOffersService(CreateOfferService createOfferService,

public List<Offer> getOffers(String direction, String fiatCurrencyCode) {
List<Offer> offers = offerBookService.getOffers().stream()
.filter(o -> !o.getDirection().name().equalsIgnoreCase(direction)
&& o.getOfferPayload().getCounterCurrencyCode().equalsIgnoreCase(fiatCurrencyCode))
.filter(o -> {
var offerOfWantedDirection = o.getDirection().name().equalsIgnoreCase(direction);
var offerInWantedCurrency = o.getOfferPayload().getCounterCurrencyCode().equalsIgnoreCase(fiatCurrencyCode);
return offerOfWantedDirection && offerInWantedCurrency;
})
.collect(Collectors.toList());

if (direction.equals(BUY.name()))
offers.sort(Comparator.comparing(Offer::getPrice));
else
// A buyer probably wants to see sell orders in price ascending order.
// A seller probably wants to see buy orders in price descending order.
if (direction.equalsIgnoreCase(BUY.name()))
offers.sort(Comparator.comparing(Offer::getPrice).reversed());
else
offers.sort(Comparator.comparing(Offer::getPrice));

return offers;
}
Expand Down

0 comments on commit 011f531

Please sign in to comment.