Skip to content

Commit

Permalink
Extract methods for show all and edit entries.
Browse files Browse the repository at this point in the history
Use isShowAllEntry methods instead of equals checks
  • Loading branch information
chimp1984 committed Jan 4, 2021
1 parent 6fc9ad4 commit c3c1f95
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class OfferBookViewModel extends ActivatableViewModel {

// If id is empty string we ignore filter (display all methods)

PaymentMethod selectedPaymentMethod = PaymentMethod.getDummyPaymentMethod(GUIUtil.SHOW_ALL_FLAG);
PaymentMethod selectedPaymentMethod = getShowAllEntryForPaymentMethod();

private boolean isTabSelected;
final BooleanProperty showAllTradeCurrenciesProperty = new SimpleBooleanProperty(true);
Expand Down Expand Up @@ -213,7 +213,7 @@ protected void activate() {
filteredItems.addListener(filterItemsListener);

String code = direction == OfferPayload.Direction.BUY ? preferences.getBuyScreenCurrencyCode() : preferences.getSellScreenCurrencyCode();
if (code != null && !code.equals(GUIUtil.SHOW_ALL_FLAG) && !code.isEmpty() &&
if (code != null && !code.isEmpty() && !isShowAllEntry(code) &&
CurrencyUtil.getTradeCurrency(code).isPresent()) {
showAllTradeCurrenciesProperty.set(false);
selectedTradeCurrency = CurrencyUtil.getTradeCurrency(code).get();
Expand Down Expand Up @@ -288,10 +288,10 @@ void onSetPaymentMethod(PaymentMethod paymentMethod) {
// If we select TransferWise we switch to show all currencies as TransferWise supports
// sending to most currencies.
if (paymentMethod.getId().equals(PaymentMethod.TRANSFERWISE_ID)) {
onSetTradeCurrency(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, ""));
onSetTradeCurrency(getShowAllEntryForCurrency());
}
} else {
this.selectedPaymentMethod = PaymentMethod.getDummyPaymentMethod(GUIUtil.SHOW_ALL_FLAG);
this.selectedPaymentMethod = getShowAllEntryForPaymentMethod();
}

applyFilterPredicate();
Expand Down Expand Up @@ -348,7 +348,7 @@ ObservableList<PaymentMethod> getPaymentMethods() {
}

list.sort(Comparator.naturalOrder());
list.add(0, PaymentMethod.getDummyPaymentMethod(GUIUtil.SHOW_ALL_FLAG));
list.add(0, getShowAllEntryForPaymentMethod());
return list;
}

Expand Down Expand Up @@ -528,11 +528,12 @@ private void setMarketPriceFeedCurrency() {
private void fillAllTradeCurrencies() {
allTradeCurrencies.clear();
// Used for ignoring filter (show all)
allTradeCurrencies.add(new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, ""));
allTradeCurrencies.add(getShowAllEntryForCurrency());
allTradeCurrencies.addAll(preferences.getTradeCurrenciesAsObservable());
allTradeCurrencies.add(new CryptoCurrency(GUIUtil.EDIT_FLAG, ""));
allTradeCurrencies.add(getEditEntryForCurrency());
}


///////////////////////////////////////////////////////////////////////////////////////////
// Checks
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -645,11 +646,11 @@ int getNumTrades(Offer offer) {

public boolean hasSelectionAccountSigning() {
if (showAllTradeCurrenciesProperty.get()) {
if (!selectedPaymentMethod.getId().equals(GUIUtil.SHOW_ALL_FLAG)) {
if (!isShowAllEntry(selectedPaymentMethod.getId())) {
return PaymentMethod.hasChargebackRisk(selectedPaymentMethod);
}
} else {
if (selectedPaymentMethod.getId().equals(GUIUtil.SHOW_ALL_FLAG))
if (isShowAllEntry(selectedPaymentMethod.getId()))
return CurrencyUtil.getMatureMarketCurrencies().stream()
.anyMatch(c -> c.getCode().equals(selectedTradeCurrency.getCode()));
else
Expand All @@ -675,4 +676,16 @@ public String formatDepositString(Coin deposit, long amount) {
var percentage = FormattingUtils.formatToRoundedPercentWithSymbol(deposit.getValue() / (double) amount);
return btcFormatter.formatCoin(deposit) + " (" + percentage + ")";
}

private TradeCurrency getShowAllEntryForCurrency() {
return new CryptoCurrency(GUIUtil.SHOW_ALL_FLAG, "");
}

private TradeCurrency getEditEntryForCurrency() {
return new CryptoCurrency(GUIUtil.EDIT_FLAG, "");
}

private PaymentMethod getShowAllEntryForPaymentMethod() {
return PaymentMethod.getDummyPaymentMethod(GUIUtil.SHOW_ALL_FLAG);
}
}

0 comments on commit c3c1f95

Please sign in to comment.