Add support for other currency than countries default currency at cash deposit and add support for EUR for PerfectMoney

This commit is contained in:
Manfred Karrer 2016-09-03 20:17:25 -05:00
parent 56aaf3b37b
commit 80b69109b9
3 changed files with 50 additions and 10 deletions

View File

@ -21,6 +21,7 @@ import io.bitsquare.common.util.Tuple2;
import io.bitsquare.common.util.Tuple3;
import io.bitsquare.common.util.Tuple4;
import io.bitsquare.gui.components.InputTextField;
import io.bitsquare.gui.main.overlays.popups.Popup;
import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.Layout;
import io.bitsquare.gui.util.validation.AccountNrValidator;
@ -50,7 +51,6 @@ public class CashDepositForm extends PaymentMethodForm {
protected final CashDepositAccountContractData cashDepositAccountContractData;
private InputTextField bankNameInputTextField, bankIdInputTextField, branchIdInputTextField, accountNrInputTextField, holderIdInputTextField;
private TextField currencyTextField;
private Label holderIdLabel;
protected InputTextField holderNameInputTextField, holderEmailInputTextField;
private Label bankIdLabel;
@ -65,6 +65,7 @@ public class CashDepositForm extends PaymentMethodForm {
private ComboBox<String> accountTypeComboBox;
private boolean validatorsApplied;
private boolean useHolderID;
private ComboBox<TradeCurrency> currencyComboBox;
public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountContractData paymentAccountContractData) {
CashDepositAccountContractData data = (CashDepositAccountContractData) paymentAccountContractData;
@ -255,8 +256,6 @@ public class CashDepositForm extends PaymentMethodForm {
gridRowFrom = gridRow + 1;
Tuple3<Label, ComboBox, ComboBox> tuple3 = addLabelComboBoxComboBox(gridPane, ++gridRow, "Country:");
currencyTextField = addLabelTextField(gridPane, ++gridRow, "Currency:").second;
currencyTextField.setMouseTransparent(true);
ComboBox<Region> regionComboBox = tuple3.second;
regionComboBox.setPromptText("Select region");
@ -295,7 +294,8 @@ public class CashDepositForm extends PaymentMethodForm {
String countryCode = selectedItem.code;
TradeCurrency currency = CurrencyUtil.getCurrencyByCountryCode(countryCode);
paymentAccount.setSingleTradeCurrency(currency);
currencyTextField.setText(currency.getNameAndCode());
currencyComboBox.setDisable(false);
currencyComboBox.getSelectionModel().select(currency);
bankIdLabel.setText(BankUtil.getBankIdLabel(countryCode));
branchIdLabel.setText(BankUtil.getBranchIdLabel(countryCode));
@ -338,7 +338,7 @@ public class CashDepositForm extends PaymentMethodForm {
holderNameInputTextField.minWidthProperty().unbind();
holderNameInputTextField.setMinWidth(300);
} else {
holderNameInputTextField.minWidthProperty().bind(currencyTextField.widthProperty());
holderNameInputTextField.minWidthProperty().bind(currencyComboBox.widthProperty());
}
if (useHolderID) {
@ -399,6 +399,40 @@ public class CashDepositForm extends PaymentMethodForm {
}
});
currencyComboBox = addLabelComboBox(gridPane, ++gridRow, "Currency:").second;
currencyComboBox.setPromptText("Select currency");
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("Are you sure you want to choose a currency other than the countries default currency?")
.actionButtonText("Yes")
.onAction(() -> {
paymentAccount.setSingleTradeCurrency(selectedItem);
autoFillNameTextField();
})
.closeButtonText("No, restore default currency")
.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();
@ -479,7 +513,7 @@ public class CashDepositForm extends PaymentMethodForm {
cashDepositAccountContractData.setHolderName(newValue);
updateFromInputs();
});
holderNameInputTextField.minWidthProperty().bind(currencyTextField.widthProperty());
holderNameInputTextField.minWidthProperty().bind(currencyComboBox.widthProperty());
holderNameInputTextField.setValidator(inputValidator);
holderEmailInputTextField = addLabelInputTextField(gridPane, ++gridRow, "Account holder email:").second;
@ -487,7 +521,7 @@ public class CashDepositForm extends PaymentMethodForm {
cashDepositAccountContractData.setHolderEmail(newValue);
updateFromInputs();
});
holderEmailInputTextField.minWidthProperty().bind(currencyTextField.widthProperty());
holderEmailInputTextField.minWidthProperty().bind(currencyComboBox.widthProperty());
holderEmailInputTextField.setValidator(inputValidator);
useHolderID = true;

View File

@ -53,7 +53,7 @@ public abstract class PaymentMethodForm {
protected int gridRowFrom;
protected InputTextField accountNameTextField;
protected CheckBox useCustomAccountNameCheckBox;
private ComboBox<TradeCurrency> currencyComboBox;
protected ComboBox<TradeCurrency> currencyComboBox;
public PaymentMethodForm(PaymentAccount paymentAccount, InputValidator inputValidator, GridPane gridPane, int gridRow, BSFormatter formatter) {
this.paymentAccount = paymentAccount;

View File

@ -23,10 +23,12 @@ import io.bitsquare.gui.util.Layout;
import io.bitsquare.gui.util.validation.InputValidator;
import io.bitsquare.gui.util.validation.PerfectMoneyValidator;
import io.bitsquare.locale.BSResources;
import io.bitsquare.locale.FiatCurrency;
import io.bitsquare.payment.PaymentAccount;
import io.bitsquare.payment.PaymentAccountContractData;
import io.bitsquare.payment.PerfectMoneyAccount;
import io.bitsquare.payment.PerfectMoneyAccountContractData;
import javafx.collections.FXCollections;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import org.apache.commons.lang3.StringUtils;
@ -65,12 +67,14 @@ public class PerfectMoneyForm extends PaymentMethodForm {
updateFromInputs();
});
addLabelTextField(gridPane, ++gridRow, "Currency:", perfectMoneyAccount.getSingleTradeCurrency().getNameAndCode());
addTradeCurrencyComboBox();
currencyComboBox.setItems(FXCollections.observableArrayList(new FiatCurrency("USD"), new FiatCurrency("EUR")));
currencyComboBox.getSelectionModel().select(0);
addAllowedPeriod();
addAccountNameTextFieldWithAutoFillCheckBox();
}
@Override
protected void autoFillNameTextField() {
if (useCustomAccountNameCheckBox != null && !useCustomAccountNameCheckBox.isSelected()) {
@ -88,7 +92,9 @@ public class PerfectMoneyForm extends PaymentMethodForm {
addLabelTextField(gridPane, ++gridRow, "Payment method:", BSResources.get(perfectMoneyAccount.getPaymentMethod().getId()));
TextField field = addLabelTextField(gridPane, ++gridRow, "Account nr.:", perfectMoneyAccount.getAccountNr()).second;
field.setMouseTransparent(false);
addLabelTextField(gridPane, ++gridRow, "Currency:", perfectMoneyAccount.getSingleTradeCurrency().getNameAndCode());
addAllowedPeriod();
}