Skip to content

Commit

Permalink
Add an "extra_info" text area for CashApp
Browse files Browse the repository at this point in the history
  • Loading branch information
wp07e authored and woodser committed Jul 8, 2024
1 parent 8bf8144 commit 05b0072
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 4 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 @@ -412,6 +412,8 @@ else if (getExtraDataMap() != null && getExtraDataMap().containsKey(OfferPayload
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 if (getExtraDataMap() != null && getExtraDataMap().containsKey(OfferPayload.CASHAPP_EXTRA_INFO))
return getExtraDataMap().get(OfferPayload.CASHAPP_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 @@ -94,6 +94,7 @@ public final class OfferPayload implements ProtectedStoragePayload, ExpirablePay
// Keys for extra map
// Only set for traditional offers
public static final String ACCOUNT_AGE_WITNESS_HASH = "accountAgeWitnessHash";
public static final String CASHAPP_EXTRA_INFO = "cashAppExtraInfo";
public static final String REFERRAL_ID = "referralId";
// Only used in payment method F2F
public static final String F2F_CITY = "f2fCity";
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 @@ -37,6 +37,7 @@
import static haveno.core.offer.OfferPayload.ACCOUNT_AGE_WITNESS_HASH;
import static haveno.core.offer.OfferPayload.AUSTRALIA_PAYID_EXTRA_INFO;
import static haveno.core.offer.OfferPayload.CAPABILITIES;
import static haveno.core.offer.OfferPayload.CASHAPP_EXTRA_INFO;
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;
Expand All @@ -46,6 +47,7 @@
import static haveno.core.offer.OfferPayload.XMR_AUTO_CONF_ENABLED_VALUE;

import haveno.core.payment.AustraliaPayidAccount;
import haveno.core.payment.CashAppAccount;
import haveno.core.payment.F2FAccount;
import haveno.core.payment.PayByMailAccount;
import haveno.core.payment.PayPalAccount;
Expand Down Expand Up @@ -206,6 +208,10 @@ public Map<String, String> getExtraDataMap(PaymentAccount paymentAccount,
extraDataMap.put(PAYPAL_EXTRA_INFO, ((PayPalAccount) paymentAccount).getExtraInfo());
}

if (paymentAccount instanceof CashAppAccount) {
extraDataMap.put(CASHAPP_EXTRA_INFO, ((CashAppAccount) 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/CashAppAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public final class CashAppAccount extends PaymentAccount {
PaymentAccountFormField.FieldId.EMAIL_OR_MOBILE_NR_OR_CASHTAG,
PaymentAccountFormField.FieldId.TRADE_CURRENCIES,
PaymentAccountFormField.FieldId.ACCOUNT_NAME,
PaymentAccountFormField.FieldId.EXTRA_INFO,
PaymentAccountFormField.FieldId.SALT);

public CashAppAccount() {
Expand Down Expand Up @@ -67,4 +68,12 @@ public void setEmailOrMobileNrOrCashtag(String emailOrMobileNrOrCashtag) {
public String getEmailOrMobileNrOrCashtag() {
return ((CashAppAccountPayload) paymentAccountPayload).getEmailOrMobileNrOrCashtag();
}

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

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

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

this.emailOrMobileNrOrCashtag = emailOrMobileNrOrCashtag;
this.extraInfo = extraInfo;
}

@Override
public Message toProtoMessage() {
return getPaymentAccountPayloadBuilder()
.setCashAppAccountPayload(protobuf.CashAppAccountPayload.newBuilder()
.setEmailOrMobileNrOrCashtag(emailOrMobileNrOrCashtag))
.setExtraInfo(extraInfo)
.setEmailOrMobileNrOrCashtag(emailOrMobileNrOrCashtag))
.build();
}

public static CashAppAccountPayload fromProto(protobuf.PaymentAccountPayload proto) {
return new CashAppAccountPayload(proto.getPaymentMethodId(),
proto.getId(),
proto.getCashAppAccountPayload().getEmailOrMobileNrOrCashtag(),
proto.getCashAppAccountPayload().getExtraInfo(),
proto.getMaxTradePeriod(),
new HashMap<>(proto.getExcludeFromJsonDataMap()));
}
Expand All @@ -81,7 +86,10 @@ public static CashAppAccountPayload fromProto(protobuf.PaymentAccountPayload pro

@Override
public String getPaymentDetails() {
return Res.get(paymentMethodId) + " - " + Res.getWithCol("payment.email.mobile.cashtag") + " " + emailOrMobileNrOrCashtag;
return Res.get(paymentMethodId) + " - " +
Res.getWithCol("payment.email.mobile.cashtag") +
" " + emailOrMobileNrOrCashtag + "\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.CashAppAccount;
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.addTopLabelFlowPane;
import static haveno.desktop.util.FormBuilder.addCompactTopLabelTextArea;
import static haveno.desktop.util.FormBuilder.addTopLabelTextArea;

public class CashAppForm extends PaymentMethodForm {
private final CashAppAccount cashAppAccount;
private final EmailOrMobileNrOrCashtagValidator cashAppValidator;

public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) {
addCompactTopLabelTextFieldWithCopyIcon(gridPane, ++gridRow, Res.get("payment.email.mobile.cashtag"), ((CashAppAccountPayload) paymentAccountPayload).getEmailOrMobileNrOrCashtag());

CashAppAccountPayload payId = (CashAppAccountPayload) 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() {
cashAppAccount.setEmailOrMobileNrOrCashtag(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) -> {
cashAppAccount.setExtraInfo(newValue);
updateFromInputs();
});

addCurrenciesGrid(true);
addLimitations(false);
addAccountNameTextFieldWithAutoFillToggleButton();
Expand Down Expand Up @@ -96,6 +117,12 @@ public void addFormForEditAccount() {
addAccountNameTextFieldWithAutoFillToggleButton();
TextField field = addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.email.mobile.cashtag"),
cashAppAccount.getEmailOrMobileNrOrCashtag()).second;

TextArea textAreaExtra = addCompactTopLabelTextArea(gridPane, ++gridRow, Res.get("payment.shared.extraInfo"), "").second;
textAreaExtra.setText(cashAppAccount.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 @@ -159,7 +159,7 @@ public class TakeOfferView extends ActivatableViewAndModel<AnchorPane, TakeOffer
private final HashMap<String, Boolean> paymentAccountWarningDisplayed = new HashMap<>();
private boolean offerDetailsWindowDisplayed, zelleWarningDisplayed, fasterPaymentsWarningDisplayed,
takeOfferFromUnsignedAccountWarningDisplayed, payByMailWarningDisplayed, cashAtAtmWarningDisplayed,
australiaPayidWarningDisplayed, paypalWarningDisplayed;
australiaPayidWarningDisplayed, paypalWarningDisplayed, cashAppWarningDisplayed;
private SimpleBooleanProperty errorPopupDisplayed;
private ChangeListener<Boolean> amountFocusedListener, getShowWalletFundedNotificationListener;

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

if (!model.isRange()) {
nextButton.setVisible(false);
Expand Down Expand Up @@ -1176,6 +1177,23 @@ private void maybeShowPaypalWarning(PaymentAccount paymentAccount, Offer offer)
}
}

private void maybeShowCashAppWarning(PaymentAccount paymentAccount, Offer offer) {
if (paymentAccount.getPaymentMethod().getId().equals(PaymentMethod.CASH_APP_ID) &&
!cashAppWarningDisplayed && !offer.getExtraInfo().isEmpty()) {
cashAppWarningDisplayed = 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 @@ -177,7 +177,8 @@ private void addContent() {
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);
offer.getPaymentMethod().equals(PaymentMethod.PAYPAL_ID)||
offer.getPaymentMethod().equals(PaymentMethod.CASH_APP_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 @@ -1061,6 +1061,7 @@ message UpholdAccountPayload {

message CashAppAccountPayload {
string email_or_mobile_nr_or_cashtag = 1;
string extra_info = 2;
}

message MoneyBeamAccountPayload {
Expand Down

0 comments on commit 05b0072

Please sign in to comment.