set trade role from utility class in api #1146

This commit is contained in:
woodser 2024-07-17 17:27:07 -04:00
parent caaf9f7b5b
commit 7308206a10
4 changed files with 5 additions and 12 deletions

View File

@ -561,10 +561,6 @@ public class CoreApi {
return coreTradesService.getTrades(); return coreTradesService.getTrades();
} }
public String getTradeRole(String tradeId) {
return coreTradesService.getTradeRole(tradeId);
}
public List<ChatMessage> getChatMessages(String tradeId) { public List<ChatMessage> getChatMessages(String tradeId) {
return coreTradesService.getChatMessages(tradeId); return coreTradesService.getChatMessages(tradeId);
} }

View File

@ -21,6 +21,7 @@ import haveno.common.Payload;
import haveno.core.api.model.builder.TradeInfoV1Builder; import haveno.core.api.model.builder.TradeInfoV1Builder;
import haveno.core.trade.Contract; import haveno.core.trade.Contract;
import haveno.core.trade.Trade; import haveno.core.trade.Trade;
import haveno.core.trade.TradeUtil;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
@ -142,10 +143,7 @@ public class TradeInfo implements Payload {
} }
public static TradeInfo toTradeInfo(Trade trade) { public static TradeInfo toTradeInfo(Trade trade) {
return toTradeInfo(trade, null); String role = TradeUtil.getRole(trade);
}
public static TradeInfo toTradeInfo(Trade trade, String role) {
ContractInfo contractInfo; ContractInfo contractInfo;
if (trade.getContract() != null) { if (trade.getContract() != null) {
Contract contract = trade.getContract(); Contract contract = trade.getContract();

View File

@ -172,7 +172,7 @@ public class TradeUtil {
* @param trade Trade * @param trade Trade
* @return String describing a trader's role for a given trade * @return String describing a trader's role for a given trade
*/ */
public String getRole(Trade trade) { public static String getRole(Trade trade) {
Offer offer = trade.getOffer(); Offer offer = trade.getOffer();
if (offer == null) if (offer == null)
throw new IllegalStateException(format("could not get role because no offer was found for trade '%s'", throw new IllegalStateException(format("could not get role because no offer was found for trade '%s'",
@ -191,7 +191,7 @@ public class TradeUtil {
* @param currencyCode String * @param currencyCode String
* @return String describing a trader's role * @return String describing a trader's role
*/ */
public String getRole(boolean isBuyerMakerAndSellerTaker, boolean isMaker, String currencyCode) { private static String getRole(boolean isBuyerMakerAndSellerTaker, boolean isMaker, String currencyCode) {
if (isTraditionalCurrency(currencyCode)) { if (isTraditionalCurrency(currencyCode)) {
String baseCurrencyCode = Res.getBaseCurrencyCode(); String baseCurrencyCode = Res.getBaseCurrencyCode();
if (isBuyerMakerAndSellerTaker) if (isBuyerMakerAndSellerTaker)

View File

@ -96,9 +96,8 @@ class GrpcTradesService extends TradesImplBase {
StreamObserver<GetTradeReply> responseObserver) { StreamObserver<GetTradeReply> responseObserver) {
try { try {
Trade trade = coreApi.getTrade(req.getTradeId()); Trade trade = coreApi.getTrade(req.getTradeId());
String role = coreApi.getTradeRole(req.getTradeId());
var reply = GetTradeReply.newBuilder() var reply = GetTradeReply.newBuilder()
.setTrade(toTradeInfo(trade, role).toProtoMessage()) .setTrade(toTradeInfo(trade).toProtoMessage())
.build(); .build();
responseObserver.onNext(reply); responseObserver.onNext(reply);
responseObserver.onCompleted(); responseObserver.onCompleted();