Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CashDepositAccountPayload to extends BankAccountPayload #6172

Merged
merged 1 commit into from Apr 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
}
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();
}
}
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();
}
}