-
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 #5501 from BtcContributor/capitual
Add Capitual payment method
- Loading branch information
Showing
14 changed files
with
387 additions
and
2 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
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,46 @@ | ||
/* | ||
* 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.core.payment; | ||
|
||
import bisq.core.locale.CurrencyUtil; | ||
import bisq.core.payment.payload.CapitualAccountPayload; | ||
import bisq.core.payment.payload.PaymentAccountPayload; | ||
import bisq.core.payment.payload.PaymentMethod; | ||
|
||
import lombok.EqualsAndHashCode; | ||
|
||
@EqualsAndHashCode(callSuper = true) | ||
public final class CapitualAccount extends PaymentAccount { | ||
public CapitualAccount() { | ||
super(PaymentMethod.CAPITUAL); | ||
tradeCurrencies.addAll(CurrencyUtil.getAllCapitualCurrencies()); | ||
} | ||
|
||
@Override | ||
protected PaymentAccountPayload createPayload() { | ||
return new CapitualAccountPayload(paymentMethod.getId(), id); | ||
} | ||
|
||
public void setAccountNr(String accountNr) { | ||
((CapitualAccountPayload) paymentAccountPayload).setAccountNr(accountNr); | ||
} | ||
|
||
public String getAccountNr() { | ||
return ((CapitualAccountPayload) paymentAccountPayload).getAccountNr(); | ||
} | ||
} |
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
99 changes: 99 additions & 0 deletions
99
core/src/main/java/bisq/core/payment/payload/CapitualAccountPayload.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,99 @@ | ||
/* | ||
* 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.core.payment.payload; | ||
|
||
import bisq.core.locale.Res; | ||
|
||
import com.google.protobuf.Message; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@EqualsAndHashCode(callSuper = true) | ||
@ToString | ||
@Setter | ||
@Getter | ||
@Slf4j | ||
public final class CapitualAccountPayload extends PaymentAccountPayload { | ||
private String accountNr = ""; | ||
|
||
public CapitualAccountPayload(String paymentMethod, String id) { | ||
super(paymentMethod, id); | ||
} | ||
|
||
|
||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
// PROTO BUFFER | ||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
private CapitualAccountPayload(String paymentMethod, | ||
String id, | ||
String accountNr, | ||
long maxTradePeriod, | ||
Map<String, String> excludeFromJsonDataMap) { | ||
super(paymentMethod, | ||
id, | ||
maxTradePeriod, | ||
excludeFromJsonDataMap); | ||
|
||
this.accountNr = accountNr; | ||
} | ||
|
||
@Override | ||
public Message toProtoMessage() { | ||
return getPaymentAccountPayloadBuilder() | ||
.setCapitualAccountPayload(protobuf.CapitualAccountPayload.newBuilder() | ||
.setAccountNr(accountNr)) | ||
.build(); | ||
} | ||
|
||
public static CapitualAccountPayload fromProto(protobuf.PaymentAccountPayload proto) { | ||
return new CapitualAccountPayload(proto.getPaymentMethodId(), | ||
proto.getId(), | ||
proto.getCapitualAccountPayload().getAccountNr(), | ||
proto.getMaxTradePeriod(), | ||
new HashMap<>(proto.getExcludeFromJsonDataMap())); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
// API | ||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
@Override | ||
public String getPaymentDetails() { | ||
return Res.get(paymentMethodId) + " - " + Res.getWithCol("payment.capitual.cap") + " " + accountNr; | ||
} | ||
|
||
@Override | ||
public String getPaymentDetailsForTradePopup() { | ||
return getPaymentDetails(); | ||
} | ||
|
||
@Override | ||
public byte[] getAgeWitnessInputData() { | ||
return super.getAgeWitnessInputData(accountNr.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
} |
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
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
131 changes: 131 additions & 0 deletions
131
desktop/src/main/java/bisq/desktop/components/paymentmethods/CapitualForm.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,131 @@ | ||
/* | ||
* 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.FormBuilder; | ||
import bisq.desktop.util.Layout; | ||
import bisq.desktop.util.validation.CapitualValidator; | ||
|
||
import bisq.core.account.witness.AccountAgeWitnessService; | ||
import bisq.core.locale.CurrencyUtil; | ||
import bisq.core.locale.Res; | ||
import bisq.core.payment.CapitualAccount; | ||
import bisq.core.payment.PaymentAccount; | ||
import bisq.core.payment.payload.CapitualAccountPayload; | ||
import bisq.core.payment.payload.PaymentAccountPayload; | ||
import bisq.core.util.coin.CoinFormatter; | ||
import bisq.core.util.validation.InputValidator; | ||
|
||
import bisq.common.util.Tuple2; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.FlowPane; | ||
import javafx.scene.layout.GridPane; | ||
|
||
import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextField; | ||
import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextFieldWithCopyIcon; | ||
import static bisq.desktop.util.FormBuilder.addTopLabelFlowPane; | ||
|
||
public class CapitualForm extends PaymentMethodForm { | ||
private final CapitualAccount capitualAccount; | ||
private final CapitualValidator capitualValidator; | ||
private InputTextField accountNrInputTextField; | ||
|
||
public static int addFormForBuyer(GridPane gridPane, int gridRow, | ||
PaymentAccountPayload paymentAccountPayload) { | ||
addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.capitual.cap"), | ||
((CapitualAccountPayload) paymentAccountPayload).getAccountNr()); | ||
return gridRow; | ||
} | ||
|
||
public CapitualForm(PaymentAccount paymentAccount, | ||
AccountAgeWitnessService accountAgeWitnessService, | ||
CapitualValidator capitualValidator, | ||
InputValidator inputValidator, | ||
GridPane gridPane, | ||
int gridRow, | ||
CoinFormatter formatter) { | ||
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter); | ||
this.capitualAccount = (CapitualAccount) paymentAccount; | ||
this.capitualValidator = capitualValidator; | ||
} | ||
|
||
@Override | ||
public void addFormForAddAccount() { | ||
gridRowFrom = gridRow + 1; | ||
|
||
accountNrInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.capitual.cap")); | ||
accountNrInputTextField.setValidator(capitualValidator); | ||
accountNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { | ||
capitualAccount.setAccountNr(newValue); | ||
updateFromInputs(); | ||
}); | ||
|
||
addCurrenciesGrid(true); | ||
addLimitations(false); | ||
addAccountNameTextFieldWithAutoFillToggleButton(); | ||
} | ||
|
||
private void addCurrenciesGrid(boolean isEditable) { | ||
final Tuple2<Label, FlowPane> labelFlowPaneTuple2 = addTopLabelFlowPane(gridPane, ++gridRow, Res.get("payment.supportedCurrencies"), 0); | ||
|
||
FlowPane flowPane = labelFlowPaneTuple2.second; | ||
|
||
if (isEditable) | ||
flowPane.setId("flow-pane-checkboxes-bg"); | ||
else | ||
flowPane.setId("flow-pane-checkboxes-non-editable-bg"); | ||
|
||
CurrencyUtil.getAllCapitualCurrencies().forEach(e -> | ||
fillUpFlowPaneWithCurrencies(isEditable, flowPane, e, capitualAccount)); | ||
} | ||
|
||
@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; | ||
addCompactTopLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), | ||
capitualAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE); | ||
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.paymentMethod"), | ||
Res.get(capitualAccount.getPaymentMethod().getId())); | ||
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.capitual.cap"), | ||
capitualAccount.getAccountNr()); | ||
addLimitations(true); | ||
addCurrenciesGrid(false); | ||
} | ||
|
||
@Override | ||
public void updateAllInputsValid() { | ||
allInputsValid.set(isAccountNameValid() | ||
&& capitualValidator.validate(capitualAccount.getAccountNr()).isValid | ||
&& !capitualAccount.getTradeCurrencies().isEmpty()); | ||
} | ||
|
||
} |
Oops, something went wrong.