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 Nov 19, 2019
1 parent dc74198 commit cfaa23e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
32 changes: 0 additions & 32 deletions core/src/main/java/bisq/core/util/BSFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,42 +104,10 @@ 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 getDateFromBlockHeight(long blockHeight) {
long now = new Date().getTime();
SimpleDateFormat dateFormatter = new SimpleDateFormat("dd MMM", Locale.getDefault());
SimpleDateFormat timeFormatter = new SimpleDateFormat("HH:mm", Locale.getDefault());
return FormattingUtils.formatDateTime(new Date(now + blockHeight * 10 * 60 * 1000L), dateFormatter, timeFormatter);
}

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 @@ -478,7 +478,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 @@ -636,4 +636,11 @@ public String getMakerFeeAsString(Offer offer) {
btcFormatter.formatCoinWithCode(offer.getMakerFee()) :
bsqFormatter.formatCoinWithCode(offer.getMakerFee());
}

private 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,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 @@ -482,4 +482,29 @@ private void onTradeStateChanged(Trade.State tradeState) {
break;
}
}

private 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"));
}

}

}

0 comments on commit cfaa23e

Please sign in to comment.