Clean up WeChatPayForm, PerfectMoneyForm and AliPayForm

This commit is contained in:
Christoph Atteneder 2018-10-26 17:20:35 +02:00
parent c183741fba
commit 7073e44f19
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
5 changed files with 87 additions and 140 deletions

View File

@ -17,12 +17,9 @@
package bisq.desktop.components.paymentmethods;
import bisq.desktop.components.InputTextField;
import bisq.desktop.util.FormBuilder;
import bisq.desktop.util.validation.AliPayValidator;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.AccountAgeWitnessService;
import bisq.core.payment.AliPayAccount;
import bisq.core.payment.PaymentAccount;
@ -31,21 +28,13 @@ import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.util.BSFormatter;
import bisq.core.util.validation.InputValidator;
import org.apache.commons.lang3.StringUtils;
import javafx.scene.layout.GridPane;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static bisq.desktop.util.FormBuilder.addTopLabelTextFieldWithCopyIcon;
public class AliPayForm extends PaymentMethodForm {
private static final Logger log = LoggerFactory.getLogger(AliPayForm.class);
public class AliPayForm extends GeneralAccountNumberForm {
private final AliPayAccount aliPayAccount;
private final AliPayValidator aliPayValidator;
private InputTextField accountNrInputTextField;
public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) {
addTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.account.no"), ((AliPayAccountPayload) paymentAccountPayload).getAccountNr());
@ -55,49 +44,15 @@ public class AliPayForm extends PaymentMethodForm {
public AliPayForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, AliPayValidator aliPayValidator, InputValidator inputValidator, GridPane gridPane, int gridRow, BSFormatter formatter) {
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);
this.aliPayAccount = (AliPayAccount) paymentAccount;
this.aliPayValidator = aliPayValidator;
}
@Override
public void addFormForAddAccount() {
gridRowFrom = gridRow + 1;
accountNrInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.account.no"));
accountNrInputTextField.setValidator(aliPayValidator);
accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
aliPayAccount.setAccountNr(newValue);
updateFromInputs();
});
final TradeCurrency singleTradeCurrency = aliPayAccount.getSingleTradeCurrency();
final String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "";
FormBuilder.addTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode);
addLimitations();
addAccountNameTextFieldWithAutoFillToggleButton();
void setAccountNumber(String newValue) {
aliPayAccount.setAccountNr(newValue);
}
@Override
protected void autoFillNameTextField() {
if (useCustomAccountNameToggleButton != null && !useCustomAccountNameToggleButton.isSelected()) {
String accountNr = accountNrInputTextField.getText();
accountNr = StringUtils.abbreviate(accountNr, 9);
String method = Res.get(paymentAccount.getPaymentMethod().getId());
accountNameTextField.setText(method.concat(": ").concat(accountNr));
}
String getAccountNr() {
return aliPayAccount.getAccountNr();
}
@Override
public void addFormForDisplayAccount() {
addFormForAccountNumberDisplayAccount(aliPayAccount.getAccountName(),
aliPayAccount.getPaymentMethod(), aliPayAccount.getAccountNr(),
aliPayAccount.getSingleTradeCurrency());
}
@Override
public void updateAllInputsValid() {
allInputsValid.set(isAccountNameValid()
&& aliPayValidator.validate(aliPayAccount.getAccountNr()).isValid
&& aliPayAccount.getTradeCurrencies().size() > 0);
}
}

View File

@ -0,0 +1,67 @@
package bisq.desktop.components.paymentmethods;
import bisq.desktop.components.InputTextField;
import bisq.desktop.util.FormBuilder;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.AccountAgeWitnessService;
import bisq.core.payment.PaymentAccount;
import bisq.core.util.BSFormatter;
import bisq.core.util.validation.InputValidator;
import javafx.scene.layout.GridPane;
abstract public class GeneralAccountNumberForm extends PaymentMethodForm {
private InputTextField accountNrInputTextField;
public GeneralAccountNumberForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, InputValidator inputValidator, GridPane gridPane, int gridRow, BSFormatter formatter) {
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);
}
@Override
public void addFormForAddAccount() {
gridRowFrom = gridRow + 1;
accountNrInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.account.no"));
accountNrInputTextField.setValidator(inputValidator);
accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
setAccountNumber(newValue);
updateFromInputs();
});
addTradeCurrency();
addLimitations();
addAccountNameTextFieldWithAutoFillToggleButton();
}
public void addTradeCurrency() {
final TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
final String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "";
FormBuilder.addTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode);
}
@Override
protected void autoFillNameTextField() {
setAccountNameWithString(accountNrInputTextField.getText());
}
@Override
public void addFormForDisplayAccount() {
addFormForAccountNumberDisplayAccount(paymentAccount.getAccountName(), paymentAccount.getPaymentMethod(), getAccountNr(),
paymentAccount.getSingleTradeCurrency());
}
@Override
public void updateAllInputsValid() {
allInputsValid.set(isAccountNameValid()
&& inputValidator.validate(getAccountNr()).isValid
&& paymentAccount.getTradeCurrencies().size() > 0);
}
abstract void setAccountNumber(String newValue);
abstract String getAccountNr();
}

View File

@ -92,10 +92,10 @@ public abstract class PaymentMethodForm {
}
protected void addTradeCurrencyComboBox() {
currencyComboBox = FormBuilder.<TradeCurrency>addComboBox(gridPane, ++gridRow, Res.get("shared.currency"));
currencyComboBox = FormBuilder.addComboBox(gridPane, ++gridRow, Res.get("shared.currency"));
currencyComboBox.setPromptText(Res.get("list.currency.select"));
currencyComboBox.setItems(FXCollections.observableArrayList(CurrencyUtil.getMainFiatCurrencies()));
currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {
currencyComboBox.setConverter(new StringConverter<>() {
@Override
public String toString(TradeCurrency tradeCurrency) {
return tradeCurrency.getNameAndCode();
@ -252,12 +252,12 @@ public abstract class PaymentMethodForm {
flowPane.getChildren().add(checkBox);
}
void fillUpFlowPaneWithCountries(boolean isEditable, List<CheckBox> checkBoxList, FlowPane flowPane, Country country) {
void fillUpFlowPaneWithCountries(List<CheckBox> checkBoxList, FlowPane flowPane, Country country) {
final String countryCode = country.code;
CheckBox checkBox = new AutoTooltipCheckBox(countryCode);
checkBox.setUserData(countryCode);
checkBoxList.add(checkBox);
checkBox.setMouseTransparent(!isEditable);
checkBox.setMouseTransparent(false);
checkBox.setMinWidth(45);
checkBox.setMaxWidth(45);
checkBox.setTooltip(new Tooltip(country.name));

View File

@ -17,8 +17,6 @@
package bisq.desktop.components.paymentmethods;
import bisq.desktop.components.InputTextField;
import bisq.desktop.util.FormBuilder;
import bisq.desktop.util.validation.PerfectMoneyValidator;
import bisq.core.locale.FiatCurrency;
@ -37,11 +35,9 @@ import javafx.collections.FXCollections;
import static bisq.desktop.util.FormBuilder.addTopLabelTextFieldWithCopyIcon;
public class PerfectMoneyForm extends PaymentMethodForm {
public class PerfectMoneyForm extends GeneralAccountNumberForm {
private final PerfectMoneyAccount perfectMoneyAccount;
private final PerfectMoneyValidator perfectMoneyValidator;
private InputTextField accountNrInputTextField;
public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) {
addTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.account.no"), ((PerfectMoneyAccountPayload) paymentAccountPayload).getAccountNr());
@ -52,44 +48,22 @@ public class PerfectMoneyForm extends PaymentMethodForm {
gridRow, BSFormatter formatter) {
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);
this.perfectMoneyAccount = (PerfectMoneyAccount) paymentAccount;
this.perfectMoneyValidator = perfectMoneyValidator;
}
@Override
public void addFormForAddAccount() {
gridRowFrom = gridRow + 1;
accountNrInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.account.no"));
accountNrInputTextField.setValidator(perfectMoneyValidator);
accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
perfectMoneyAccount.setAccountNr(newValue);
updateFromInputs();
});
public void addTradeCurrency() {
addTradeCurrencyComboBox();
currencyComboBox.setItems(FXCollections.observableArrayList(new FiatCurrency("USD"), new FiatCurrency("EUR")));
currencyComboBox.getSelectionModel().select(0);
addLimitations();
addAccountNameTextFieldWithAutoFillToggleButton();
}
@Override
protected void autoFillNameTextField() {
setAccountNameWithString(accountNrInputTextField.getText());
void setAccountNumber(String newValue) {
perfectMoneyAccount.setAccountNr(newValue);
}
@Override
public void addFormForDisplayAccount() {
addFormForAccountNumberDisplayAccount(perfectMoneyAccount.getAccountName(),
perfectMoneyAccount.getPaymentMethod(), perfectMoneyAccount.getAccountNr(),
perfectMoneyAccount.getSingleTradeCurrency());
}
@Override
public void updateAllInputsValid() {
allInputsValid.set(isAccountNameValid()
&& perfectMoneyValidator.validate(perfectMoneyAccount.getAccountNr()).isValid
&& perfectMoneyAccount.getTradeCurrencies().size() > 0);
String getAccountNr() {
return perfectMoneyAccount.getAccountNr();
}
}

View File

@ -17,13 +17,9 @@
package bisq.desktop.components.paymentmethods;
import bisq.desktop.components.InputTextField;
import bisq.desktop.util.FormBuilder;
import bisq.desktop.util.Layout;
import bisq.desktop.util.validation.WeChatPayValidator;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.AccountAgeWitnessService;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.WeChatPayAccount;
@ -32,19 +28,13 @@ import bisq.core.payment.payload.WeChatPayAccountPayload;
import bisq.core.util.BSFormatter;
import bisq.core.util.validation.InputValidator;
import org.apache.commons.lang3.StringUtils;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import static bisq.desktop.util.FormBuilder.addTopLabelTextField;
import static bisq.desktop.util.FormBuilder.addTopLabelTextFieldWithCopyIcon;
public class WeChatPayForm extends PaymentMethodForm {
public class WeChatPayForm extends GeneralAccountNumberForm {
private final WeChatPayAccount weChatPayAccount;
private final WeChatPayValidator weChatPayValidator;
private InputTextField accountNrInputTextField;
public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) {
addTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.account.no"), ((WeChatPayAccountPayload) paymentAccountPayload).getAccountNr());
@ -54,54 +44,15 @@ public class WeChatPayForm extends PaymentMethodForm {
public WeChatPayForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, WeChatPayValidator weChatPayValidator, InputValidator inputValidator, GridPane gridPane, int gridRow, BSFormatter formatter) {
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);
this.weChatPayAccount = (WeChatPayAccount) paymentAccount;
this.weChatPayValidator = weChatPayValidator;
}
@Override
public void addFormForAddAccount() {
gridRowFrom = gridRow + 1;
accountNrInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.account.no"));
accountNrInputTextField.setValidator(weChatPayValidator);
accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
weChatPayAccount.setAccountNr(newValue);
updateFromInputs();
});
final TradeCurrency singleTradeCurrency = weChatPayAccount.getSingleTradeCurrency();
final String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "";
FormBuilder.addTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode);
addLimitations();
addAccountNameTextFieldWithAutoFillToggleButton();
void setAccountNumber(String newValue) {
weChatPayAccount.setAccountNr(newValue);
}
@Override
protected void autoFillNameTextField() {
if (useCustomAccountNameToggleButton != null && !useCustomAccountNameToggleButton.isSelected()) {
String accountNr = accountNrInputTextField.getText();
accountNr = StringUtils.abbreviate(accountNr, 9);
String method = Res.get(paymentAccount.getPaymentMethod().getId());
accountNameTextField.setText(method.concat(": ").concat(accountNr));
}
}
@Override
public void addFormForDisplayAccount() {
gridRowFrom = gridRow;
addTopLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), weChatPayAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
FormBuilder.addTopLabelTextField(gridPane, ++gridRow, Res.get("shared.paymentMethod"), Res.get(weChatPayAccount.getPaymentMethod().getId()));
TextField field = FormBuilder.addTopLabelTextField(gridPane, ++gridRow, Res.get("payment.account.no"), weChatPayAccount.getAccountNr()).second;
field.setMouseTransparent(false);
final TradeCurrency singleTradeCurrency = weChatPayAccount.getSingleTradeCurrency();
final String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "";
FormBuilder.addTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode);
addLimitations();
}
@Override
public void updateAllInputsValid() {
allInputsValid.set(isAccountNameValid()
&& weChatPayValidator.validate(weChatPayAccount.getAccountNr()).isValid
&& weChatPayAccount.getTradeCurrencies().size() > 0);
String getAccountNr() {
return weChatPayAccount.getAccountNr();
}
}