-
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 #1619 from ManfredKarrer/halcash
Add HalCash
- Loading branch information
Showing
11 changed files
with
294 additions
and
25 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
src/main/java/bisq/desktop/components/paymentmethods/HalCashForm.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,112 @@ | ||
/* | ||
* 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.util.Layout; | ||
import bisq.desktop.util.validation.HalCashValidator; | ||
|
||
import bisq.core.locale.Res; | ||
import bisq.core.locale.TradeCurrency; | ||
import bisq.core.payment.AccountAgeWitnessService; | ||
import bisq.core.payment.HalCashAccount; | ||
import bisq.core.payment.PaymentAccount; | ||
import bisq.core.payment.payload.HalCashAccountPayload; | ||
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.control.TextField; | ||
import javafx.scene.layout.GridPane; | ||
|
||
import static bisq.desktop.util.FormBuilder.addLabelInputTextField; | ||
import static bisq.desktop.util.FormBuilder.addLabelTextField; | ||
|
||
public class HalCashForm extends PaymentMethodForm { | ||
private final HalCashAccount halCashAccount; | ||
private final HalCashValidator halCashValidator; | ||
private InputTextField mobileNrInputTextField; | ||
|
||
public static int addFormForBuyer(GridPane gridPane, int gridRow, | ||
PaymentAccountPayload paymentAccountPayload) { | ||
addLabelTextField(gridPane, ++gridRow, Res.get("payment.mobile"), | ||
((HalCashAccountPayload) paymentAccountPayload).getMobileNr()); | ||
return gridRow; | ||
} | ||
|
||
public HalCashForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, HalCashValidator halCashValidator, | ||
InputValidator inputValidator, GridPane gridPane, int gridRow, BSFormatter formatter) { | ||
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter); | ||
this.halCashAccount = (HalCashAccount) paymentAccount; | ||
this.halCashValidator = halCashValidator; | ||
} | ||
|
||
@Override | ||
public void addFormForAddAccount() { | ||
gridRowFrom = gridRow + 1; | ||
|
||
mobileNrInputTextField = addLabelInputTextField(gridPane, ++gridRow, | ||
Res.get("payment.mobile")).second; | ||
mobileNrInputTextField.setValidator(halCashValidator); | ||
mobileNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { | ||
halCashAccount.setMobileNr(newValue); | ||
updateFromInputs(); | ||
}); | ||
|
||
TradeCurrency singleTradeCurrency = halCashAccount.getSingleTradeCurrency(); | ||
String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null"; | ||
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("shared.currency"), nameAndCode); | ||
addLimitations(); | ||
addAccountNameTextFieldWithAutoFillCheckBox(); | ||
} | ||
|
||
@Override | ||
protected void autoFillNameTextField() { | ||
if (useCustomAccountNameCheckBox != null && !useCustomAccountNameCheckBox.isSelected()) { | ||
String mobileNr = mobileNrInputTextField.getText(); | ||
mobileNr = StringUtils.abbreviate(mobileNr, 9); | ||
String method = Res.get(paymentAccount.getPaymentMethod().getId()); | ||
accountNameTextField.setText(method.concat(": ").concat(mobileNr)); | ||
} | ||
} | ||
|
||
@Override | ||
public void addFormForDisplayAccount() { | ||
gridRowFrom = gridRow; | ||
addLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), | ||
halCashAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE); | ||
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("shared.paymentMethod"), | ||
Res.get(halCashAccount.getPaymentMethod().getId())); | ||
TextField field = addLabelTextField(gridPane, ++gridRow, Res.get("payment.mobile"), | ||
halCashAccount.getMobileNr()).second; | ||
field.setMouseTransparent(false); | ||
TradeCurrency singleTradeCurrency = halCashAccount.getSingleTradeCurrency(); | ||
String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null"; | ||
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("shared.currency"), nameAndCode); | ||
addLimitations(); | ||
} | ||
|
||
@Override | ||
public void updateAllInputsValid() { | ||
allInputsValid.set(isAccountNameValid() | ||
&& halCashValidator.validate(halCashAccount.getMobileNr()).isValid | ||
&& halCashAccount.getTradeCurrencies().size() > 0); | ||
} | ||
} |
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
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
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.