From 82f7fbf7e41d3ca9e977853481519dffa13b6e4e Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 25 Jan 2022 12:33:24 +0100 Subject: [PATCH] [#12071] Some ENS names starting with 0x are not picked up as universal links Signed-off-by: andrey --- src/status_im/add_new/core.cljs | 70 ++++++++++--------- src/status_im/router/core.cljs | 8 +-- .../ui/screens/add_new/new_chat/views.cljs | 2 +- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/status_im/add_new/core.cljs b/src/status_im/add_new/core.cljs index 2ac21b18c7..12a11f1097 100644 --- a/src/status_im/add_new/core.cljs +++ b/src/status_im/add_new/core.cljs @@ -12,7 +12,8 @@ [status-im.i18n.i18n :as i18n] [status-im.contact.core :as contact] [status-im.router.core :as router] - [status-im.navigation :as navigation])) + [status-im.navigation :as navigation] + [status-im.utils.db :as utils.db])) (re-frame/reg-fx :resolve-public-key @@ -27,37 +28,42 @@ (fx/defn new-chat-set-new-identity {:events [:new-chat/set-new-identity]} [{db :db} new-identity-raw new-ens-name id] - (when (or (not id) (= id @resolve-last-id)) - (let [new-identity (utils/safe-trim new-identity-raw) - is-public-key? (and (string? new-identity) - (string/starts-with? new-identity "0x")) - is-ens? (and (not is-public-key?) - (ens/valid-eth-name-prefix? new-identity)) - error (db/validate-pub-key db new-identity)] - (reset! resolve-last-id nil) - (merge {:db (assoc db - :contacts/new-identity - {:public-key new-identity - :state (cond is-ens? - :searching - (and (string/blank? new-identity) (not new-ens-name)) - :empty - error - :error - :else - :valid) - :error error - :ens-name (resolver/ens-name-parse new-ens-name)})} - (when is-ens? - (reset! resolve-last-id (random/id)) - (let [chain (ethereum/chain-keyword db)] - {:resolve-public-key - {:chain chain - :contact-identity new-identity - :cb #(re-frame/dispatch [:new-chat/set-new-identity - % - new-identity - @resolve-last-id])}})))))) + (let [new-identity (utils/safe-trim new-identity-raw) + ens-error (and (= new-identity-raw "0x") (not (string/blank? new-ens-name)))] + (when (and (or (not id) (= id @resolve-last-id)) + (or ens-error (> (count new-identity) 4))) + (if ens-error + {:db (assoc-in db [:contacts/new-identity :state] :error)} + (let [new-identity (utils/safe-trim new-identity-raw) + is-public-key? (and (string? new-identity) + (utils.db/valid-public-key? new-identity)) + is-ens? (and (not is-public-key?) + (ens/valid-eth-name-prefix? new-identity)) + error (db/validate-pub-key db new-identity)] + (reset! resolve-last-id nil) + (merge {:db (assoc db + :contacts/new-identity + {:public-key new-identity + :state (cond is-ens? + :searching + (and (string/blank? new-identity) (not new-ens-name)) + :empty + error + :error + :else + :valid) + :error error + :ens-name (resolver/ens-name-parse new-ens-name)})} + (when is-ens? + (reset! resolve-last-id (random/id)) + (let [chain (ethereum/chain-keyword db)] + {:resolve-public-key + {:chain chain + :contact-identity new-identity + :cb #(re-frame/dispatch [:new-chat/set-new-identity + % + new-identity + @resolve-last-id])}})))))))) (fx/defn clear-new-identity {:events [::clear-new-identity ::new-chat-focus]} diff --git a/src/status_im/router/core.cljs b/src/status_im/router/core.cljs index c10d35f86a..95ed06694f 100644 --- a/src/status_im/router/core.cljs +++ b/src/status_im/router/core.cljs @@ -69,16 +69,14 @@ (defn match-contact-async [chain {:keys [user-id]} callback] - (let [public-key? (and (string? user-id) - (string/starts-with? user-id "0x")) - valid-key (and (spec/valid? :global/public-key user-id) + (let [valid-key (and (spec/valid? :global/public-key user-id) (not= user-id ens/default-key))] (cond - (and public-key? valid-key) + (and valid-key) (callback {:type :contact :public-key user-id}) - (and (not public-key?) (string? user-id)) + (and (not valid-key) (string? user-id)) (let [registry (get ens/ens-registries chain) ens-name (resolver/ens-name-parse user-id) on-success #(match-contact-async chain {:user-id %} callback)] diff --git a/src/status_im/ui/screens/add_new/new_chat/views.cljs b/src/status_im/ui/screens/add_new/new_chat/views.cljs index 3527056b42..b019fd2a1d 100644 --- a/src/status_im/ui/screens/add_new/new_chat/views.cljs +++ b/src/status_im/ui/screens/add_new/new_chat/views.cljs @@ -142,7 +142,7 @@ {:on-change-text #(do (reset! search-value %) - (re-frame/dispatch [:set-in [:contacts/new-identity :state] :searching]) + (re-frame/dispatch [:set-in [:contacts/new-identity :state] :empty]) (debounce/debounce-and-dispatch [:new-chat/set-new-identity %] 600)) :on-submit-editing #(when (= state :valid)