Refactor CashDepositAccountPayload to extends BankAccountPayload

This commit is contained in:
xyzmaker123 2022-04-26 14:17:28 +02:00 committed by Christoph Atteneder
parent 1a87426807
commit ca50662ff2
No known key found for this signature in database
GPG Key ID: CD5DC1C529CDFD3B
3 changed files with 16 additions and 109 deletions

View File

@ -23,8 +23,6 @@ import bisq.core.locale.Res;
import com.google.protobuf.Message;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@ -42,22 +40,11 @@ import javax.annotation.Nullable;
@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);
@ -86,18 +73,19 @@ public class CashDepositAccountPayload extends CountryBasedPaymentAccountPayload
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
@ -186,43 +174,4 @@ public class CashDepositAccountPayload extends CountryBasedPaymentAccountPayload
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;
}
}

View File

@ -31,7 +31,6 @@ import bisq.core.locale.Res;
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;
@ -479,24 +478,4 @@ public class CashDepositForm extends GeneralBankForm {
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();
}
}

View File

@ -11,8 +11,6 @@ import bisq.core.locale.BankUtil;
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;
@ -140,25 +138,26 @@ public abstract class GeneralBankForm extends PaymentMethodForm {
@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);
@ -209,24 +208,4 @@ public abstract class GeneralBankForm extends PaymentMethodForm {
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();
}
}