Search in sources :

Example 6 with Country

use of bisq.core.locale.Country in project bisq-desktop by bisq-network.

the class PreferencesView method activateGeneralOptions.

// /////////////////////////////////////////////////////////////////////////////////////////
// Activate
// /////////////////////////////////////////////////////////////////////////////////////////
private void activateGeneralOptions() {
    List<BaseCurrencyNetwork> baseCurrencyNetworks = Arrays.asList(BaseCurrencyNetwork.values());
    // show ony mainnet in production version
    if (!DevEnv.isDevMode())
        baseCurrencyNetworks = baseCurrencyNetworks.stream().filter(e -> !e.isDash()).filter(BaseCurrencyNetwork::isMainnet).collect(Collectors.toList());
    selectBaseCurrencyNetworkComboBox.setItems(FXCollections.observableArrayList(baseCurrencyNetworks));
    selectBaseCurrencyNetworkComboBox.setOnAction(e -> onSelectNetwork());
    selectBaseCurrencyNetworkComboBox.getSelectionModel().select(BisqEnvironment.getBaseCurrencyNetwork());
    boolean useCustomWithdrawalTxFee = preferences.isUseCustomWithdrawalTxFee();
    useCustomFeeCheckbox.setSelected(useCustomWithdrawalTxFee);
    transactionFeeInputTextField.setEditable(useCustomWithdrawalTxFee);
    if (!useCustomWithdrawalTxFee) {
        transactionFeeInputTextField.setText(String.valueOf(feeService.getTxFeePerByte().value));
        feeService.feeUpdateCounterProperty().addListener(transactionFeeChangeListener);
    }
    transactionFeeInputTextField.setText(String.valueOf(getTxFeeForWithdrawalPerByte()));
    ignoreTradersListInputTextField.setText(preferences.getIgnoreTradersList().stream().collect(Collectors.joining(", ")));
    userLanguageComboBox.setItems(languageCodes);
    userLanguageComboBox.getSelectionModel().select(preferences.getUserLanguage());
    userLanguageComboBox.setConverter(new StringConverter<String>() {

        @Override
        public String toString(String code) {
            return LanguageUtil.getDisplayName(code);
        }

        @Override
        public String fromString(String string) {
            return null;
        }
    });
    userLanguageComboBox.setOnAction(e -> {
        String selectedItem = userLanguageComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            preferences.setUserLanguage(selectedItem);
            new Popup<>().information(Res.get("settings.preferences.languageChange")).closeButtonText(Res.get("shared.ok")).show();
        }
    // Should we apply the changed currency immediately to the language list?
    // If so and the user selects a unknown language he might get lost and it is hard to find
    // again the language he understands
    /* if (selectedItem != null && !selectedItem.equals(preferences.getUserLanguage())) {
                preferences.setUserLanguage(selectedItem);
                UserThread.execute(() -> {
                    languageCodes.clear();
                    languageCodes.addAll(LanguageUtil.getAllLanguageCodes());
                    userLanguageComboBox.getSelectionModel().select(preferences.getUserLanguage());
                });
            }*/
    });
    userCountryComboBox.setItems(countries);
    userCountryComboBox.getSelectionModel().select(preferences.getUserCountry());
    userCountryComboBox.setConverter(new StringConverter<Country>() {

        @Override
        public String toString(Country country) {
            return CountryUtil.getNameByCode(country.code);
        }

        @Override
        public Country fromString(String string) {
            return null;
        }
    });
    userCountryComboBox.setOnAction(e -> {
        Country country = userCountryComboBox.getSelectionModel().getSelectedItem();
        if (country != null) {
            preferences.setUserCountry(country);
        }
    });
    blockChainExplorerComboBox.setItems(blockExplorers);
    blockChainExplorerComboBox.getSelectionModel().select(preferences.getBlockChainExplorer());
    blockChainExplorerComboBox.setConverter(new StringConverter<BlockChainExplorer>() {

        @Override
        public String toString(BlockChainExplorer blockChainExplorer) {
            return blockChainExplorer.name;
        }

        @Override
        public BlockChainExplorer fromString(String string) {
            return null;
        }
    });
    blockChainExplorerComboBox.setOnAction(e -> preferences.setBlockChainExplorer(blockChainExplorerComboBox.getSelectionModel().getSelectedItem()));
    deviationInputTextField.setText(formatter.formatPercentagePrice(preferences.getMaxPriceDistanceInPercent()));
    deviationInputTextField.textProperty().addListener(deviationListener);
    deviationInputTextField.focusedProperty().addListener(deviationFocusedListener);
    transactionFeeInputTextField.focusedProperty().addListener(transactionFeeFocusedListener);
    ignoreTradersListInputTextField.textProperty().addListener(ignoreTradersListListener);
    useCustomFeeCheckbox.selectedProperty().addListener(useCustomFeeCheckboxListener);
}
Also used : BaseCurrencyNetwork(bisq.core.btc.BaseCurrencyNetwork) Country(bisq.core.locale.Country) BlockChainExplorer(bisq.core.user.BlockChainExplorer)

Example 7 with Country

use of bisq.core.locale.Country in project bisq-desktop by bisq-network.

the class OfferBookViewModelTest method getSameBankAccount.

private PaymentAccount getSameBankAccount(String currencyCode, String countryCode, String bankId) {
    SameBankAccount paymentAccount = new SameBankAccount();
    paymentAccount.setSingleTradeCurrency(new FiatCurrency(currencyCode));
    paymentAccount.setCountry(new Country(countryCode, null, null));
    ((SameBankAccountPayload) paymentAccount.getPaymentAccountPayload()).setBankId(bankId);
    return paymentAccount;
}
Also used : SameBankAccount(bisq.core.payment.SameBankAccount) Country(bisq.core.locale.Country) SameBankAccountPayload(bisq.core.payment.payload.SameBankAccountPayload) FiatCurrency(bisq.core.locale.FiatCurrency)

Example 8 with Country

use of bisq.core.locale.Country in project bisq-desktop by bisq-network.

the class WesternUnionForm method addFormForAddAccount.

@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;
    Tuple3<Label, ComboBox, ComboBox> tuple3 = FormBuilder.addLabelComboBoxComboBox(gridPane, ++gridRow, Res.get("payment.country"));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Region> regionComboBox = tuple3.second;
    regionComboBox.setPromptText(Res.get("payment.select.region"));
    regionComboBox.setConverter(new StringConverter<Region>() {

        @Override
        public String toString(Region region) {
            return region.name;
        }

        @Override
        public Region fromString(String s) {
            return null;
        }
    });
    regionComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllRegions()));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Country> countryComboBox = tuple3.third;
    countryComboBox.setVisibleRowCount(15);
    countryComboBox.setDisable(true);
    countryComboBox.setPromptText(Res.get("payment.select.country"));
    countryComboBox.setConverter(new StringConverter<Country>() {

        @Override
        public String toString(Country country) {
            return country.name + " (" + country.code + ")";
        }

        @Override
        public Country fromString(String s) {
            return null;
        }
    });
    countryComboBox.setOnAction(e -> {
        Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            getCountryBasedPaymentAccount().setCountry(selectedItem);
            String countryCode = selectedItem.code;
            TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(countryCode);
            paymentAccount.setSingleTradeCurrency(currency);
            currencyComboBox.setDisable(false);
            currencyComboBox.getSelectionModel().select(currency);
            updateFromInputs();
            applyIsStateRequired();
            cityInputTextField.setText("");
            stateInputTextField.setText("");
        }
    });
    regionComboBox.setOnAction(e -> {
        Region selectedItem = regionComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            countryComboBox.setDisable(false);
            countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllCountriesForRegion(selectedItem)));
        }
    });
    // noinspection unchecked
    currencyComboBox = FormBuilder.addLabelComboBox(gridPane, ++gridRow, Res.getWithCol("shared.currency")).second;
    currencyComboBox.setPromptText(Res.get("list.currency.select"));
    currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getAllSortedFiatCurrencies()));
    currencyComboBox.setOnAction(e -> {
        TradeCurrency selectedItem = currencyComboBox.getSelectionModel().getSelectedItem();
        FiatCurrency defaultCurrency = CurrencyUtil.getCurrencyByCountryCode(countryComboBox.getSelectionModel().getSelectedItem().code);
        if (!defaultCurrency.equals(selectedItem)) {
            new Popup<>().warning(Res.get("payment.foreign.currency")).actionButtonText(Res.get("shared.yes")).onAction(() -> {
                paymentAccount.setSingleTradeCurrency(selectedItem);
                autoFillNameTextField();
            }).closeButtonText(Res.get("payment.restore.default")).onClose(() -> currencyComboBox.getSelectionModel().select(defaultCurrency)).show();
        } else {
            paymentAccount.setSingleTradeCurrency(selectedItem);
            autoFillNameTextField();
        }
    });
    currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {

        @Override
        public String toString(TradeCurrency currency) {
            return currency.getNameAndCode();
        }

        @Override
        public TradeCurrency fromString(String string) {
            return null;
        }
    });
    currencyComboBox.setDisable(true);
    holderNameInputTextField = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, Res.getWithCol("payment.account.fullName")).second;
    holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        westernUnionAccountPayload.setHolderName(newValue);
        updateFromInputs();
    });
    holderNameInputTextField.setValidator(inputValidator);
    cityInputTextField = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.account.city")).second;
    cityInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        westernUnionAccountPayload.setCity(newValue);
        updateFromInputs();
    });
    final Tuple2<Label, InputTextField> tuple2 = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.account.state"));
    stateLabel = tuple2.first;
    stateInputTextField = tuple2.second;
    stateInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        westernUnionAccountPayload.setState(newValue);
        updateFromInputs();
    });
    applyIsStateRequired();
    emailInputTextField = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.email")).second;
    emailInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        westernUnionAccountPayload.setEmail(newValue);
        updateFromInputs();
    });
    emailInputTextField.setValidator(emailValidator);
    addLimitations();
    addAccountNameTextFieldWithAutoFillCheckBox();
    updateFromInputs();
}
Also used : TradeCurrency(bisq.core.locale.TradeCurrency) ComboBox(javafx.scene.control.ComboBox) InputTextField(bisq.desktop.components.InputTextField) Label(javafx.scene.control.Label) Popup(bisq.desktop.main.overlays.popups.Popup) Region(bisq.core.locale.Region) Country(bisq.core.locale.Country) FiatCurrency(bisq.core.locale.FiatCurrency)

Example 9 with Country

use of bisq.core.locale.Country in project bisq-desktop by bisq-network.

the class BankForm method addFormForAddAccount.

@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;
    Tuple3<Label, ComboBox, ComboBox> tuple3 = addLabelComboBoxComboBox(gridPane, ++gridRow, Res.get("payment.country"));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Region> regionComboBox = tuple3.second;
    regionComboBox.setPromptText(Res.get("payment.select.region"));
    regionComboBox.setConverter(new StringConverter<Region>() {

        @Override
        public String toString(Region region) {
            return region.name;
        }

        @Override
        public Region fromString(String s) {
            return null;
        }
    });
    regionComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllRegions()));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Country> countryComboBox = tuple3.third;
    countryComboBox.setVisibleRowCount(15);
    countryComboBox.setDisable(true);
    countryComboBox.setPromptText(Res.get("payment.select.country"));
    countryComboBox.setConverter(new StringConverter<Country>() {

        @Override
        public String toString(Country country) {
            return country.name + " (" + country.code + ")";
        }

        @Override
        public Country fromString(String s) {
            return null;
        }
    });
    countryComboBox.setOnAction(e -> {
        Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            getCountryBasedPaymentAccount().setCountry(selectedItem);
            String countryCode = selectedItem.code;
            TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(countryCode);
            paymentAccount.setSingleTradeCurrency(currency);
            currencyComboBox.setDisable(false);
            currencyComboBox.getSelectionModel().select(currency);
            bankIdLabel.setText(BankUtil.getBankIdLabel(countryCode));
            branchIdLabel.setText(BankUtil.getBranchIdLabel(countryCode));
            accountNrLabel.setText(BankUtil.getAccountNrLabel(countryCode));
            accountTypeLabel.setText(BankUtil.getAccountTypeLabel(countryCode));
            bankNameInputTextField.setText("");
            bankIdInputTextField.setText("");
            branchIdInputTextField.setText("");
            accountNrInputTextField.setText("");
            accountTypeComboBox.getSelectionModel().clearSelection();
            accountTypeComboBox.setItems(FXCollections.observableArrayList(BankUtil.getAccountTypeValues(countryCode)));
            if (BankUtil.useValidation(countryCode) && !validatorsApplied) {
                validatorsApplied = true;
                if (useHolderID)
                    holderIdInputTextField.setValidator(inputValidator);
                bankNameInputTextField.setValidator(inputValidator);
                bankIdInputTextField.setValidator(new BankIdValidator(countryCode));
                branchIdInputTextField.setValidator(new BranchIdValidator(countryCode));
                accountNrInputTextField.setValidator(new AccountNrValidator(countryCode));
            } else {
                validatorsApplied = false;
                if (useHolderID)
                    holderIdInputTextField.setValidator(null);
                bankNameInputTextField.setValidator(null);
                bankIdInputTextField.setValidator(null);
                branchIdInputTextField.setValidator(null);
                accountNrInputTextField.setValidator(null);
            }
            holderNameInputTextField.resetValidation();
            bankNameInputTextField.resetValidation();
            bankIdInputTextField.resetValidation();
            branchIdInputTextField.resetValidation();
            accountNrInputTextField.resetValidation();
            boolean requiresHolderId = BankUtil.isHolderIdRequired(countryCode);
            if (requiresHolderId) {
                holderNameInputTextField.minWidthProperty().unbind();
                holderNameInputTextField.setMinWidth(250);
            } else {
                holderNameInputTextField.minWidthProperty().bind(currencyComboBox.widthProperty());
            }
            if (useHolderID) {
                if (!requiresHolderId)
                    holderIdInputTextField.setText("");
                holderIdInputTextField.resetValidation();
                holderIdInputTextField.setVisible(requiresHolderId);
                holderIdInputTextField.setManaged(requiresHolderId);
                holderIdLabel.setText(BankUtil.getHolderIdLabel(countryCode));
                holderIdLabel.setVisible(requiresHolderId);
                holderIdLabel.setManaged(requiresHolderId);
            }
            boolean bankNameRequired = BankUtil.isBankNameRequired(countryCode);
            bankNameTuple.first.setVisible(bankNameRequired);
            bankNameTuple.first.setManaged(bankNameRequired);
            bankNameInputTextField.setVisible(bankNameRequired);
            bankNameInputTextField.setManaged(bankNameRequired);
            boolean bankIdRequired = BankUtil.isBankIdRequired(countryCode);
            bankIdTuple.first.setVisible(bankIdRequired);
            bankIdTuple.first.setManaged(bankIdRequired);
            bankIdInputTextField.setVisible(bankIdRequired);
            bankIdInputTextField.setManaged(bankIdRequired);
            boolean branchIdRequired = BankUtil.isBranchIdRequired(countryCode);
            branchIdTuple.first.setVisible(branchIdRequired);
            branchIdTuple.first.setManaged(branchIdRequired);
            branchIdInputTextField.setVisible(branchIdRequired);
            branchIdInputTextField.setManaged(branchIdRequired);
            boolean accountNrRequired = BankUtil.isAccountNrRequired(countryCode);
            accountNrTuple.first.setVisible(accountNrRequired);
            accountNrTuple.first.setManaged(accountNrRequired);
            accountNrInputTextField.setVisible(accountNrRequired);
            accountNrInputTextField.setManaged(accountNrRequired);
            boolean accountTypeRequired = BankUtil.isAccountTypeRequired(countryCode);
            accountTypeTuple.first.setVisible(accountTypeRequired);
            accountTypeTuple.first.setManaged(accountTypeRequired);
            accountTypeTuple.second.setVisible(accountTypeRequired);
            accountTypeTuple.second.setManaged(accountTypeRequired);
            updateFromInputs();
            onCountryChanged();
        }
    });
    regionComboBox.setOnAction(e -> {
        Region selectedItem = regionComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            countryComboBox.setDisable(false);
            countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllCountriesForRegion(selectedItem)));
        }
    });
    // noinspection unchecked
    currencyComboBox = addLabelComboBox(gridPane, ++gridRow, Res.getWithCol("shared.currency")).second;
    currencyComboBox.setPromptText(Res.get("list.currency.select"));
    currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getAllSortedFiatCurrencies()));
    currencyComboBox.setOnAction(e -> {
        TradeCurrency selectedItem = currencyComboBox.getSelectionModel().getSelectedItem();
        FiatCurrency defaultCurrency = CurrencyUtil.getCurrencyByCountryCode(countryComboBox.getSelectionModel().getSelectedItem().code);
        if (!defaultCurrency.equals(selectedItem)) {
            new Popup<>().warning(Res.get("payment.foreign.currency")).actionButtonText(Res.get("shared.yes")).onAction(() -> {
                paymentAccount.setSingleTradeCurrency(selectedItem);
                autoFillNameTextField();
            }).closeButtonText(Res.get("payment.restore.default")).onClose(() -> currencyComboBox.getSelectionModel().select(defaultCurrency)).show();
        } else {
            paymentAccount.setSingleTradeCurrency(selectedItem);
            autoFillNameTextField();
        }
    });
    currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {

        @Override
        public String toString(TradeCurrency currency) {
            return currency.getNameAndCode();
        }

        @Override
        public TradeCurrency fromString(String string) {
            return null;
        }
    });
    currencyComboBox.setDisable(true);
    addAcceptedBanksForAddAccount();
    addHolderNameAndId();
    bankNameTuple = addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.bank.name"));
    bankNameInputTextField = bankNameTuple.second;
    bankNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountPayload.setBankName(newValue);
        updateFromInputs();
    });
    bankIdTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBankIdLabel(""));
    bankIdLabel = bankIdTuple.first;
    bankIdInputTextField = bankIdTuple.second;
    bankIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountPayload.setBankId(newValue);
        updateFromInputs();
    });
    branchIdTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBranchIdLabel(""));
    branchIdLabel = branchIdTuple.first;
    branchIdInputTextField = branchIdTuple.second;
    branchIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountPayload.setBranchId(newValue);
        updateFromInputs();
    });
    accountNrTuple = addLabelInputTextField(gridPane, ++gridRow, BankUtil.getAccountNrLabel(""));
    accountNrLabel = accountNrTuple.first;
    accountNrInputTextField = accountNrTuple.second;
    accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        bankAccountPayload.setAccountNr(newValue);
        updateFromInputs();
    });
    accountTypeTuple = addLabelComboBox(gridPane, ++gridRow, "");
    accountTypeLabel = accountTypeTuple.first;
    // noinspection unchecked
    accountTypeComboBox = accountTypeTuple.second;
    accountTypeComboBox.setPromptText(Res.get("payment.select.account"));
    accountTypeComboBox.setOnAction(e -> {
        if (BankUtil.isAccountTypeRequired(bankAccountPayload.getCountryCode())) {
            bankAccountPayload.setAccountType(accountTypeComboBox.getSelectionModel().getSelectedItem());
            updateFromInputs();
        }
    });
    addLimitations();
    addAccountNameTextFieldWithAutoFillCheckBox();
    updateFromInputs();
}
Also used : BankIdValidator(bisq.desktop.util.validation.BankIdValidator) TradeCurrency(bisq.core.locale.TradeCurrency) ComboBox(javafx.scene.control.ComboBox) Label(javafx.scene.control.Label) BranchIdValidator(bisq.desktop.util.validation.BranchIdValidator) Popup(bisq.desktop.main.overlays.popups.Popup) Region(bisq.core.locale.Region) Country(bisq.core.locale.Country) FiatCurrency(bisq.core.locale.FiatCurrency) AccountNrValidator(bisq.desktop.util.validation.AccountNrValidator)

Example 10 with Country

use of bisq.core.locale.Country in project bisq-desktop by bisq-network.

the class CashDepositForm method addFormForAddAccount.

@Override
public void addFormForAddAccount() {
    gridRowFrom = gridRow + 1;
    Tuple3<Label, ComboBox, ComboBox> tuple3 = FormBuilder.addLabelComboBoxComboBox(gridPane, ++gridRow, Res.get("payment.country"));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Region> regionComboBox = tuple3.second;
    regionComboBox.setPromptText(Res.get("payment.select.region"));
    regionComboBox.setConverter(new StringConverter<Region>() {

        @Override
        public String toString(Region region) {
            return region.name;
        }

        @Override
        public Region fromString(String s) {
            return null;
        }
    });
    regionComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllRegions()));
    // noinspection unchecked,unchecked,unchecked
    ComboBox<Country> countryComboBox = tuple3.third;
    countryComboBox.setVisibleRowCount(15);
    countryComboBox.setDisable(true);
    countryComboBox.setPromptText(Res.get("payment.select.country"));
    countryComboBox.setConverter(new StringConverter<Country>() {

        @Override
        public String toString(Country country) {
            return country.name + " (" + country.code + ")";
        }

        @Override
        public Country fromString(String s) {
            return null;
        }
    });
    countryComboBox.setOnAction(e -> {
        Country selectedItem = countryComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            getCountryBasedPaymentAccount().setCountry(selectedItem);
            String countryCode = selectedItem.code;
            TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(countryCode);
            paymentAccount.setSingleTradeCurrency(currency);
            currencyComboBox.setDisable(false);
            currencyComboBox.getSelectionModel().select(currency);
            bankIdLabel.setText(BankUtil.getBankIdLabel(countryCode));
            branchIdLabel.setText(BankUtil.getBranchIdLabel(countryCode));
            accountNrLabel.setText(BankUtil.getAccountNrLabel(countryCode));
            accountTypeLabel.setText(BankUtil.getAccountTypeLabel(countryCode));
            bankNameInputTextField.setText("");
            bankIdInputTextField.setText("");
            branchIdInputTextField.setText("");
            accountNrInputTextField.setText("");
            accountTypeComboBox.getSelectionModel().clearSelection();
            accountTypeComboBox.setItems(FXCollections.observableArrayList(BankUtil.getAccountTypeValues(countryCode)));
            if (BankUtil.useValidation(countryCode) && !validatorsApplied) {
                validatorsApplied = true;
                if (useHolderID)
                    holderIdInputTextField.setValidator(inputValidator);
                bankNameInputTextField.setValidator(inputValidator);
                bankIdInputTextField.setValidator(new BankIdValidator(countryCode));
                branchIdInputTextField.setValidator(new BranchIdValidator(countryCode));
                accountNrInputTextField.setValidator(new AccountNrValidator(countryCode));
            } else {
                validatorsApplied = false;
                if (useHolderID)
                    holderIdInputTextField.setValidator(null);
                bankNameInputTextField.setValidator(null);
                bankIdInputTextField.setValidator(null);
                branchIdInputTextField.setValidator(null);
                accountNrInputTextField.setValidator(null);
            }
            holderNameInputTextField.resetValidation();
            emailInputTextField.resetValidation();
            bankNameInputTextField.resetValidation();
            bankIdInputTextField.resetValidation();
            branchIdInputTextField.resetValidation();
            accountNrInputTextField.resetValidation();
            boolean requiresHolderId = BankUtil.isHolderIdRequired(countryCode);
            if (requiresHolderId) {
                holderNameInputTextField.minWidthProperty().unbind();
                holderNameInputTextField.setMinWidth(300);
            } else {
                holderNameInputTextField.minWidthProperty().bind(currencyComboBox.widthProperty());
            }
            if (useHolderID) {
                if (!requiresHolderId)
                    holderIdInputTextField.setText("");
                holderIdInputTextField.resetValidation();
                holderIdInputTextField.setVisible(requiresHolderId);
                holderIdInputTextField.setManaged(requiresHolderId);
                holderIdLabel.setText(BankUtil.getHolderIdLabel(countryCode));
                holderIdLabel.setVisible(requiresHolderId);
                holderIdLabel.setManaged(requiresHolderId);
            }
            boolean bankNameRequired = BankUtil.isBankNameRequired(countryCode);
            bankNameTuple.first.setVisible(bankNameRequired);
            bankNameTuple.first.setManaged(bankNameRequired);
            bankNameInputTextField.setVisible(bankNameRequired);
            bankNameInputTextField.setManaged(bankNameRequired);
            boolean bankIdRequired = BankUtil.isBankIdRequired(countryCode);
            bankIdTuple.first.setVisible(bankIdRequired);
            bankIdTuple.first.setManaged(bankIdRequired);
            bankIdInputTextField.setVisible(bankIdRequired);
            bankIdInputTextField.setManaged(bankIdRequired);
            boolean branchIdRequired = BankUtil.isBranchIdRequired(countryCode);
            branchIdTuple.first.setVisible(branchIdRequired);
            branchIdTuple.first.setManaged(branchIdRequired);
            branchIdInputTextField.setVisible(branchIdRequired);
            branchIdInputTextField.setManaged(branchIdRequired);
            boolean accountNrRequired = BankUtil.isAccountNrRequired(countryCode);
            accountNrTuple.first.setVisible(accountNrRequired);
            accountNrTuple.first.setManaged(accountNrRequired);
            accountNrInputTextField.setVisible(accountNrRequired);
            accountNrInputTextField.setManaged(accountNrRequired);
            boolean accountTypeRequired = BankUtil.isAccountTypeRequired(countryCode);
            accountTypeTuple.first.setVisible(accountTypeRequired);
            accountTypeTuple.first.setManaged(accountTypeRequired);
            accountTypeTuple.second.setVisible(accountTypeRequired);
            accountTypeTuple.second.setManaged(accountTypeRequired);
            updateFromInputs();
            onCountryChanged();
        }
    });
    regionComboBox.setOnAction(e -> {
        Region selectedItem = regionComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            countryComboBox.setDisable(false);
            countryComboBox.setItems(FXCollections.observableArrayList(CountryUtil.getAllCountriesForRegion(selectedItem)));
        }
    });
    // noinspection unchecked
    currencyComboBox = FormBuilder.addLabelComboBox(gridPane, ++gridRow, Res.getWithCol("shared.currency")).second;
    currencyComboBox.setPromptText(Res.get("list.currency.select"));
    currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getAllSortedFiatCurrencies()));
    currencyComboBox.setOnAction(e -> {
        TradeCurrency selectedItem = currencyComboBox.getSelectionModel().getSelectedItem();
        FiatCurrency defaultCurrency = CurrencyUtil.getCurrencyByCountryCode(countryComboBox.getSelectionModel().getSelectedItem().code);
        if (!defaultCurrency.equals(selectedItem)) {
            new Popup<>().warning(Res.get("payment.foreign.currency")).actionButtonText(Res.get("shared.yes")).onAction(() -> {
                paymentAccount.setSingleTradeCurrency(selectedItem);
                autoFillNameTextField();
            }).closeButtonText(Res.get("payment.restore.default")).onClose(() -> currencyComboBox.getSelectionModel().select(defaultCurrency)).show();
        } else {
            paymentAccount.setSingleTradeCurrency(selectedItem);
            autoFillNameTextField();
        }
    });
    currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {

        @Override
        public String toString(TradeCurrency currency) {
            return currency.getNameAndCode();
        }

        @Override
        public TradeCurrency fromString(String string) {
            return null;
        }
    });
    currencyComboBox.setDisable(true);
    addAcceptedBanksForAddAccount();
    addHolderNameAndId();
    bankNameTuple = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, Res.get("payment.bank.name"));
    bankNameInputTextField = bankNameTuple.second;
    bankNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountPayload.setBankName(newValue);
        updateFromInputs();
    });
    bankIdTuple = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBankIdLabel(""));
    bankIdLabel = bankIdTuple.first;
    bankIdInputTextField = bankIdTuple.second;
    bankIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountPayload.setBankId(newValue);
        updateFromInputs();
    });
    branchIdTuple = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, BankUtil.getBranchIdLabel(""));
    branchIdLabel = branchIdTuple.first;
    branchIdInputTextField = branchIdTuple.second;
    branchIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountPayload.setBranchId(newValue);
        updateFromInputs();
    });
    accountNrTuple = FormBuilder.addLabelInputTextField(gridPane, ++gridRow, BankUtil.getAccountNrLabel(""));
    accountNrLabel = accountNrTuple.first;
    accountNrInputTextField = accountNrTuple.second;
    accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountPayload.setAccountNr(newValue);
        updateFromInputs();
    });
    accountTypeTuple = FormBuilder.addLabelComboBox(gridPane, ++gridRow, "");
    accountTypeLabel = accountTypeTuple.first;
    // noinspection unchecked
    accountTypeComboBox = accountTypeTuple.second;
    accountTypeComboBox.setPromptText(Res.get("payment.select.account"));
    accountTypeComboBox.setOnAction(e -> {
        if (BankUtil.isAccountTypeRequired(cashDepositAccountPayload.getCountryCode())) {
            cashDepositAccountPayload.setAccountType(accountTypeComboBox.getSelectionModel().getSelectedItem());
            updateFromInputs();
        }
    });
    TextArea requirementsTextArea = FormBuilder.addLabelTextArea(gridPane, ++gridRow, Res.get("payment.extras"), "").second;
    requirementsTextArea.setMinHeight(30);
    requirementsTextArea.setMaxHeight(30);
    requirementsTextArea.textProperty().addListener((ov, oldValue, newValue) -> {
        cashDepositAccountPayload.setRequirements(newValue);
        updateFromInputs();
    });
    addLimitations();
    addAccountNameTextFieldWithAutoFillCheckBox();
    updateFromInputs();
}
Also used : BankIdValidator(bisq.desktop.util.validation.BankIdValidator) TradeCurrency(bisq.core.locale.TradeCurrency) TextArea(javafx.scene.control.TextArea) ComboBox(javafx.scene.control.ComboBox) Label(javafx.scene.control.Label) BranchIdValidator(bisq.desktop.util.validation.BranchIdValidator) Popup(bisq.desktop.main.overlays.popups.Popup) Region(bisq.core.locale.Region) Country(bisq.core.locale.Country) FiatCurrency(bisq.core.locale.FiatCurrency) AccountNrValidator(bisq.desktop.util.validation.AccountNrValidator)

Aggregations

Country (bisq.core.locale.Country)12 FiatCurrency (bisq.core.locale.FiatCurrency)7 TradeCurrency (bisq.core.locale.TradeCurrency)7 ComboBox (javafx.scene.control.ComboBox)5 Region (bisq.core.locale.Region)3 InputTextField (bisq.desktop.components.InputTextField)3 Popup (bisq.desktop.main.overlays.popups.Popup)3 Label (javafx.scene.control.Label)3 CountryBasedPaymentAccount (bisq.core.payment.CountryBasedPaymentAccount)2 AccountNrValidator (bisq.desktop.util.validation.AccountNrValidator)2 BankIdValidator (bisq.desktop.util.validation.BankIdValidator)2 BranchIdValidator (bisq.desktop.util.validation.BranchIdValidator)2 TextField (javafx.scene.control.TextField)2 HBox (javafx.scene.layout.HBox)2 BaseCurrencyNetwork (bisq.core.btc.BaseCurrencyNetwork)1 NationalBankAccount (bisq.core.payment.NationalBankAccount)1 SameBankAccount (bisq.core.payment.SameBankAccount)1 SepaAccount (bisq.core.payment.SepaAccount)1 SpecificBanksAccount (bisq.core.payment.SpecificBanksAccount)1 NationalBankAccountPayload (bisq.core.payment.payload.NationalBankAccountPayload)1