From e221e2325503f0ae808b0e1109c74d920f7de08e Mon Sep 17 00:00:00 2001 From: Ulises Manuel <90291778+ulisesmac@users.noreply.github.com> Date: Tue, 2 Jul 2024 13:57:31 -0600 Subject: [PATCH] fix(wallet): Validation of addresses in send-to screen (#20570) * Fix validation of addresses in send-to screen --- src/status_im/contexts/wallet/events.cljs | 2 +- .../wallet/send/select_address/view.cljs | 45 +++++++++---------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 8eb78a1f81..735c549d38 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -309,7 +309,7 @@ [] (filter #(string/starts-with? (or (:ens-name %) "") input) contacts))] (if (and input (empty? result)) - (rf/dispatch [:wallet/search-ens input on-error-fn ".stateofus.eth"]) + {:fx [[:dispatch [:wallet/search-ens input on-error-fn ".stateofus.eth"]]]} {:db (-> db (assoc-in [:wallet :ui :search-address :local-suggestions] (map #(assoc % :type item-types/saved-address) result)) diff --git a/src/status_im/contexts/wallet/send/select_address/view.cljs b/src/status_im/contexts/wallet/send/select_address/view.cljs index 4fe791d88c..f936422114 100644 --- a/src/status_im/contexts/wallet/send/select_address/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/view.cljs @@ -31,11 +31,10 @@ (defn- validate-address [address] (debounce/debounce-and-dispatch - (if (and (> (count address) 0) - (not (or (validation/ens-name? address) - (validation/eth-address? address)))) - [:wallet/address-validation-failed address] - [:wallet/address-validation-success address]) + (cond + (<= (count address) 0) [:wallet/address-validation-failed address] + (validation/eth-address? address) [:wallet/address-validation-success address] + :else [:wallet/address-validation-failed address]) 300)) (defn- address-input @@ -59,12 +58,13 @@ :ens-regex constants/regx-ens :scanned-value (or (when recipient-plain-address? send-address) scanned-address) :address-regex constants/regx-multichain-address - :on-detect-address #(when (or (= current-screen-id :screen/wallet.select-address) - (= current-screen-id :screen/wallet.scan-address)) - ; ^ this check is to prevent effect being triggered when screen is - ; loaded but not being shown to the user (deep in the navigation - ; stack) and avoid undesired behaviors - (validate-address %)) + :on-detect-address (fn [address] + (when (or (= current-screen-id :screen/wallet.select-address) + (= current-screen-id :screen/wallet.scan-address)) + ; ^ this check is to prevent effect being triggered when screen + ; is loaded but not being shown to the user (deep in the + ; navigation stack) and avoid undesired behaviors + (validate-address address))) :on-detect-ens (fn [text cb] (when (or (= current-screen-id :screen/wallet.select-address) (= current-screen-id :screen/wallet.scan-address)) @@ -75,8 +75,7 @@ [:wallet/find-ens text contacts cb] 300))) :on-change-text (fn [text] - (when (empty? text) - (rf/dispatch [:wallet/clean-local-suggestions])) + (rf/dispatch [:wallet/clean-local-suggestions]) (validate-address text) (reset! input-value text)) :valid-ens-or-address? valid-ens-or-address?}]))) @@ -101,8 +100,9 @@ (defn- suggestion-component [] - (fn [{:keys [type ens address accounts primary-name public-key ens-name color] :as local-suggestion} _ - _ _] + (fn [{:keys [type ens address accounts primary-name public-key ens-name color] + :as local-suggestion} + _ _ _] (let [props {:on-press (fn [] (let [address (if accounts (:address (first accounts)) address)] (when-not ens @@ -114,11 +114,12 @@ (cond (= type types/saved-address) [quo/saved-address - (merge props - {:user-props {:name primary-name - :address public-key - :ens ens-name - :customization-color color}})] + (assoc props + :user-props + {:name primary-name + :address public-key + :ens ens-name + :customization-color color})] (= type types/saved-contact-address) [quo/saved-contact-address (merge props local-suggestion)] (and (not ens) (= type types/address)) @@ -208,9 +209,7 @@ [rn/keyboard-avoiding-view {:style {:flex 1} :keyboard-vertical-offset 26} - [rn/view - {:style {:flex 1 - :padding 8}} + [rn/view {:style {:flex 1 :padding 8}} [local-suggestions-list]]] [:<> [quo/tabs