-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1607 from ManfredKarrer/f2f
Implements Face to Face payment method
- Loading branch information
Showing
10 changed files
with
469 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
263 changes: 263 additions & 0 deletions
263
src/main/java/bisq/desktop/components/paymentmethods/F2FForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.