From aee0c1c0b2773dda87789a797df2957ac1c3e062 Mon Sep 17 00:00:00 2001
From: woodser <woodser@protonmail.com>
Date: Tue, 5 Nov 2024 10:34:42 -0500
Subject: [PATCH] validate form fields on create payment account from form

---
 .../haveno/core/api/CorePaymentAccountsService.java   | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/core/src/main/java/haveno/core/api/CorePaymentAccountsService.java b/core/src/main/java/haveno/core/api/CorePaymentAccountsService.java
index dcf1ef0e..b506a00a 100644
--- a/core/src/main/java/haveno/core/api/CorePaymentAccountsService.java
+++ b/core/src/main/java/haveno/core/api/CorePaymentAccountsService.java
@@ -64,9 +64,14 @@ class CorePaymentAccountsService {
     }
 
     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 {}.",
@@ -166,6 +171,12 @@ class CorePaymentAccountsService {
                 .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