From 8bf8144709fd550c0d7395d920de97c161156f54 Mon Sep 17 00:00:00 2001 From: walkerp07 Date: Sat, 6 Jul 2024 20:01:54 -0400 Subject: [PATCH] Add an "extra_info" text area for PayPal --- .../main/java/haveno/core/offer/Offer.java | 2 ++ .../java/haveno/core/offer/OfferPayload.java | 1 + .../java/haveno/core/offer/OfferUtil.java | 6 ++++ .../haveno/core/payment/PayPalAccount.java | 9 ++++++ .../payment/payload/PayPalAccountPayload.java | 11 +++++-- .../components/paymentmethods/PayPalForm.java | 29 ++++++++++++++++++- .../main/offer/takeoffer/TakeOfferView.java | 21 +++++++++++++- .../overlays/windows/OfferDetailsWindow.java | 5 +++- proto/src/main/proto/pb.proto | 1 + 9 files changed, 79 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/haveno/core/offer/Offer.java b/core/src/main/java/haveno/core/offer/Offer.java index 5c2f6eb51b..63d9fd022e 100644 --- a/core/src/main/java/haveno/core/offer/Offer.java +++ b/core/src/main/java/haveno/core/offer/Offer.java @@ -410,6 +410,8 @@ public class Offer implements NetworkPayload, PersistablePayload { return getExtraDataMap().get(OfferPayload.PAY_BY_MAIL_EXTRA_INFO); else if (getExtraDataMap() != null && getExtraDataMap().containsKey(OfferPayload.AUSTRALIA_PAYID_EXTRA_INFO)) return getExtraDataMap().get(OfferPayload.AUSTRALIA_PAYID_EXTRA_INFO); + else if (getExtraDataMap() != null && getExtraDataMap().containsKey(OfferPayload.PAYPAL_EXTRA_INFO)) + return getExtraDataMap().get(OfferPayload.PAYPAL_EXTRA_INFO); else return ""; } diff --git a/core/src/main/java/haveno/core/offer/OfferPayload.java b/core/src/main/java/haveno/core/offer/OfferPayload.java index 1a194a1a98..6f69dbebf8 100644 --- a/core/src/main/java/haveno/core/offer/OfferPayload.java +++ b/core/src/main/java/haveno/core/offer/OfferPayload.java @@ -100,6 +100,7 @@ public final class OfferPayload implements ProtectedStoragePayload, ExpirablePay public static final String F2F_EXTRA_INFO = "f2fExtraInfo"; public static final String PAY_BY_MAIL_EXTRA_INFO = "payByMailExtraInfo"; public static final String AUSTRALIA_PAYID_EXTRA_INFO = "australiaPayidExtraInfo"; + public static final String PAYPAL_EXTRA_INFO = "paypalExtraInfo"; // Comma separated list of ordinal of a haveno.common.app.Capability. E.g. ordinal of // Capability.SIGNED_ACCOUNT_AGE_WITNESS is 11 and Capability.MEDIATION is 12 so if we want to signal that maker diff --git a/core/src/main/java/haveno/core/offer/OfferUtil.java b/core/src/main/java/haveno/core/offer/OfferUtil.java index 6d314fe2f2..a097bf9609 100644 --- a/core/src/main/java/haveno/core/offer/OfferUtil.java +++ b/core/src/main/java/haveno/core/offer/OfferUtil.java @@ -40,6 +40,7 @@ import static haveno.core.offer.OfferPayload.CAPABILITIES; import static haveno.core.offer.OfferPayload.F2F_CITY; import static haveno.core.offer.OfferPayload.F2F_EXTRA_INFO; import static haveno.core.offer.OfferPayload.PAY_BY_MAIL_EXTRA_INFO; +import static haveno.core.offer.OfferPayload.PAYPAL_EXTRA_INFO; import static haveno.core.offer.OfferPayload.REFERRAL_ID; import static haveno.core.offer.OfferPayload.XMR_AUTO_CONF; import static haveno.core.offer.OfferPayload.XMR_AUTO_CONF_ENABLED_VALUE; @@ -47,6 +48,7 @@ import static haveno.core.offer.OfferPayload.XMR_AUTO_CONF_ENABLED_VALUE; import haveno.core.payment.AustraliaPayidAccount; import haveno.core.payment.F2FAccount; import haveno.core.payment.PayByMailAccount; +import haveno.core.payment.PayPalAccount; import haveno.core.payment.PaymentAccount; import haveno.core.provider.price.MarketPrice; import haveno.core.provider.price.PriceFeedService; @@ -200,6 +202,10 @@ public class OfferUtil { extraDataMap.put(PAY_BY_MAIL_EXTRA_INFO, ((PayByMailAccount) paymentAccount).getExtraInfo()); } + if (paymentAccount instanceof PayPalAccount) { + extraDataMap.put(PAYPAL_EXTRA_INFO, ((PayPalAccount) paymentAccount).getExtraInfo()); + } + if (paymentAccount instanceof AustraliaPayidAccount) { extraDataMap.put(AUSTRALIA_PAYID_EXTRA_INFO, ((AustraliaPayidAccount) paymentAccount).getExtraInfo()); } diff --git a/core/src/main/java/haveno/core/payment/PayPalAccount.java b/core/src/main/java/haveno/core/payment/PayPalAccount.java index 04c8a36430..c7ec15183a 100644 --- a/core/src/main/java/haveno/core/payment/PayPalAccount.java +++ b/core/src/main/java/haveno/core/payment/PayPalAccount.java @@ -62,6 +62,7 @@ public final class PayPalAccount extends PaymentAccount { PaymentAccountFormField.FieldId.EMAIL_OR_MOBILE_NR_OR_USERNAME, PaymentAccountFormField.FieldId.TRADE_CURRENCIES, PaymentAccountFormField.FieldId.ACCOUNT_NAME, + PaymentAccountFormField.FieldId.EXTRA_INFO, PaymentAccountFormField.FieldId.SALT); public PayPalAccount() { @@ -91,4 +92,12 @@ public final class PayPalAccount extends PaymentAccount { public String getEmailOrMobileNrOrUsername() { return ((PayPalAccountPayload) paymentAccountPayload).getEmailOrMobileNrOrUsername(); } + + public void setExtraInfo(String extraInfo) { + ((PayPalAccountPayload) paymentAccountPayload).setExtraInfo(extraInfo); + } + + public String getExtraInfo() { + return ((PayPalAccountPayload) paymentAccountPayload).getExtraInfo(); + } } diff --git a/core/src/main/java/haveno/core/payment/payload/PayPalAccountPayload.java b/core/src/main/java/haveno/core/payment/payload/PayPalAccountPayload.java index 31765f49a0..76e4f87814 100644 --- a/core/src/main/java/haveno/core/payment/payload/PayPalAccountPayload.java +++ b/core/src/main/java/haveno/core/payment/payload/PayPalAccountPayload.java @@ -36,6 +36,7 @@ import java.util.Map; @Slf4j public final class PayPalAccountPayload extends PaymentAccountPayload { private String emailOrMobileNrOrUsername = ""; + private String extraInfo = ""; public PayPalAccountPayload(String paymentMethod, String id) { super(paymentMethod, id); @@ -48,6 +49,7 @@ public final class PayPalAccountPayload extends PaymentAccountPayload { private PayPalAccountPayload(String paymentMethod, String id, String emailOrMobileNrOrUsername, + String extraInfo, long maxTradePeriod, Map excludeFromJsonDataMap) { super(paymentMethod, @@ -56,13 +58,15 @@ public final class PayPalAccountPayload extends PaymentAccountPayload { excludeFromJsonDataMap); this.emailOrMobileNrOrUsername = emailOrMobileNrOrUsername; + this.extraInfo = extraInfo; } @Override public Message toProtoMessage() { return getPaymentAccountPayloadBuilder() .setPaypalAccountPayload(protobuf.PayPalAccountPayload.newBuilder() - .setEmailOrMobileNrOrUsername(emailOrMobileNrOrUsername)) + .setExtraInfo(extraInfo) + .setEmailOrMobileNrOrUsername(emailOrMobileNrOrUsername)) .build(); } @@ -70,6 +74,7 @@ public final class PayPalAccountPayload extends PaymentAccountPayload { return new PayPalAccountPayload(proto.getPaymentMethodId(), proto.getId(), proto.getPaypalAccountPayload().getEmailOrMobileNrOrUsername(), + proto.getPaypalAccountPayload().getExtraInfo(), proto.getMaxTradePeriod(), new HashMap<>(proto.getExcludeFromJsonDataMap())); } @@ -80,8 +85,8 @@ public final class PayPalAccountPayload extends PaymentAccountPayload { @Override public String getPaymentDetails() { - return Res.getWithCol("payment.email.mobile.username") + " " - + emailOrMobileNrOrUsername; + return Res.getWithCol("payment.email.mobile.username") + " "+ emailOrMobileNrOrUsername + "\n" + + Res.getWithCol("payment.shared.extraInfo") + " " + extraInfo+ "\n"; } @Override diff --git a/desktop/src/main/java/haveno/desktop/components/paymentmethods/PayPalForm.java b/desktop/src/main/java/haveno/desktop/components/paymentmethods/PayPalForm.java index b3c9833dfd..e382b4213d 100644 --- a/desktop/src/main/java/haveno/desktop/components/paymentmethods/PayPalForm.java +++ b/desktop/src/main/java/haveno/desktop/components/paymentmethods/PayPalForm.java @@ -17,6 +17,7 @@ package haveno.desktop.components.paymentmethods; +import com.jfoenix.controls.JFXTextArea; import haveno.core.account.witness.AccountAgeWitnessService; import haveno.core.locale.Res; import haveno.core.payment.PayPalAccount; @@ -29,13 +30,16 @@ import haveno.core.util.validation.InputValidator; import haveno.desktop.components.InputTextField; import haveno.desktop.util.FormBuilder; import haveno.desktop.util.Layout; +import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.layout.FlowPane; import javafx.scene.layout.GridPane; -import static haveno.desktop.util.FormBuilder.addCompactTopLabelTextField; import static haveno.desktop.util.FormBuilder.addCompactTopLabelTextFieldWithCopyIcon; +import static haveno.desktop.util.FormBuilder.addCompactTopLabelTextArea; +import static haveno.desktop.util.FormBuilder.addTopLabelTextArea; import static haveno.desktop.util.FormBuilder.addTopLabelFlowPane; +import static haveno.desktop.util.FormBuilder.addCompactTopLabelTextField; public class PayPalForm extends PaymentMethodForm { private final PayPalAccount paypalAccount; @@ -43,6 +47,13 @@ public class PayPalForm extends PaymentMethodForm { public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) { addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.email.mobile.username"), ((PayPalAccountPayload) paymentAccountPayload).getEmailOrMobileNrOrUsername()); + + PayPalAccountPayload payId = (PayPalAccountPayload) paymentAccountPayload; + TextArea textExtraInfo = addCompactTopLabelTextArea(gridPane, gridRow, 1, Res.get("payment.shared.extraInfo"), "").second; + textExtraInfo.setMinHeight(70); + textExtraInfo.setEditable(false); + textExtraInfo.setText(payId.getExtraInfo()); + return gridRow; } @@ -66,6 +77,16 @@ public class PayPalForm extends PaymentMethodForm { paypalAccount.setEmailOrMobileNrOrUsername(newValue.trim()); updateFromInputs(); }); + + TextArea extraTextArea = addTopLabelTextArea(gridPane, ++gridRow, + Res.get("payment.shared.optionalExtra"), Res.get("payment.shared.extraInfo.prompt")).second; + extraTextArea.setMinHeight(70); + ((JFXTextArea) extraTextArea).setLabelFloat(false); + extraTextArea.textProperty().addListener((ov, oldValue, newValue) -> { + paypalAccount.setExtraInfo(newValue); + updateFromInputs(); + }); + addCurrenciesGrid(true); addLimitations(false); addAccountNameTextFieldWithAutoFillToggleButton(); @@ -99,6 +120,12 @@ public class PayPalForm extends PaymentMethodForm { TextField field = addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.email.mobile.username"), paypalAccount.getEmailOrMobileNrOrUsername()).second; + + TextArea textAreaExtra = addCompactTopLabelTextArea(gridPane, ++gridRow, Res.get("payment.shared.extraInfo"), "").second; + textAreaExtra.setText(paypalAccount.getExtraInfo()); + textAreaExtra.setMinHeight(70); + textAreaExtra.setEditable(false); + field.setMouseTransparent(false); addLimitations(true); addCurrenciesGrid(false); diff --git a/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferView.java b/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferView.java index 2b8899c3e3..e64e1a6ae0 100644 --- a/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferView.java +++ b/desktop/src/main/java/haveno/desktop/main/offer/takeoffer/TakeOfferView.java @@ -158,7 +158,8 @@ public class TakeOfferView extends ActivatableViewAndModel paymentAccountWarningDisplayed = new HashMap<>(); private boolean offerDetailsWindowDisplayed, zelleWarningDisplayed, fasterPaymentsWarningDisplayed, - takeOfferFromUnsignedAccountWarningDisplayed, payByMailWarningDisplayed, cashAtAtmWarningDisplayed, australiaPayidWarningDisplayed; + takeOfferFromUnsignedAccountWarningDisplayed, payByMailWarningDisplayed, cashAtAtmWarningDisplayed, + australiaPayidWarningDisplayed, paypalWarningDisplayed; private SimpleBooleanProperty errorPopupDisplayed; private ChangeListener amountFocusedListener, getShowWalletFundedNotificationListener; @@ -268,6 +269,7 @@ public class TakeOfferView extends ActivatableViewAndModel { + new GenericMessageWindow() + .preamble(Res.get("payment.tradingRestrictions")) + .instruction(offer.getExtraInfo()) + .actionButtonText(Res.get("shared.iConfirm")) + .closeButtonText(Res.get("shared.close")) + .width(Layout.INITIAL_WINDOW_WIDTH) + .onClose(() -> close(false)) + .show(); + }, 500, TimeUnit.MILLISECONDS); + } + } + private Tuple2 getTradeInputBox(HBox amountValueBox, String promptText) { Label descriptionLabel = new AutoTooltipLabel(promptText); descriptionLabel.setId("input-description-label"); diff --git a/desktop/src/main/java/haveno/desktop/main/overlays/windows/OfferDetailsWindow.java b/desktop/src/main/java/haveno/desktop/main/overlays/windows/OfferDetailsWindow.java index 0692162eb4..30ed30e0df 100644 --- a/desktop/src/main/java/haveno/desktop/main/overlays/windows/OfferDetailsWindow.java +++ b/desktop/src/main/java/haveno/desktop/main/overlays/windows/OfferDetailsWindow.java @@ -174,7 +174,10 @@ public class OfferDetailsWindow extends Overlay { List acceptedCountryCodes = offer.getAcceptedCountryCodes(); boolean showAcceptedCountryCodes = acceptedCountryCodes != null && !acceptedCountryCodes.isEmpty(); boolean isF2F = offer.getPaymentMethod().equals(PaymentMethod.F2F); - boolean showExtraInfo = offer.getPaymentMethod().equals(PaymentMethod.F2F) || offer.getPaymentMethod().equals(PaymentMethod.PAY_BY_MAIL) || offer.getPaymentMethod().equals(PaymentMethod.AUSTRALIA_PAYID); + boolean showExtraInfo = offer.getPaymentMethod().equals(PaymentMethod.F2F) || + offer.getPaymentMethod().equals(PaymentMethod.PAY_BY_MAIL) || + offer.getPaymentMethod().equals(PaymentMethod.AUSTRALIA_PAYID)|| + offer.getPaymentMethod().equals(PaymentMethod.PAYPAL_ID); if (!takeOfferHandlerOptional.isPresent()) rows++; if (showAcceptedBanks) diff --git a/proto/src/main/proto/pb.proto b/proto/src/main/proto/pb.proto index 8e988bbe57..f50bebfb07 100644 --- a/proto/src/main/proto/pb.proto +++ b/proto/src/main/proto/pb.proto @@ -1072,6 +1072,7 @@ message VenmoAccountPayload { } message PayPalAccountPayload { string email_or_mobile_nr_or_username = 1; + string extra_info = 2; } message PopmoneyAccountPayload {