Skip to content

Commit

Permalink
Add an "extra_info" text area for PayPal
Browse files Browse the repository at this point in the history
  • Loading branch information
wp07e authored and woodser committed Jul 8, 2024
1 parent 31ce183 commit 8bf8144
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 6 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/haveno/core/offer/Offer.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,8 @@ else if (getExtraDataMap() != null && getExtraDataMap().containsKey(OfferPayload
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 "";
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/haveno/core/offer/OfferPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/haveno/core/offer/OfferUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@
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;

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;
Expand Down Expand Up @@ -200,6 +202,10 @@ public Map<String, String> getExtraDataMap(PaymentAccount paymentAccount,
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());
}
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/haveno/core/payment/PayPalAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -91,4 +92,12 @@ public void setEmailOrMobileNrOrUsername(String emailOrMobileNrOrUsername) {
public String getEmailOrMobileNrOrUsername() {
return ((PayPalAccountPayload) paymentAccountPayload).getEmailOrMobileNrOrUsername();
}

public void setExtraInfo(String extraInfo) {
((PayPalAccountPayload) paymentAccountPayload).setExtraInfo(extraInfo);
}

public String getExtraInfo() {
return ((PayPalAccountPayload) paymentAccountPayload).getExtraInfo();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@Slf4j
public final class PayPalAccountPayload extends PaymentAccountPayload {
private String emailOrMobileNrOrUsername = "";
private String extraInfo = "";

public PayPalAccountPayload(String paymentMethod, String id) {
super(paymentMethod, id);
Expand All @@ -48,6 +49,7 @@ public PayPalAccountPayload(String paymentMethod, String id) {
private PayPalAccountPayload(String paymentMethod,
String id,
String emailOrMobileNrOrUsername,
String extraInfo,
long maxTradePeriod,
Map<String, String> excludeFromJsonDataMap) {
super(paymentMethod,
Expand All @@ -56,20 +58,23 @@ private PayPalAccountPayload(String paymentMethod,
excludeFromJsonDataMap);

this.emailOrMobileNrOrUsername = emailOrMobileNrOrUsername;
this.extraInfo = extraInfo;
}

@Override
public Message toProtoMessage() {
return getPaymentAccountPayloadBuilder()
.setPaypalAccountPayload(protobuf.PayPalAccountPayload.newBuilder()
.setEmailOrMobileNrOrUsername(emailOrMobileNrOrUsername))
.setExtraInfo(extraInfo)
.setEmailOrMobileNrOrUsername(emailOrMobileNrOrUsername))
.build();
}

public static PayPalAccountPayload fromProto(protobuf.PaymentAccountPayload proto) {
return new PayPalAccountPayload(proto.getPaymentMethodId(),
proto.getId(),
proto.getPaypalAccountPayload().getEmailOrMobileNrOrUsername(),
proto.getPaypalAccountPayload().getExtraInfo(),
proto.getMaxTradePeriod(),
new HashMap<>(proto.getExcludeFromJsonDataMap()));
}
Expand All @@ -80,8 +85,8 @@ public static PayPalAccountPayload fromProto(protobuf.PaymentAccountPayload prot

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,20 +30,30 @@
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;
private final EmailOrMobileNrOrUsernameValidator paypalValidator;

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;
}

Expand All @@ -66,6 +77,16 @@ public void addFormForAddAccount() {
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();
Expand Down Expand Up @@ -99,6 +120,12 @@ public void addFormForEditAccount() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
private int gridRow = 0;
private final HashMap<String, Boolean> paymentAccountWarningDisplayed = new HashMap<>();
private boolean offerDetailsWindowDisplayed, zelleWarningDisplayed, fasterPaymentsWarningDisplayed,
takeOfferFromUnsignedAccountWarningDisplayed, payByMailWarningDisplayed, cashAtAtmWarningDisplayed, australiaPayidWarningDisplayed;
takeOfferFromUnsignedAccountWarningDisplayed, payByMailWarningDisplayed, cashAtAtmWarningDisplayed,
australiaPayidWarningDisplayed, paypalWarningDisplayed;
private SimpleBooleanProperty errorPopupDisplayed;
private ChangeListener<Boolean> amountFocusedListener, getShowWalletFundedNotificationListener;

Expand Down Expand Up @@ -268,6 +269,7 @@ protected void activate() {
maybeShowPayByMailWarning(lastPaymentAccount, model.dataModel.getOffer());
maybeShowCashAtAtmWarning(lastPaymentAccount, model.dataModel.getOffer());
maybeShowAustraliaPayidWarning(lastPaymentAccount, model.dataModel.getOffer());
maybeShowPaypalWarning(lastPaymentAccount, model.dataModel.getOffer());

if (!model.isRange()) {
nextButton.setVisible(false);
Expand Down Expand Up @@ -1157,6 +1159,23 @@ private void maybeShowAustraliaPayidWarning(PaymentAccount paymentAccount, Offer
}
}

private void maybeShowPaypalWarning(PaymentAccount paymentAccount, Offer offer) {
if (paymentAccount.getPaymentMethod().getId().equals(PaymentMethod.PAYPAL_ID) &&
!paypalWarningDisplayed && !offer.getExtraInfo().isEmpty()) {
paypalWarningDisplayed = true;
UserThread.runAfter(() -> {
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<Label, VBox> getTradeInputBox(HBox amountValueBox, String promptText) {
Label descriptionLabel = new AutoTooltipLabel(promptText);
descriptionLabel.setId("input-description-label");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ private void addContent() {
List<String> 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)
Expand Down
1 change: 1 addition & 0 deletions proto/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,7 @@ message VenmoAccountPayload {
}
message PayPalAccountPayload {
string email_or_mobile_nr_or_username = 1;
string extra_info = 2;
}

message PopmoneyAccountPayload {
Expand Down

0 comments on commit 8bf8144

Please sign in to comment.