forked from bisq-network/bisq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
321 additions
and
0 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
46 changes: 46 additions & 0 deletions
46
core/src/main/java/bisq/core/payment/PromptPayAccount.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,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.FiatCurrency; | ||
import bisq.core.payment.payload.PaymentAccountPayload; | ||
import bisq.core.payment.payload.PaymentMethod; | ||
import bisq.core.payment.payload.PromptPayAccountPayload; | ||
|
||
import lombok.EqualsAndHashCode; | ||
|
||
@EqualsAndHashCode(callSuper = true) | ||
public final class PromptPayAccount extends PaymentAccount { | ||
public PromptPayAccount() { | ||
super(PaymentMethod.PROMPT_PAY); | ||
setSingleTradeCurrency(new FiatCurrency("THB")); | ||
} | ||
|
||
@Override | ||
protected PaymentAccountPayload createPayload() { | ||
return new PromptPayAccountPayload(paymentMethod.getId(), id); | ||
} | ||
|
||
public void setPromptPayId(String promptPayId) { | ||
((PromptPayAccountPayload) paymentAccountPayload).setPromptPayId(promptPayId); | ||
} | ||
|
||
public String getPromptPayId() { | ||
return ((PromptPayAccountPayload) paymentAccountPayload).getPromptPayId(); | ||
} | ||
} |
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
103 changes: 103 additions & 0 deletions
103
core/src/main/java/bisq/core/payment/payload/PromptPayAccountPayload.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,103 @@ | ||
/* | ||
* 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 io.bisq.generated.protobuffer.PB; | ||
|
||
import com.google.protobuf.Message; | ||
|
||
import org.springframework.util.CollectionUtils; | ||
|
||
import java.nio.charset.Charset; | ||
|
||
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; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
@EqualsAndHashCode(callSuper = true) | ||
@ToString | ||
@Setter | ||
@Getter | ||
@Slf4j | ||
public final class PromptPayAccountPayload extends PaymentAccountPayload { | ||
private String promptPayId = ""; | ||
|
||
public PromptPayAccountPayload(String paymentMethod, String id) { | ||
super(paymentMethod, id); | ||
} | ||
|
||
|
||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
// PROTO BUFFER | ||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
private PromptPayAccountPayload(String paymentMethod, String id, | ||
String promptPayId, | ||
long maxTradePeriod, | ||
@Nullable Map<String, String> excludeFromJsonDataMap) { | ||
super(paymentMethod, | ||
id, | ||
maxTradePeriod, | ||
excludeFromJsonDataMap); | ||
|
||
this.promptPayId = promptPayId; | ||
} | ||
|
||
@Override | ||
public Message toProtoMessage() { | ||
return getPaymentAccountPayloadBuilder() | ||
.setPromptPayAccountPayload(PB.PromptPayAccountPayload.newBuilder() | ||
.setPromptPayId(promptPayId)) | ||
.build(); | ||
} | ||
|
||
public static PromptPayAccountPayload fromProto(PB.PaymentAccountPayload proto) { | ||
return new PromptPayAccountPayload(proto.getPaymentMethodId(), | ||
proto.getId(), | ||
proto.getPromptPayAccountPayload().getPromptPayId(), | ||
proto.getMaxTradePeriod(), | ||
CollectionUtils.isEmpty(proto.getExcludeFromJsonDataMap()) ? null : new HashMap<>(proto.getExcludeFromJsonDataMap())); | ||
} | ||
|
||
|
||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
// API | ||
/////////////////////////////////////////////////////////////////////////////////////////// | ||
|
||
@Override | ||
public String getPaymentDetails() { | ||
return "PromptPay ID: " + promptPayId; | ||
} | ||
|
||
@Override | ||
public String getPaymentDetailsForTradePopup() { | ||
return getPaymentDetails(); | ||
} | ||
|
||
@Override | ||
public byte[] getAgeWitnessInputData() { | ||
return super.getAgeWitnessInputData(promptPayId.getBytes(Charset.forName("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
112 changes: 112 additions & 0 deletions
112
desktop/src/main/java/bisq/desktop/components/paymentmethods/PromptPayForm.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.PromptPayValidator; | ||
|
||
import bisq.core.locale.Res; | ||
import bisq.core.locale.TradeCurrency; | ||
import bisq.core.payment.AccountAgeWitnessService; | ||
import bisq.core.payment.PromptPayAccount; | ||
import bisq.core.payment.PaymentAccount; | ||
import bisq.core.payment.payload.PromptPayAccountPayload; | ||
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 PromptPayForm extends PaymentMethodForm { | ||
private final PromptPayAccount promptPayAccount; | ||
private final PromptPayValidator promptPayValidator; | ||
private InputTextField promptPayIdInputTextField; | ||
|
||
public static int addFormForBuyer(GridPane gridPane, int gridRow, | ||
PaymentAccountPayload paymentAccountPayload) { | ||
addLabelTextField(gridPane, ++gridRow, Res.get("payment.promptPay.promptPayId"), | ||
((PromptPayAccountPayload) paymentAccountPayload).getPromptPayId()); | ||
return gridRow; | ||
} | ||
|
||
public PromptPayForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, PromptPayValidator promptPayValidator, | ||
InputValidator inputValidator, GridPane gridPane, int gridRow, BSFormatter formatter) { | ||
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter); | ||
this.promptPayAccount = (PromptPayAccount) paymentAccount; | ||
this.promptPayValidator = promptPayValidator; | ||
} | ||
|
||
@Override | ||
public void addFormForAddAccount() { | ||
gridRowFrom = gridRow + 1; | ||
|
||
promptPayIdInputTextField = addLabelInputTextField(gridPane, ++gridRow, | ||
Res.get("payment.promptPay.promptPayId")).second; | ||
promptPayIdInputTextField.setValidator(promptPayValidator); | ||
promptPayIdInputTextField.textProperty().addListener((ov, oldValue, newValue) -> { | ||
promptPayAccount.setPromptPayId(newValue); | ||
updateFromInputs(); | ||
}); | ||
|
||
TradeCurrency singleTradeCurrency = promptPayAccount.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 promptPayId = promptPayIdInputTextField.getText(); | ||
promptPayId = StringUtils.abbreviate(promptPayId, 9); | ||
String method = Res.get(paymentAccount.getPaymentMethod().getId()); | ||
accountNameTextField.setText(method.concat(": ").concat(promptPayId)); | ||
} | ||
} | ||
|
||
@Override | ||
public void addFormForDisplayAccount() { | ||
gridRowFrom = gridRow; | ||
addLabelTextField(gridPane, gridRow, Res.get("payment.account.name"), | ||
promptPayAccount.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE); | ||
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("shared.paymentMethod"), | ||
Res.get(promptPayAccount.getPaymentMethod().getId())); | ||
TextField field = addLabelTextField(gridPane, ++gridRow, Res.get("payment.promptPay.promptPayId"), | ||
promptPayAccount.getPromptPayId()).second; | ||
field.setMouseTransparent(false); | ||
TradeCurrency singleTradeCurrency = promptPayAccount.getSingleTradeCurrency(); | ||
String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null"; | ||
addLabelTextField(gridPane, ++gridRow, Res.getWithCol("shared.currency"), nameAndCode); | ||
addLimitations(); | ||
} | ||
|
||
@Override | ||
public void updateAllInputsValid() { | ||
allInputsValid.set(isAccountNameValid() | ||
&& promptPayValidator.validate(promptPayAccount.getPromptPayId()).isValid | ||
&& promptPayAccount.getTradeCurrencies().size() > 0); | ||
} | ||
} |
Oops, something went wrong.