Skip to content

Commit

Permalink
Move functions that only have 1 call-site out of BSFormatter
Browse files Browse the repository at this point in the history
Make them private instance functions at call site to minimize
dependencies.
  • Loading branch information
Justin Carter committed Sep 18, 2019
1 parent 13fca56 commit 3ca10fd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
35 changes: 0 additions & 35 deletions core/src/main/java/bisq/core/util/BSFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,39 +103,4 @@ public String formatCoinWithCode(long value) {
return FormattingUtils.formatCoinWithCode(Coin.valueOf(value), monetaryFormat);
}

public static String getDirectionWithCodeDetailed(OfferPayload.Direction direction, String currencyCode) {
if (CurrencyUtil.isFiatCurrency(currencyCode))
return (direction == OfferPayload.Direction.BUY) ? Res.get("shared.buyingBTCWith", currencyCode) : Res.get("shared.sellingBTCFor", currencyCode);
else
return (direction == OfferPayload.Direction.SELL) ? Res.get("shared.buyingCurrency", currencyCode) : Res.get("shared.sellingCurrency", currencyCode);
}

public static String arbitratorAddressesToString(List<NodeAddress> nodeAddresses) {
return nodeAddresses.stream().map(NodeAddress::getFullAddress).collect(Collectors.joining(", "));
}

public static String getRole(boolean isBuyerMakerAndSellerTaker, boolean isMaker, String currencyCode) {
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
String baseCurrencyCode = Res.getBaseCurrencyCode();
if (isBuyerMakerAndSellerTaker)
return isMaker ?
Res.get("formatter.asMaker", baseCurrencyCode, Res.get("shared.buyer")) :
Res.get("formatter.asTaker", baseCurrencyCode, Res.get("shared.seller"));
else
return isMaker ?
Res.get("formatter.asMaker", baseCurrencyCode, Res.get("shared.seller")) :
Res.get("formatter.asTaker", baseCurrencyCode, Res.get("shared.buyer"));
} else {
if (isBuyerMakerAndSellerTaker)
return isMaker ?
Res.get("formatter.asMaker", currencyCode, Res.get("shared.seller")) :
Res.get("formatter.asTaker", currencyCode, Res.get("shared.buyer"));
else
return isMaker ?
Res.get("formatter.asMaker", currencyCode, Res.get("shared.buyer")) :
Res.get("formatter.asTaker", currencyCode, Res.get("shared.seller"));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ private boolean isF2F(Offer offer) {
}

String getDirectionLabelTooltip(Offer offer) {
return BSFormatter.getDirectionWithCodeDetailed(offer.getMirroredDirection(), offer.getCurrencyCode());
return getDirectionWithCodeDetailed(offer.getMirroredDirection(), offer.getCurrencyCode());
}

Optional<PaymentAccount> getMostMaturePaymentAccountForOffer(Offer offer) {
Expand Down Expand Up @@ -617,4 +617,11 @@ int getNumTrades(Offer offer) {
.collect(Collectors.toSet())
.size();
}

private String getDirectionWithCodeDetailed(OfferPayload.Direction direction, String currencyCode) {
if (CurrencyUtil.isFiatCurrency(currencyCode))
return (direction == OfferPayload.Direction.BUY) ? Res.get("shared.buyingBTCWith", currencyCode) : Res.get("shared.sellingBTCFor", currencyCode);
else
return (direction == OfferPayload.Direction.SELL) ? Res.get("shared.buyingCurrency", currencyCode) : Res.get("shared.sellingCurrency", currencyCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import bisq.core.util.BSFormatter;
import bisq.core.util.FormattingUtils;

import bisq.network.p2p.NodeAddress;

import bisq.common.crypto.KeyRing;
import bisq.common.util.Tuple2;
import bisq.common.util.Tuple4;
Expand All @@ -60,6 +62,7 @@

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -407,4 +410,8 @@ private void addConfirmAndCancelButtons(boolean isPlaceOffer) {
}
});
}

private String arbitratorAddressesToString(List<NodeAddress> nodeAddresses) {
return nodeAddresses.stream().map(NodeAddress::getFullAddress).collect(Collectors.joining(", "));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ String getMyRole(PendingTradesListItem item) {
Contract contract = trade.getContract();
if (contract != null) {
Offer offer = trade.getOffer();
return BSFormatter.getRole(contract.isBuyerMakerAndSellerTaker(), dataModel.isMaker(offer), offer.getCurrencyCode());
return getRole(contract.isBuyerMakerAndSellerTaker(), dataModel.isMaker(offer), offer.getCurrencyCode());
} else {
return "";
}
Expand Down Expand Up @@ -458,4 +458,28 @@ private void onTradeStateChanged(Trade.State tradeState) {
break;
}
}

private String getRole(boolean isBuyerMakerAndSellerTaker, boolean isMaker, String currencyCode) {
if (CurrencyUtil.isFiatCurrency(currencyCode)) {
String baseCurrencyCode = Res.getBaseCurrencyCode();
if (isBuyerMakerAndSellerTaker)
return isMaker ?
Res.get("formatter.asMaker", baseCurrencyCode, Res.get("shared.buyer")) :
Res.get("formatter.asTaker", baseCurrencyCode, Res.get("shared.seller"));
else
return isMaker ?
Res.get("formatter.asMaker", baseCurrencyCode, Res.get("shared.seller")) :
Res.get("formatter.asTaker", baseCurrencyCode, Res.get("shared.buyer"));
} else {
if (isBuyerMakerAndSellerTaker)
return isMaker ?
Res.get("formatter.asMaker", currencyCode, Res.get("shared.seller")) :
Res.get("formatter.asTaker", currencyCode, Res.get("shared.buyer"));
else
return isMaker ?
Res.get("formatter.asMaker", currencyCode, Res.get("shared.buyer")) :
Res.get("formatter.asTaker", currencyCode, Res.get("shared.seller"));
}

}
}

0 comments on commit 3ca10fd

Please sign in to comment.