Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements Face to Face payment method #1607

Merged
merged 3 commits into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/bisq/desktop/bisq.css
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ bg color of non edit textFields: fafafa
-fx-background-color: -bs-bg-light;
}

.text-area {
-fx-prompt-text-fill: derive(-fx-control-inner-background, -30%);
}

#label-url {
-fx-cursor: hand;
-fx-text-fill: -bs-blue;
Expand Down
263 changes: 263 additions & 0 deletions src/main/java/bisq/desktop/components/paymentmethods/F2FForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.desktop.components.paymentmethods;

import bisq.desktop.components.InputTextField;
import bisq.desktop.main.overlays.popups.Popup;
import bisq.desktop.util.Layout;
import bisq.desktop.util.validation.F2FValidator;

import bisq.core.locale.Country;
import bisq.core.locale.CountryUtil;
import bisq.core.locale.CurrencyUtil;
import bisq.core.locale.FiatCurrency;
import bisq.core.locale.Region;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.offer.Offer;
import bisq.core.payment.AccountAgeWitnessService;
import bisq.core.payment.CountryBasedPaymentAccount;
import bisq.core.payment.F2FAccount;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.F2FAccountPayload;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.util.BSFormatter;
import bisq.core.util.validation.InputValidator;

import bisq.common.util.Tuple3;

import org.apache.commons.lang3.StringUtils;

import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.GridPane;

import javafx.collections.FXCollections;

import javafx.util.StringConverter;

import static bisq.desktop.util.FormBuilder.*;

public class F2FForm extends PaymentMethodForm {
private final F2FAccount f2fAccount;
private final F2FValidator f2fValidator;
private TextArea extraTextArea;
private InputTextField cityInputTextField;

public static int addFormForBuyer(GridPane gridPane, int gridRow,
PaymentAccountPayload paymentAccountPayload, Offer offer) {
F2FAccountPayload f2fAccountPayload = (F2FAccountPayload) paymentAccountPayload;
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.getWithCol("shared.country"),
CountryUtil.getNameAndCode(f2fAccountPayload.getCountryCode()));
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.getWithCol("payment.f2f.contact"),
f2fAccountPayload.getContact());
addLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.getWithCol("payment.f2f.city"),
offer.getF2FCity());
TextArea textArea = addLabelTextArea(gridPane, ++gridRow, Res.getWithCol("payment.f2f.extra"), "").second;
textArea.setPrefHeight(60);
textArea.setEditable(false);
textArea.setId("text-area-disabled");
textArea.setText(offer.getF2FExtraInfo());
return gridRow;
}

public F2FForm(PaymentAccount paymentAccount,
AccountAgeWitnessService accountAgeWitnessService, F2FValidator f2fValidator,
InputValidator inputValidator, GridPane gridPane, int gridRow, BSFormatter formatter) {
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);

this.f2fAccount = (F2FAccount) paymentAccount;
this.f2fValidator = f2fValidator;
}


@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);

updateFromInputs();
}
});

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);

InputTextField contactInputTextField = addLabelInputTextField(gridPane, ++gridRow,
Res.getWithCol("payment.f2f.contact")).second;
contactInputTextField.setPromptText(Res.get("payment.f2f.contact.prompt"));
contactInputTextField.setValidator(f2fValidator);
contactInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
f2fAccount.setContact(newValue);
updateFromInputs();
});

cityInputTextField = addLabelInputTextField(gridPane, ++gridRow,
Res.getWithCol("payment.f2f.city")).second;
cityInputTextField.setPromptText(Res.get("payment.f2f.city.prompt"));
cityInputTextField.setValidator(f2fValidator);
cityInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
f2fAccount.setCity(newValue);
updateFromInputs();
});

extraTextArea = addLabelTextArea(gridPane, ++gridRow,
Res.getWithCol("payment.f2f.optionalExtra"), "").second;
extraTextArea.setPromptText(Res.get("payment.f2f.extra.prompt"));
extraTextArea.setPrefHeight(60);
//extraTextArea.setValidator(f2fValidator);
extraTextArea.textProperty().addListener((ov, oldValue, newValue) -> {
f2fAccount.setExtraInfo(newValue);
updateFromInputs();
});

addLimitations();
addAccountNameTextFieldWithAutoFillCheckBox();
}

@Override
protected void autoFillNameTextField() {
if (useCustomAccountNameCheckBox != null && !useCustomAccountNameCheckBox.isSelected()) {
String city = cityInputTextField.getText();
city = StringUtils.abbreviate(city, 9);
String method = Res.get(paymentAccount.getPaymentMethod().getId());
accountNameTextField.setText(method.concat(": ").concat(city));
}
}

@Override
public void addFormForDisplayAccount() {
gridRowFrom = gridRow;

addLabelTextField(gridPane, gridRow, Res.get("payment.account.name"),
paymentAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("shared.paymentMethod"),
Res.get(paymentAccount.getPaymentMethod().getId()));
addLabelTextField(gridPane, ++gridRow, Res.get("payment.country"),
getCountryBasedPaymentAccount().getCountry() != null ? getCountryBasedPaymentAccount().getCountry().name : "");
TradeCurrency singleTradeCurrency = paymentAccount.getSingleTradeCurrency();
String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null";
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("shared.currency"), nameAndCode);
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("payment.f2f.contact", f2fAccount.getContact()),
f2fAccount.getContact());
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("payment.f2f.city", f2fAccount.getCity()),
f2fAccount.getCity());
TextArea textArea = addLabelTextArea(gridPane, ++gridRow, Res.get("payment.f2f.extra"), "").second;
textArea.setText(f2fAccount.getExtraInfo());
textArea.setPrefHeight(60);
textArea.setEditable(false);

addLimitations();
}

@Override
public void updateAllInputsValid() {
allInputsValid.set(isAccountNameValid()
&& f2fValidator.validate(f2fAccount.getContact()).isValid
&& f2fValidator.validate(f2fAccount.getCity()).isValid
&& f2fAccount.getTradeCurrencies().size() > 0);
}

private CountryBasedPaymentAccount getCountryBasedPaymentAccount() {
return (CountryBasedPaymentAccount) this.paymentAccount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,12 @@
import javafx.scene.control.TextArea;
import javafx.scene.layout.GridPane;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static bisq.desktop.util.FormBuilder.addLabelInputTextField;
import static bisq.desktop.util.FormBuilder.addLabelTextArea;
import static bisq.desktop.util.FormBuilder.addLabelTextField;
import static bisq.desktop.util.FormBuilder.addLabelTextFieldWithCopyIcon;

public class USPostalMoneyOrderForm extends PaymentMethodForm {
private static final Logger log = LoggerFactory.getLogger(USPostalMoneyOrderForm.class);

private final USPostalMoneyOrderAccount usPostalMoneyOrderAccount;
private final USPostalMoneyOrderValidator usPostalMoneyOrderValidator;
private TextArea postalAddressTextArea;
Expand Down
Loading