From ae7ee33f00873d200ff273f366f63f21334891de Mon Sep 17 00:00:00 2001 From: Brian Sztamfater Date: Wed, 7 Feb 2024 12:39:49 -0300 Subject: [PATCH] fix: ENS regex not being used to detect an ENS on address input (#18626) Signed-off-by: Brian Sztamfater --- .../components/inputs/address_input/view.cljs | 16 ++++--- src/status_im/contexts/wallet/events.cljs | 4 ++ .../wallet/send/select_address/view.cljs | 44 ++++++++++--------- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/quo/components/inputs/address_input/view.cljs b/src/quo/components/inputs/address_input/view.cljs index 51177f4d4f..8efd13f346 100644 --- a/src/quo/components/inputs/address_input/view.cljs +++ b/src/quo/components/inputs/address_input/view.cljs @@ -61,24 +61,30 @@ value (reagent/atom "") focused? (atom false)] (fn [{:keys [scanned-value theme blur? on-change-text on-blur on-focus on-clear on-scan - on-detect-ens on-detect-address address-regex valid-ens-or-address? - container-style]}] + on-detect-ens on-detect-address on-detect-unclassified address-regex ens-regex + valid-ens-or-address? container-style]}] (let [on-change (fn [text] (when (not= @value text) (let [address? (when address-regex - (boolean (re-matches address-regex text)))] + (boolean (re-matches address-regex text))) + ens? (when ens-regex + (boolean (re-matches ens-regex text)))] (if (> (count text) 0) (reset! status :typing) (reset! status :active)) (reset! value text) (when on-change-text (on-change-text text)) - (when (and on-detect-ens (> (count text) 0)) + (when (and on-detect-ens ens?) (reset! status :loading) (on-detect-ens text #(reset! status :typing))) (when (and address? on-detect-address) (reset! status :loading) - (on-detect-address text))))) + (on-detect-address text)) + (when (and (not address?) + (not ens?) + on-detect-unclassified) + (on-detect-unclassified text))))) on-paste (fn [] (clipboard/get-string (fn [clipboard] diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index f911e0c3f2..efeb810495 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -313,6 +313,10 @@ (background-timer/clear-timeout current-timeout) {:db (assoc db :wallet/local-suggestions [] :wallet/valid-ens-or-address? false)}))) +(rf/reg-event-fx :wallet/clean-ens-or-address-validation + (fn [{:keys [db]}] + {:db (assoc db :wallet/valid-ens-or-address? false)})) + (rf/reg-event-fx :wallet/get-address-details-success (fn [{:keys [db]} [{:keys [hasActivity]}]] {:db (assoc-in db 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 65279f7ae1..6e865acea2 100644 --- a/src/status_im/contexts/wallet/send/select_address/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/view.cljs @@ -32,27 +32,29 @@ chain-id (rf/sub [:chain-id]) contacts (rf/sub [:contacts/active])] [quo/address-input - {:on-focus #(reset! input-focused? true) - :on-blur #(reset! input-focused? false) - :on-scan (fn [] - (rn/dismiss-keyboard!) - (rf/dispatch [:wallet/clean-scanned-address]) - (rf/dispatch [:open-modal :scan-address])) - :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 #(debounce/debounce-and-dispatch - [:wallet/validate-address %] - 300) - :on-detect-ens (fn [text cb] - (debounce/debounce-and-dispatch - [:wallet/find-ens text contacts chain-id cb] - 300)) - :on-change-text (fn [text] - (when (empty? text) - (rf/dispatch [:wallet/clean-local-suggestions])) - (reset! input-value text)) - :valid-ens-or-address? valid-ens-or-address?}]))) + {:on-focus #(reset! input-focused? true) + :on-blur #(reset! input-focused? false) + :on-scan (fn [] + (rn/dismiss-keyboard!) + (rf/dispatch [:wallet/clean-scanned-address]) + (rf/dispatch [:open-modal :scan-address])) + :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 #(debounce/debounce-and-dispatch + [:wallet/validate-address %] + 300) + :on-detect-ens (fn [text cb] + (debounce/debounce-and-dispatch + [:wallet/find-ens text contacts chain-id cb] + 300)) + :on-detect-unclassified #(when valid-ens-or-address? + (rf/dispatch [:wallet/clean-ens-or-address-validation])) + :on-change-text (fn [text] + (when (empty? text) + (rf/dispatch [:wallet/clean-local-suggestions])) + (reset! input-value text)) + :valid-ens-or-address? valid-ens-or-address?}]))) (defn- ens-linked-address [{:keys [address networks theme]}]