Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
ripcurlx committed Nov 3, 2020
1 parent d1bfc3e commit 93ee94a
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 100 deletions.
48 changes: 16 additions & 32 deletions core/src/main/java/bisq/core/payment/AustraliaPayID.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,37 @@

package bisq.core.payment;

import bisq.core.payment.payload.AustraliaPayIDPayload;
import bisq.core.locale.FiatCurrency;
import bisq.core.payment.payload.AustraliaPayidPayload;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.payment.payload.PaymentMethod;
import bisq.core.payment.payload.AustraliaPayIDPayload;

import org.jetbrains.annotations.NotNull;

import lombok.Getter;
import lombok.Setter;

import bisq.core.locale.Country;
import bisq.core.locale.FiatCurrency;
import bisq.core.payment.payload.AustraliaPayIDPayload;

public final class AustraliaPayID extends PaymentAccount
{
public AustraliaPayID()
{
public final class AustraliaPayid extends PaymentAccount {
public AustraliaPayid() {
super(PaymentMethod.AUSTRALIA_PAYID);
setSingleTradeCurrency(new FiatCurrency("AUD"));
}

@Override
protected PaymentAccountPayload createPayload()
{
return new AustraliaPayIDPayload(paymentMethod.getId(), id);
protected PaymentAccountPayload createPayload() {
return new AustraliaPayidPayload(paymentMethod.getId(), id);
}

// payid
public String getPayID()
{
return ((AustraliaPayIDPayload) paymentAccountPayload).getPayid();
public String getPayid() {
return ((AustraliaPayidPayload) paymentAccountPayload).getPayid();
}
public void setPayID(String payid)
{

public void setPayid(String payid) {
if (payid == null) payid = "";
((AustraliaPayIDPayload) paymentAccountPayload).setPayid(payid);
((AustraliaPayidPayload) paymentAccountPayload).setPayid(payid);
}

// bankAccount name
public String getBankAccountName()
{
return ((AustraliaPayIDPayload) paymentAccountPayload).getBankAccountName();
public String getBankAccountName() {
return ((AustraliaPayidPayload) paymentAccountPayload).getBankAccountName();
}
public void setBankAccountName(String bankAccountName)
{

public void setBankAccountName(String bankAccountName) {
if (bankAccountName == null) bankAccountName = "";
((AustraliaPayIDPayload) paymentAccountPayload).setBankAccountName(bankAccountName);
((AustraliaPayidPayload) paymentAccountPayload).setBankAccountName(bankAccountName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static PaymentAccount getPaymentAccount(PaymentMethod paymentMethod) {
case PaymentMethod.JAPAN_BANK_ID:
return new JapanBankAccount();
case PaymentMethod.AUSTRALIA_PAYID_ID:
return new AustraliaPayID();
return new AustraliaPayid();
case PaymentMethod.ALI_PAY_ID:
return new AliPayAccount();
case PaymentMethod.WECHAT_PAY_ID:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import com.google.protobuf.Message;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -39,12 +39,11 @@
@Setter
@Getter
@Slf4j
public final class AustraliaPayIDPayload extends PaymentAccountPayload {
// payid
public final class AustraliaPayidPayload extends PaymentAccountPayload {
private String payid = "";
private String bankAccountName = "";

public AustraliaPayIDPayload(String paymentMethod, String id) {
public AustraliaPayidPayload(String paymentMethod, String id) {
super(paymentMethod, id);
}

Expand All @@ -53,7 +52,7 @@ public AustraliaPayIDPayload(String paymentMethod, String id) {
// PROTO BUFFER
///////////////////////////////////////////////////////////////////////////////////////////

private AustraliaPayIDPayload(String paymentMethod,
private AustraliaPayidPayload(String paymentMethod,
String id,
String payid,
String bankAccountName,
Expand All @@ -72,18 +71,18 @@ private AustraliaPayIDPayload(String paymentMethod,
public Message toProtoMessage() {
return getPaymentAccountPayloadBuilder()
.setAustraliaPayidPayload(
protobuf.AustraliaPayIDPayload.newBuilder()
.setPayid(payid)
.setBankAccountName(bankAccountName)
protobuf.AustraliaPayidPayload.newBuilder()
.setPayid(payid)
.setBankAccountName(bankAccountName)
).build();
}

public static AustraliaPayIDPayload fromProto(protobuf.PaymentAccountPayload proto) {
protobuf.AustraliaPayIDPayload AustraliaPayIDPayload = proto.getAustraliaPayidPayload();
return new AustraliaPayIDPayload(proto.getPaymentMethodId(),
public static AustraliaPayidPayload fromProto(protobuf.PaymentAccountPayload proto) {
protobuf.AustraliaPayidPayload AustraliaPayidPayload = proto.getAustraliaPayidPayload();
return new AustraliaPayidPayload(proto.getPaymentMethodId(),
proto.getId(),
AustraliaPayIDPayload.getPayid(),
AustraliaPayIDPayload.getBankAccountName(),
AustraliaPayidPayload.getPayid(),
AustraliaPayidPayload.getBankAccountName(),
proto.getMaxTradePeriod(),
CollectionUtils.isEmpty(proto.getExcludeFromJsonDataMap()) ? null : new HashMap<>(proto.getExcludeFromJsonDataMap()));
}
Expand All @@ -94,23 +93,21 @@ public static AustraliaPayIDPayload fromProto(protobuf.PaymentAccountPayload pro
///////////////////////////////////////////////////////////////////////////////////////////

@Override
public String getPaymentDetails()
{
public String getPaymentDetails() {
return Res.get(paymentMethodId) + " - " + getPaymentDetailsForTradePopup().replace("\n", ", ");
}

@Override
public String getPaymentDetailsForTradePopup()
{
public String getPaymentDetailsForTradePopup() {
return
Res.get("payment.australia.payid") + ": " + payid + "\n" +
Res.get("payment.account.owner") + ": " + bankAccountName;
}
Res.get("payment.australia.payid") + ": " + payid + "\n" +
Res.get("payment.account.owner") + ": " + bankAccountName;
}


@Override
public byte[] getAgeWitnessInputData() {
String all = this.payid + this.bankAccountName;
return super.getAgeWitnessInputData(all.getBytes(Charset.forName("UTF-8")));
return super.getAgeWitnessInputData(all.getBytes(StandardCharsets.UTF_8));
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/proto/CoreProtoResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import bisq.core.dao.governance.proposal.storage.appendonly.ProposalPayload;
import bisq.core.payment.payload.AdvancedCashAccountPayload;
import bisq.core.payment.payload.AliPayAccountPayload;
import bisq.core.payment.payload.AustraliaPayidPayload;
import bisq.core.payment.payload.CashAppAccountPayload;
import bisq.core.payment.payload.CashDepositAccountPayload;
import bisq.core.payment.payload.ChaseQuickPayAccountPayload;
Expand All @@ -34,7 +35,6 @@
import bisq.core.payment.payload.InstantCryptoCurrencyPayload;
import bisq.core.payment.payload.InteracETransferAccountPayload;
import bisq.core.payment.payload.JapanBankAccountPayload;
import bisq.core.payment.payload.AustraliaPayIDPayload;
import bisq.core.payment.payload.MoneyBeamAccountPayload;
import bisq.core.payment.payload.MoneyGramAccountPayload;
import bisq.core.payment.payload.NationalBankAccountPayload;
Expand Down Expand Up @@ -126,7 +126,7 @@ public PaymentAccountPayload fromProto(protobuf.PaymentAccountPayload proto) {
case JAPAN_BANK_ACCOUNT_PAYLOAD:
return JapanBankAccountPayload.fromProto(proto);
case AUSTRALIA_PAYID_PAYLOAD:
return AustraliaPayIDPayload.fromProto(proto);
return AustraliaPayidPayload.fromProto(proto);
case UPHOLD_ACCOUNT_PAYLOAD:
return UpholdAccountPayload.fromProto(proto);
case MONEY_BEAM_ACCOUNT_PAYLOAD:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import bisq.desktop.components.InputTextField;
import bisq.desktop.util.FormBuilder;
import bisq.desktop.util.Layout;
import bisq.desktop.util.validation.AustraliaPayIDValidator;
import bisq.desktop.util.validation.AustraliaPayidValidator;

import bisq.core.account.witness.AccountAgeWitnessService;
import bisq.core.locale.Res;
import bisq.core.locale.TradeCurrency;
import bisq.core.payment.AustraliaPayID;
import bisq.core.payment.AustraliaPayid;
import bisq.core.payment.PaymentAccount;
import bisq.core.payment.payload.AustraliaPayIDPayload;
import bisq.core.payment.payload.AustraliaPayidPayload;
import bisq.core.payment.payload.PaymentAccountPayload;
import bisq.core.util.coin.CoinFormatter;
import bisq.core.util.validation.InputValidator;
Expand All @@ -38,24 +38,29 @@
import static bisq.desktop.util.FormBuilder.addCompactTopLabelTextField;
import static bisq.desktop.util.FormBuilder.addTopLabelTextField;

public class AustraliaPayIDForm extends PaymentMethodForm {
private final AustraliaPayID australiaPayID;
private final AustraliaPayIDValidator australiaPayIDValidator;
public class AustraliaPayidForm extends PaymentMethodForm {
private final AustraliaPayid australiaPayid;
private final AustraliaPayidValidator australiaPayidValidator;
private InputTextField mobileNrInputTextField;

public static int addFormForBuyer(GridPane gridPane, int gridRow, PaymentAccountPayload paymentAccountPayload) {
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.account.owner"),
((AustraliaPayIDPayload) paymentAccountPayload).getBankAccountName());
((AustraliaPayidPayload) paymentAccountPayload).getBankAccountName());
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.payid"),
((AustraliaPayIDPayload) paymentAccountPayload).getPayid());
((AustraliaPayidPayload) paymentAccountPayload).getPayid());
return gridRow;
}

public AustraliaPayIDForm(PaymentAccount paymentAccount, AccountAgeWitnessService accountAgeWitnessService, AustraliaPayIDValidator australiaPayIDValidator,
InputValidator inputValidator, GridPane gridPane, int gridRow, CoinFormatter formatter) {
public AustraliaPayidForm(PaymentAccount paymentAccount,
AccountAgeWitnessService accountAgeWitnessService,
AustraliaPayidValidator australiaPayidValidator,
InputValidator inputValidator,
GridPane gridPane,
int gridRow,
CoinFormatter formatter) {
super(paymentAccount, accountAgeWitnessService, inputValidator, gridPane, gridRow, formatter);
this.australiaPayID = (AustraliaPayID) paymentAccount;
this.australiaPayIDValidator = australiaPayIDValidator;
this.australiaPayid = (AustraliaPayid) paymentAccount;
this.australiaPayidValidator = australiaPayidValidator;
}

@Override
Expand All @@ -66,18 +71,18 @@ public void addFormForAddAccount() {
Res.get("payment.account.owner"));
holderNameInputTextField.setValidator(inputValidator);
holderNameInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
australiaPayID.setBankAccountName(newValue);
australiaPayid.setBankAccountName(newValue);
updateFromInputs();
});

mobileNrInputTextField = FormBuilder.addInputTextField(gridPane, ++gridRow, Res.get("payment.payid"));
mobileNrInputTextField.setValidator(australiaPayIDValidator);
mobileNrInputTextField.setValidator(australiaPayidValidator);
mobileNrInputTextField.textProperty().addListener((ov, oldValue, newValue) -> {
australiaPayID.setPayID(newValue);
australiaPayid.setPayid(newValue);
updateFromInputs();
});

TradeCurrency singleTradeCurrency = australiaPayID.getSingleTradeCurrency();
TradeCurrency singleTradeCurrency = australiaPayid.getSingleTradeCurrency();
String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null";
addTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode);
addLimitations(false);
Expand All @@ -93,15 +98,15 @@ protected void autoFillNameTextField() {
public void addFormForDisplayAccount() {
gridRowFrom = gridRow;
addTopLabelTextField(gridPane, gridRow, Res.get("payment.account.name"),
australiaPayID.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
australiaPayid.getAccountName(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.paymentMethod"),
Res.get(australiaPayID.getPaymentMethod().getId()));
Res.get(australiaPayid.getPaymentMethod().getId()));
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.payid"),
australiaPayID.getPayID());
australiaPayid.getPayid());
TextField field = addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("payment.account.owner"),
australiaPayID.getBankAccountName()).second;
australiaPayid.getBankAccountName()).second;
field.setMouseTransparent(false);
TradeCurrency singleTradeCurrency = australiaPayID.getSingleTradeCurrency();
TradeCurrency singleTradeCurrency = australiaPayid.getSingleTradeCurrency();
String nameAndCode = singleTradeCurrency != null ? singleTradeCurrency.getNameAndCode() : "null";
addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("shared.currency"), nameAndCode);
addLimitations(true);
Expand All @@ -110,8 +115,8 @@ public void addFormForDisplayAccount() {
@Override
public void updateAllInputsValid() {
allInputsValid.set(isAccountNameValid()
&& australiaPayIDValidator.validate(australiaPayID.getPayID()).isValid
&& inputValidator.validate(australiaPayID.getBankAccountName()).isValid
&& australiaPayID.getTradeCurrencies().size() > 0);
&& australiaPayidValidator.validate(australiaPayid.getPayid()).isValid
&& inputValidator.validate(australiaPayid.getBankAccountName()).isValid
&& australiaPayid.getTradeCurrencies().size() > 0);
}
}
Loading

0 comments on commit 93ee94a

Please sign in to comment.