Skip to content

Commit

Permalink
Merge pull request #5045 from chimp1984/add-option-to-hide-non-suppor…
Browse files Browse the repository at this point in the history
…ted-payment-methods

Add option to hide non supported payment methods
  • Loading branch information
sqrrm authored Jan 4, 2021
2 parents 4127f75 + eddb7cb commit 7bc9c10
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 6 deletions.
7 changes: 7 additions & 0 deletions core/src/main/java/bisq/core/user/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ public void setAutoConfTradeLimit(String currencyCode, long tradeLimit) {
});
}

public void setHideNonAccountPaymentMethods(boolean hideNonAccountPaymentMethods) {
prefPayload.setHideNonAccountPaymentMethods(hideNonAccountPaymentMethods);
requestPersistence();
}

private void requestPersistence() {
if (initialReadDone)
persistenceManager.requestPersistence();
Expand Down Expand Up @@ -1074,5 +1079,7 @@ private interface ExcludesDelegateMethods {
void setBsqAverageTrimThreshold(double bsqAverageTrimThreshold);

void setAutoConfirmSettings(AutoConfirmSettings autoConfirmSettings);

void setHideNonAccountPaymentMethods(boolean hideNonAccountPaymentMethods);
}
}
8 changes: 6 additions & 2 deletions core/src/main/java/bisq/core/user/PreferencesPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public final class PreferencesPayload implements PersistableEnvelope {
// Added at 1.3.8
private List<AutoConfirmSettings> autoConfirmSettingsList = new ArrayList<>();

// Added in 1.5.5
private boolean hideNonAccountPaymentMethods;

///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
Expand Down Expand Up @@ -192,7 +194,8 @@ public Message toProtoMessage() {
.setBsqAverageTrimThreshold(bsqAverageTrimThreshold)
.addAllAutoConfirmSettings(autoConfirmSettingsList.stream()
.map(autoConfirmSettings -> ((protobuf.AutoConfirmSettings) autoConfirmSettings.toProtoMessage()))
.collect(Collectors.toList()));
.collect(Collectors.toList()))
.setHideNonAccountPaymentMethods(hideNonAccountPaymentMethods);

Optional.ofNullable(backupDirectory).ifPresent(builder::setBackupDirectory);
Optional.ofNullable(preferredTradeCurrency).ifPresent(e -> builder.setPreferredTradeCurrency((protobuf.TradeCurrency) e.toProtoMessage()));
Expand Down Expand Up @@ -286,7 +289,8 @@ public static PreferencesPayload fromProto(protobuf.PreferencesPayload proto, Co
proto.getAutoConfirmSettingsList().isEmpty() ? new ArrayList<>() :
new ArrayList<>(proto.getAutoConfirmSettingsList().stream()
.map(AutoConfirmSettings::fromProto)
.collect(Collectors.toList()))
.collect(Collectors.toList())),
proto.getHideNonAccountPaymentMethods()
);
}
}
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,7 @@ setting.preferences.showOwnOffers=Show my own offers in offer book
setting.preferences.useAnimations=Use animations
setting.preferences.useDarkMode=Use dark mode
setting.preferences.sortWithNumOffers=Sort market lists with no. of offers/trades
setting.preferences.onlyShowPaymentMethodsFromAccount=Hide non-supported payment methods
setting.preferences.resetAllFlags=Reset all \"Don't show again\" flags
settings.preferences.languageChange=To apply the language change to all screens requires a restart.
settings.preferences.supportLanguageWarning=In case of a dispute, please note that mediation is handled in {0} and arbitration in {1}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -338,6 +339,14 @@ TradeCurrency getSelectedTradeCurrency() {

ObservableList<PaymentMethod> getPaymentMethods() {
ObservableList<PaymentMethod> list = FXCollections.observableArrayList(PaymentMethod.getPaymentMethods());
if (preferences.isHideNonAccountPaymentMethods() && user.getPaymentAccounts() != null) {
Set<PaymentMethod> supportedPaymentMethods = user.getPaymentAccounts().stream()
.map(PaymentAccount::getPaymentMethod).collect(Collectors.toSet());
if (!supportedPaymentMethods.isEmpty()) {
list = FXCollections.observableArrayList(supportedPaymentMethods);
}
}

list.sort(Comparator.naturalOrder());
list.add(0, PaymentMethod.getDummyPaymentMethod(GUIUtil.SHOW_ALL_FLAG));
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@
import bisq.core.locale.LanguageUtil;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.provider.fee.FeeService;
import bisq.core.user.Preferences;
import bisq.core.user.User;
import bisq.core.util.FormattingUtils;
import bisq.core.util.ParsingUtils;
import bisq.core.util.coin.CoinFormatter;
Expand Down Expand Up @@ -100,21 +103,24 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static bisq.desktop.util.FormBuilder.*;
import static com.google.common.base.Preconditions.checkArgument;

@FxmlView
public class PreferencesView extends ActivatableViewAndModel<GridPane, PreferencesViewModel> {
private final User user;
private final CoinFormatter formatter;
private TextField btcExplorerTextField, bsqExplorerTextField;
private ComboBox<String> userLanguageComboBox;
private ComboBox<Country> userCountryComboBox;
private ComboBox<TradeCurrency> preferredTradeCurrencyComboBox;

private ToggleButton showOwnOffersInOfferBook, useAnimations, useDarkMode, sortMarketCurrenciesNumerically,
avoidStandbyMode, useCustomFee, autoConfirmXmrToggle;
avoidStandbyMode, useCustomFee, autoConfirmXmrToggle, hideNonAccountPaymentMethodsToggle;
private int gridRow = 0;
private int displayCurrenciesGridRowIndex = 0;
private InputTextField transactionFeeInputTextField, ignoreTradersListInputTextField, ignoreDustThresholdInputTextField,
Expand Down Expand Up @@ -171,12 +177,14 @@ public PreferencesView(PreferencesViewModel model,
FilterManager filterManager,
DaoFacade daoFacade,
Config config,
User user,
@Named(FormattingUtils.BTC_FORMATTER_KEY) CoinFormatter formatter,
@Named(Config.RPC_USER) String rpcUser,
@Named(Config.RPC_PASSWORD) String rpcPassword,
@Named(Config.RPC_BLOCK_NOTIFICATION_PORT) int rpcBlockNotificationPort,
@Named(Config.STORAGE_DIR) File storageDir) {
super(model);
this.user = user;
this.formatter = formatter;
this.preferences = preferences;
this.feeService = feeService;
Expand Down Expand Up @@ -595,14 +603,14 @@ public CryptoCurrency fromString(String s) {
}

private void initializeDisplayOptions() {
TitledGroupBg titledGroupBg = addTitledGroupBg(root, ++gridRow, 5, Res.get("setting.preferences.displayOptions"), Layout.GROUP_DISTANCE);
TitledGroupBg titledGroupBg = addTitledGroupBg(root, ++gridRow, 6, Res.get("setting.preferences.displayOptions"), Layout.GROUP_DISTANCE);
GridPane.setColumnSpan(titledGroupBg, 1);

showOwnOffersInOfferBook = addSlideToggleButton(root, gridRow, Res.get("setting.preferences.showOwnOffers"), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
useAnimations = addSlideToggleButton(root, ++gridRow, Res.get("setting.preferences.useAnimations"));
useDarkMode = addSlideToggleButton(root, ++gridRow, Res.get("setting.preferences.useDarkMode"));
// useStickyMarketPriceCheckBox = addLabelCheckBox(root, ++gridRow, "Use sticky market price:", "").second;
sortMarketCurrenciesNumerically = addSlideToggleButton(root, ++gridRow, Res.get("setting.preferences.sortWithNumOffers"));
hideNonAccountPaymentMethodsToggle = addSlideToggleButton(root, ++gridRow, Res.get("setting.preferences.onlyShowPaymentMethodsFromAccount"));
resetDontShowAgainButton = addButton(root, ++gridRow, Res.get("setting.preferences.resetAllFlags"), 0);
resetDontShowAgainButton.getStyleClass().add("compact-button");
resetDontShowAgainButton.setMaxWidth(Double.MAX_VALUE);
Expand Down Expand Up @@ -932,6 +940,16 @@ private void activateDisplayPreferences() {
sortMarketCurrenciesNumerically.setSelected(preferences.isSortMarketCurrenciesNumerically());
sortMarketCurrenciesNumerically.setOnAction(e -> preferences.setSortMarketCurrenciesNumerically(sortMarketCurrenciesNumerically.isSelected()));

boolean disableToggle = false;
if (user.getPaymentAccounts() != null) {
Set<PaymentMethod> supportedPaymentMethods = user.getPaymentAccounts().stream()
.map(PaymentAccount::getPaymentMethod).collect(Collectors.toSet());
disableToggle = supportedPaymentMethods.isEmpty();
}
hideNonAccountPaymentMethodsToggle.setSelected(preferences.isHideNonAccountPaymentMethods() && !disableToggle);
hideNonAccountPaymentMethodsToggle.setOnAction(e -> preferences.setHideNonAccountPaymentMethods(hideNonAccountPaymentMethodsToggle.isSelected()));
hideNonAccountPaymentMethodsToggle.setDisable(disableToggle);

resetDontShowAgainButton.setOnAction(e -> preferences.resetDontShowAgain());

editCustomBtcExplorer.setOnAction(e -> {
Expand Down Expand Up @@ -1108,8 +1126,8 @@ private void deactivateDisplayCurrencies() {
private void deactivateDisplayPreferences() {
useAnimations.setOnAction(null);
useDarkMode.setOnAction(null);
// useStickyMarketPriceCheckBox.setOnAction(null);
sortMarketCurrenciesNumerically.setOnAction(null);
hideNonAccountPaymentMethodsToggle.setOnAction(null);
showOwnOffersInOfferBook.setOnAction(null);
resetDontShowAgainButton.setOnAction(null);
if (displayStandbyModeFeature) {
Expand Down
1 change: 1 addition & 0 deletions proto/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,7 @@ message PreferencesPayload {
bool tac_accepted_v120 = 55;
repeated AutoConfirmSettings auto_confirm_settings = 56;
double bsq_average_trim_threshold = 57;
bool hide_non_account_payment_methods = 58;
}

message AutoConfirmSettings {
Expand Down

0 comments on commit 7bc9c10

Please sign in to comment.