Skip to content

Commit

Permalink
validate form fields on create payment account from form
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Nov 5, 2024
1 parent 4857463 commit aee0c1c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/src/main/java/haveno/core/api/CorePaymentAccountsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@ public CorePaymentAccountsService(CoreAccountService accountService,
}

PaymentAccount createPaymentAccount(PaymentAccountForm form) {
validateFormFields(form);
PaymentAccount paymentAccount = form.toPaymentAccount();
setSelectedTradeCurrency(paymentAccount); // TODO: selected trade currency is function of offer, not payment account payload
verifyPaymentAccountHasRequiredFields(paymentAccount);
if (paymentAccount instanceof CryptoCurrencyAccount) {
CryptoCurrencyAccount cryptoAccount = (CryptoCurrencyAccount) paymentAccount;
verifyCryptoCurrencyAddress(cryptoAccount.getSingleTradeCurrency().getCode(), cryptoAccount.getAddress());
}
user.addPaymentAccountIfNotExists(paymentAccount);
accountAgeWitnessService.publishMyAccountAgeWitness(paymentAccount.getPaymentAccountPayload());
log.info("Saved payment account with id {} and payment method {}.",
Expand Down Expand Up @@ -166,6 +171,12 @@ List<PaymentMethod> getCryptoCurrencyPaymentMethods() {
.collect(Collectors.toList());
}

private void validateFormFields(PaymentAccountForm form) {
for (PaymentAccountFormField field : form.getFields()) {
validateFormField(form, field.getId(), field.getValue());
}
}

void validateFormField(PaymentAccountForm form, PaymentAccountFormField.FieldId fieldId, String value) {

// get payment method id
Expand Down

0 comments on commit aee0c1c

Please sign in to comment.