mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Sort the final, cumulative trades list in gRPC GetTrades service
Resolves issue https://github.com/bisq-network/bisq/pull/5976#issuecomment-1023004215
This commit is contained in:
parent
820642516a
commit
111e39ffe8
@ -64,6 +64,7 @@ import static bisq.daemon.grpc.interceptor.GrpcServiceRateMeteringConfig.getCust
|
|||||||
import static bisq.proto.grpc.GetTradesRequest.Category.CLOSED;
|
import static bisq.proto.grpc.GetTradesRequest.Category.CLOSED;
|
||||||
import static bisq.proto.grpc.GetTradesRequest.Category.OPEN;
|
import static bisq.proto.grpc.GetTradesRequest.Category.OPEN;
|
||||||
import static bisq.proto.grpc.TradesGrpc.*;
|
import static bisq.proto.grpc.TradesGrpc.*;
|
||||||
|
import static java.util.Comparator.comparing;
|
||||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||||
|
|
||||||
@ -303,8 +304,9 @@ class GrpcTradesService extends TradesImplBase {
|
|||||||
|
|
||||||
|
|
||||||
private GetTradesReply buildGetTradesReply(List<TradeModel> trades, GetTradesRequest.Category category) {
|
private GetTradesReply buildGetTradesReply(List<TradeModel> trades, GetTradesRequest.Category category) {
|
||||||
// Build trade history list, starting with closed BsqSwap and v1 trades.
|
// Build an unsorted List<TradeInfo>, starting with
|
||||||
List<TradeInfo> result = trades.stream()
|
// all pending, or all completed BsqSwap and v1 trades.
|
||||||
|
List<TradeInfo> unsortedTrades = trades.stream()
|
||||||
.map(tradeModel -> {
|
.map(tradeModel -> {
|
||||||
var role = coreApi.getTradeRole(tradeModel);
|
var role = coreApi.getTradeRole(tradeModel);
|
||||||
var isMyOffer = coreApi.isMyOffer(tradeModel.getOffer());
|
var isMyOffer = coreApi.isMyOffer(tradeModel.getOffer());
|
||||||
@ -321,7 +323,8 @@ class GrpcTradesService extends TradesImplBase {
|
|||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// Add canceled OpenOffers to returned closed trades list.
|
// If closed trades were requested, add any canceled
|
||||||
|
// OpenOffers (canceled trades) to the unsorted List<TradeInfo>.
|
||||||
Optional<List<OpenOffer>> canceledOpenOffers = category.equals(CLOSED)
|
Optional<List<OpenOffer>> canceledOpenOffers = category.equals(CLOSED)
|
||||||
? Optional.of(coreApi.getCanceledOpenOffers())
|
? Optional.of(coreApi.getCanceledOpenOffers())
|
||||||
: Optional.empty();
|
: Optional.empty();
|
||||||
@ -331,12 +334,15 @@ class GrpcTradesService extends TradesImplBase {
|
|||||||
.map(CanceledTradeInfo::toCanceledTradeInfo)
|
.map(CanceledTradeInfo::toCanceledTradeInfo)
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
));
|
));
|
||||||
|
unsortedTrades.addAll(canceledTrades);
|
||||||
|
|
||||||
|
// Sort the cumulative List<TradeInfo> by date before sending it to the client.
|
||||||
|
List<TradeInfo> sortedTrades = unsortedTrades.stream()
|
||||||
|
.sorted(comparing(TradeInfo::getDate))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
return GetTradesReply.newBuilder()
|
return GetTradesReply.newBuilder()
|
||||||
.addAllTrades(result.stream()
|
.addAllTrades(sortedTrades.stream()
|
||||||
.map(TradeInfo::toProtoMessage)
|
|
||||||
.collect(Collectors.toList()))
|
|
||||||
.addAllTrades(canceledTrades.stream()
|
|
||||||
.map(TradeInfo::toProtoMessage)
|
.map(TradeInfo::toProtoMessage)
|
||||||
.collect(Collectors.toList()))
|
.collect(Collectors.toList()))
|
||||||
.build();
|
.build();
|
||||||
|
Loading…
Reference in New Issue
Block a user