Skip to content

Commit

Permalink
Merge pull request #6172 from xyzmaker123/refactor-cash-deposit-payload
Browse files Browse the repository at this point in the history
Refactor CashDepositAccountPayload to extends BankAccountPayload
  • Loading branch information
ripcurlx authored Apr 28, 2022
2 parents f5bb7a0 + b932f0f commit 6d3863d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

import com.google.protobuf.Message;

import java.nio.charset.StandardCharsets;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
Expand All @@ -42,22 +40,11 @@
@Setter
@Getter
@Slf4j
public class CashDepositAccountPayload extends CountryBasedPaymentAccountPayload implements PayloadWithHolderName {
private String holderName = "";
public class CashDepositAccountPayload extends BankAccountPayload {
@Nullable
private String holderEmail;
private String bankName = "";
private String branchId = "";
private String accountNr = "";
@Nullable
private String accountType;
@Nullable
private String requirements;
@Nullable
private String holderTaxId;
private String bankId = "";
@Nullable
protected String nationalAccountId;

public CashDepositAccountPayload(String paymentMethod, String id) {
super(paymentMethod, id);
Expand Down Expand Up @@ -86,18 +73,19 @@ private CashDepositAccountPayload(String paymentMethodName,
super(paymentMethodName,
id,
countryCode,
holderName,
bankName,
branchId,
accountNr,
accountType,
holderTaxId,
bankId,
nationalAccountId,
maxTradePeriod,
excludeFromJsonDataMap);
this.holderName = holderName;

this.holderEmail = holderEmail;
this.bankName = bankName;
this.branchId = branchId;
this.accountNr = accountNr;
this.accountType = accountType;
this.requirements = requirements;
this.holderTaxId = holderTaxId;
this.bankId = bankId;
this.nationalAccountId = nationalAccountId;
}

@Override
Expand Down Expand Up @@ -186,43 +174,4 @@ public String getPaymentDetailsForTradePopup() {
requirementsString +
Res.getWithCol("payment.bank.country") + " " + CountryUtil.getNameByCode(countryCode);
}

public String getHolderIdLabel() {
return BankUtil.getHolderIdLabel(countryCode);
}

@Nullable
public String getBankId() {
return BankUtil.isBankIdRequired(countryCode) ? bankId : bankName;
}

@Override
public byte[] getAgeWitnessInputData() {
String bankName = BankUtil.isBankNameRequired(countryCode) ? this.bankName : "";
String bankId = BankUtil.isBankIdRequired(countryCode) ? this.bankId : "";
String branchId = BankUtil.isBranchIdRequired(countryCode) ? this.branchId : "";
String accountNr = BankUtil.isAccountNrRequired(countryCode) ? this.accountNr : "";
String accountType = BankUtil.isAccountTypeRequired(countryCode) ? this.accountType : "";
String holderTaxIdString = BankUtil.isHolderIdRequired(countryCode) ?
(BankUtil.getHolderIdLabel(countryCode) + " " + holderTaxId + "\n") : "";
String nationalAccountId = BankUtil.isNationalAccountIdRequired(countryCode) ? this.nationalAccountId : "";

// We don't add holderName and holderEmail because we don't want to break age validation if the user recreates an account with
// slight changes in holder name (e.g. add or remove middle name)

String all = bankName +
bankId +
branchId +
accountNr +
accountType +
holderTaxIdString +
nationalAccountId;

return super.getAgeWitnessInputData(all.getBytes(StandardCharsets.UTF_8));
}

@Override
public String getOwnerId() {
return holderName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.CountryBasedPaymentAccount;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.BankAccountPayload;
import bisq.core.payment.payload.CashDepositAccountPayload;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.util.coin.CoinFormatter;
Expand Down Expand Up @@ -479,24 +478,4 @@ private void addHolderNameAndIdForDisplayAccount() {
cashDepositAccountPayload.getHolderName());
}
}

@Override
protected String getBankId() {
return ((CashDepositAccountPayload) paymentAccount.paymentAccountPayload).getBankId();
}

@Override
protected String getBranchId() {
return ((CashDepositAccountPayload) paymentAccount.paymentAccountPayload).getBranchId();
}

@Override
protected String getBankName() {
return ((CashDepositAccountPayload) paymentAccount.paymentAccountPayload).getBankName();
}

@Override
protected String getAccountNr() {
return ((CashDepositAccountPayload) paymentAccount.paymentAccountPayload).getAccountNr();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import bisq.core.locale.Res;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.BankAccountPayload;
import bisq.core.payment.payload.CashDepositAccountPayload;
import bisq.core.payment.payload.CountryBasedPaymentAccountPayload;
import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.validation.InputValidator;

Expand Down Expand Up @@ -140,25 +138,26 @@ void updateHolderIDInput(String countryCode, boolean requiresHolderId) {
@Override
protected void autoFillNameTextField() {
if (useCustomAccountNameToggleButton != null && !useCustomAccountNameToggleButton.isSelected()) {
BankAccountPayload payload = (BankAccountPayload) paymentAccount.paymentAccountPayload;
String bankId = null;
String countryCode = getCountryCode();
String countryCode = payload.getCountryCode();
if (countryCode == null)
countryCode = "";
if (BankUtil.isBankIdRequired(countryCode)) {
bankId = getBankId();
bankId = payload.getBankId();
if (bankId.length() > 9)
bankId = StringUtils.abbreviate(bankId, 9);
} else if (BankUtil.isBranchIdRequired(countryCode)) {
bankId = getBranchId();
bankId = payload.getBranchId();
if (bankId.length() > 9)
bankId = StringUtils.abbreviate(bankId, 9);
} else if (BankUtil.isBankNameRequired(countryCode)) {
bankId = getBankName();
bankId = payload.getBankName();
if (bankId.length() > 9)
bankId = StringUtils.abbreviate(bankId, 9);
}

String accountNr = getAccountNr();
String accountNr = payload.getAccountNr();
if (accountNr.length() > 9)
accountNr = StringUtils.abbreviate(accountNr, 9);

Expand Down Expand Up @@ -209,24 +208,4 @@ boolean getValidationResult(boolean result, String countryCode, String bankName,

return result;
}

protected String getBankId() {
return ((BankAccountPayload) paymentAccount.paymentAccountPayload).getBankId();
}

protected String getBranchId() {
return ((BankAccountPayload) paymentAccount.paymentAccountPayload).getBranchId();
}

protected String getBankName() {
return ((BankAccountPayload) paymentAccount.paymentAccountPayload).getBankName();
}

protected String getAccountNr() {
return ((BankAccountPayload) paymentAccount.paymentAccountPayload).getAccountNr();
}

protected String getCountryCode() {
return ((CountryBasedPaymentAccountPayload) paymentAccount.paymentAccountPayload).getCountryCode();
}
}

0 comments on commit 6d3863d

Please sign in to comment.