fix: ENS regex not being used to detect an ENS on address input (#18626)

Signed-off-by: Brian Sztamfater <brian@status.im>
This commit is contained in:
Brian Sztamfater 2024-02-07 12:39:49 -03:00 committed by GitHub
parent c70646bd5c
commit ae7ee33f00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 38 additions and 26 deletions

View File

@ -61,24 +61,30 @@
value (reagent/atom "") value (reagent/atom "")
focused? (atom false)] focused? (atom false)]
(fn [{:keys [scanned-value theme blur? on-change-text on-blur on-focus on-clear on-scan (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? on-detect-ens on-detect-address on-detect-unclassified address-regex ens-regex
container-style]}] valid-ens-or-address? container-style]}]
(let [on-change (fn [text] (let [on-change (fn [text]
(when (not= @value text) (when (not= @value text)
(let [address? (when address-regex (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) (if (> (count text) 0)
(reset! status :typing) (reset! status :typing)
(reset! status :active)) (reset! status :active))
(reset! value text) (reset! value text)
(when on-change-text (when on-change-text
(on-change-text text)) (on-change-text text))
(when (and on-detect-ens (> (count text) 0)) (when (and on-detect-ens ens?)
(reset! status :loading) (reset! status :loading)
(on-detect-ens text #(reset! status :typing))) (on-detect-ens text #(reset! status :typing)))
(when (and address? on-detect-address) (when (and address? on-detect-address)
(reset! status :loading) (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 [] on-paste (fn []
(clipboard/get-string (clipboard/get-string
(fn [clipboard] (fn [clipboard]

View File

@ -313,6 +313,10 @@
(background-timer/clear-timeout current-timeout) (background-timer/clear-timeout current-timeout)
{:db (assoc db :wallet/local-suggestions [] :wallet/valid-ens-or-address? false)}))) {: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 (rf/reg-event-fx :wallet/get-address-details-success
(fn [{:keys [db]} [{:keys [hasActivity]}]] (fn [{:keys [db]} [{:keys [hasActivity]}]]
{:db (assoc-in db {:db (assoc-in db

View File

@ -48,6 +48,8 @@
(debounce/debounce-and-dispatch (debounce/debounce-and-dispatch
[:wallet/find-ens text contacts chain-id cb] [:wallet/find-ens text contacts chain-id cb]
300)) 300))
:on-detect-unclassified #(when valid-ens-or-address?
(rf/dispatch [:wallet/clean-ens-or-address-validation]))
:on-change-text (fn [text] :on-change-text (fn [text]
(when (empty? text) (when (empty? text)
(rf/dispatch [:wallet/clean-local-suggestions])) (rf/dispatch [:wallet/clean-local-suggestions]))