Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetTrades should not filter open failed trades #7023

Merged
merged 1 commit into from Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/src/main/java/bisq/core/api/model/TradeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public class TradeInfo implements Payload {
private final boolean isCompleted;
private final String contractAsJson;
private final ContractInfo contract;
private final boolean hasFailed;
private final String errorMessage;
// Optional BSQ swap trade protocol details (post v1).
private BsqSwapTradeInfo bsqSwapTradeInfo;
private final String closingStatus;
Expand Down Expand Up @@ -126,6 +128,8 @@ public TradeInfo(TradeInfoV1Builder builder) {
this.contract = builder.getContract();
this.bsqSwapTradeInfo = null;
this.closingStatus = builder.getClosingStatus();
this.hasFailed = builder.isHasFailed();
this.errorMessage = builder.getErrorMessage();
}

public static TradeInfo toNewTradeInfo(BsqSwapTrade trade, String role) {
Expand Down Expand Up @@ -243,6 +247,8 @@ private static TradeInfo toTradeInfo(Trade trade,
.withContractAsJson(trade.getContractAsJson())
.withContract(contractInfo)
.withClosingStatus(closingStatus)
.withHasFailed(trade.hasFailed())
.withErrorMessage(trade.hasErrorMessage() ? trade.getErrorMessage() : "")
.build();
}

Expand Down Expand Up @@ -278,6 +284,8 @@ public bisq.proto.grpc.TradeInfo toProtoMessage() {
.setIsPaymentReceivedMessageSent(isPaymentReceivedMessageSent)
.setIsPayoutPublished(isPayoutPublished)
.setIsCompleted(isCompleted)
.setHasFailed(hasFailed)
.setErrorMessage(errorMessage == null ? "" : errorMessage)
.setClosingStatus(closingStatus);
if (offer.isBsqSwapOffer()) {
protoBuilder.setBsqSwapTradeInfo(bsqSwapTradeInfo.toProtoMessage());
Expand Down Expand Up @@ -318,6 +326,8 @@ public static TradeInfo fromProto(bisq.proto.grpc.TradeInfo proto) {
.withContractAsJson(proto.getContractAsJson())
.withContract((ContractInfo.fromProto(proto.getContract())))
.withClosingStatus(proto.getClosingStatus())
.withHasFailed(proto.getHasFailed())
.withErrorMessage(proto.getErrorMessage())
.build();

if (proto.getOffer().getIsBsqSwapOffer())
Expand Down Expand Up @@ -357,6 +367,8 @@ public String toString() {
", contract=" + contract + "\n" +
", bsqSwapTradeInfo=" + bsqSwapTradeInfo + "\n" +
", closingStatus=" + closingStatus + "\n" +
", hasFailed=" + hasFailed + "\n" +
", errorMessage=" + errorMessage + "\n" +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ public final class TradeInfoV1Builder {
private boolean isPaymentReceivedMessageSent;
private boolean isPayoutPublished;
private boolean isCompleted;
private boolean hasFailed;
private String contractAsJson;
private ContractInfo contract;
private String closingStatus;
private String errorMessage;

public TradeInfoV1Builder withOffer(OfferInfo offer) {
this.offer = offer;
Expand Down Expand Up @@ -180,6 +182,16 @@ public TradeInfoV1Builder withIsCompleted(boolean isCompleted) {
return this;
}

public TradeInfoV1Builder withHasFailed(boolean hasFailed) {
this.hasFailed = hasFailed;
return this;
}

public TradeInfoV1Builder withErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
return this;
}

public TradeInfoV1Builder withContractAsJson(String contractAsJson) {
this.contractAsJson = contractAsJson;
return this;
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/bisq/core/trade/TradeManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@

import org.bouncycastle.crypto.params.KeyParameter;

import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -911,9 +912,7 @@ public Optional<Trade> getTradeById(String tradeId) {
}

public List<Trade> getTrades() {
return getObservableList().stream()
.filter(t -> !t.hasFailed())
.collect(Collectors.toList());
return Collections.unmodifiableList(getObservableList());
}

private void removeTrade(Trade trade) {
Expand Down
4 changes: 4 additions & 0 deletions proto/src/main/proto/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,10 @@ message TradeInfo {
BsqSwapTradeInfo bsq_swap_trade_info = 28;
// Needed by open/closed/failed trade list items.
string closing_status = 29;
// Whether the trade failed.
bool has_failed = 30;
// Error message applicable when trade is failed.
string error_message = 31;
}

message ContractInfo {
Expand Down