Skip to content

Commit

Permalink
set trade role from utility class in api #1146
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jul 18, 2024
1 parent caaf9f7 commit 7308206
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
4 changes: 0 additions & 4 deletions core/src/main/java/haveno/core/api/CoreApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,6 @@ public List<Trade> getTrades() {
return coreTradesService.getTrades();
}

public String getTradeRole(String tradeId) {
return coreTradesService.getTradeRole(tradeId);
}

public List<ChatMessage> getChatMessages(String tradeId) {
return coreTradesService.getChatMessages(tradeId);
}
Expand Down
6 changes: 2 additions & 4 deletions core/src/main/java/haveno/core/api/model/TradeInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import haveno.core.api.model.builder.TradeInfoV1Builder;
import haveno.core.trade.Contract;
import haveno.core.trade.Trade;
import haveno.core.trade.TradeUtil;
import lombok.EqualsAndHashCode;
import lombok.Getter;

Expand Down Expand Up @@ -142,10 +143,7 @@ public TradeInfo(TradeInfoV1Builder builder) {
}

public static TradeInfo toTradeInfo(Trade trade) {
return toTradeInfo(trade, null);
}

public static TradeInfo toTradeInfo(Trade trade, String role) {
String role = TradeUtil.getRole(trade);
ContractInfo contractInfo;
if (trade.getContract() != null) {
Contract contract = trade.getContract();
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/haveno/core/trade/TradeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public String getPaymentMethodNameWithCountryCode(Trade trade) {
* @param trade 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();
if (offer == null)
throw new IllegalStateException(format("could not get role because no offer was found for trade '%s'",
Expand All @@ -191,7 +191,7 @@ public String getRole(Trade trade) {
* @param currencyCode String
* @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)) {
String baseCurrencyCode = Res.getBaseCurrencyCode();
if (isBuyerMakerAndSellerTaker)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ public void getTrade(GetTradeRequest req,
StreamObserver<GetTradeReply> responseObserver) {
try {
Trade trade = coreApi.getTrade(req.getTradeId());
String role = coreApi.getTradeRole(req.getTradeId());
var reply = GetTradeReply.newBuilder()
.setTrade(toTradeInfo(trade, role).toProtoMessage())
.setTrade(toTradeInfo(trade).toProtoMessage())
.build();
responseObserver.onNext(reply);
responseObserver.onCompleted();
Expand Down

0 comments on commit 7308206

Please sign in to comment.