diff --git a/src/status_im/add_new/core.cljs b/src/status_im/add_new/core.cljs index a8e4350a36..e19be04ee9 100644 --- a/src/status_im/add_new/core.cljs +++ b/src/status_im/add_new/core.cljs @@ -68,7 +68,7 @@ (fx/defn qr-code-handled {:events [::qr-code-handled]} - [{:keys [db] :as cofx} {:keys [type public-key chat-id data]} {:keys [new-contact?] :as opts}] + [{:keys [db] :as cofx} {:keys [type public-key chat-id data ens-name]} {:keys [new-contact?] :as opts}] (let [public-key? (and (string? data) (string/starts-with? data "0x")) chat-key (cond @@ -80,9 +80,9 @@ (if-not validation-result (if new-contact? (fx/merge cofx - (contact/add-contact chat-key nil nil) + (contact/add-contact chat-key nil ens-name) (navigation/navigate-to-cofx :contacts-list {})) - (chat/start-chat cofx chat-key nil)) + (chat/start-chat cofx chat-key ens-name)) {:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code) :content (case validation-result :invalid diff --git a/src/status_im/chat/models.cljs b/src/status_im/chat/models.cljs index 1764bcd746..d7d5429dd0 100644 --- a/src/status_im/chat/models.cljs +++ b/src/status_im/chat/models.cljs @@ -387,12 +387,14 @@ (fx/defn show-profile {:events [:chat.ui/show-profile]} - [{:keys [db] :as cofx} identity] + [{:keys [db] :as cofx} identity ens-name] (let [my-public-key (get-in db [:multiaccount :public-key])] (when (not= my-public-key identity) (fx/merge cofx - {:db (assoc db :contacts/identity identity)} + {:db (-> db + (assoc :contacts/identity identity) + (assoc :contacts/ens-name ens-name))} (start-profile-chat identity true))))) (fx/defn clear-history-pressed diff --git a/src/status_im/contact/chat.cljs b/src/status_im/contact/chat.cljs index 2206765846..d2e395c8ee 100644 --- a/src/status_im/contact/chat.cljs +++ b/src/status_im/contact/chat.cljs @@ -9,9 +9,9 @@ (fx/defn send-message-pressed {:events [:contact.ui/send-message-pressed] :interceptors [(re-frame/inject-cofx :random-id-generator)]} - [cofx {:keys [public-key]}] + [cofx {:keys [public-key ens-name]}] (fx/merge cofx - {:dispatch-later [{:ms 1000 :dispatch [:chat.ui/start-chat public-key]}]} + {:dispatch-later [{:ms 1000 :dispatch [:chat.ui/start-chat public-key ens-name]}]} (notification-center/accept-all-activity-center-notifications-from-chat public-key) (navigation/pop-to-root-tab :chat-stack))) diff --git a/src/status_im/contact/db.cljs b/src/status_im/contact/db.cljs index d6c0468fe6..26f2e03f5d 100644 --- a/src/status_im/contact/db.cljs +++ b/src/status_im/contact/db.cljs @@ -14,6 +14,14 @@ :identicon (identicon/identicon public-key) :public-key public-key})) +(defn public-key-and-ens-name->new-contact [public-key ens-name] + (let [contact (public-key->new-contact public-key)] + (if ens-name (-> contact + (assoc :ens-name ens-name) + (assoc :ens-verified true) + (assoc :name ens-name)) + contact))) + (defn public-key->contact [contacts public-key] (when public-key diff --git a/src/status_im/qr_scanner/core.cljs b/src/status_im/qr_scanner/core.cljs index dab9aa5a18..9d64533b94 100644 --- a/src/status_im/qr_scanner/core.cljs +++ b/src/status_im/qr_scanner/core.cljs @@ -55,16 +55,16 @@ (group-chats/create-from-link cofx params)) (fx/defn handle-view-profile - [{:keys [db] :as cofx} {:keys [public-key]}] + [{:keys [db] :as cofx} {:keys [public-key ens-name]}] (let [own (new-chat.db/own-public-key? db public-key)] (cond (and public-key own) - {:navigate-change-tab-fx :profile + {:change-tab-fx :profile :pop-to-root-tab-fx :profile-stack} (and public-key (not own)) (fx/merge cofx - {:dispatch [:chat.ui/show-profile public-key]} + {:dispatch [:chat.ui/show-profile public-key ens-name]} (navigation/navigate-back)) :else diff --git a/src/status_im/router/core.cljs b/src/status_im/router/core.cljs index a7a5d6145f..3929b8e95a 100644 --- a/src/status_im/router/core.cljs +++ b/src/status_im/router/core.cljs @@ -62,19 +62,20 @@ (assoc (bidi/match-route routes uri) :uri uri :query-params (parse-query-params uri))) (defn match-contact-async - [chain {:keys [user-id]} callback] + [chain {:keys [user-id ens-name]} callback] (let [valid-key (and (spec/valid? :global/public-key user-id) (not= user-id ens/default-key))] (cond - (and valid-key) + valid-key (callback {:type :contact - :public-key user-id}) + :public-key user-id + :ens-name ens-name}) (and (not valid-key) (string? user-id) (not (string/blank? user-id)) (not= user-id "0x")) (let [chain-id (ethereum/chain-keyword->chain-id chain) ens-name (stateofus/ens-name-parse user-id) - on-success #(match-contact-async chain {:user-id %} callback)] + on-success #(match-contact-async chain {:user-id % :ens-name ens-name} callback)] (ens/pubkey chain-id ens-name on-success)) :else diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index ef730fcdc9..31e609427b 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -152,6 +152,7 @@ ;;contacts (reg-root-key-sub ::contacts :contacts/contacts) (reg-root-key-sub :contacts/current-contact-identity :contacts/identity) +(reg-root-key-sub :contacts/current-contact-ens-name :contacts/ens-name) (reg-root-key-sub :contacts/new-identity :contacts/new-identity) (reg-root-key-sub :group/selected-contacts :group/selected-contacts) (reg-root-key-sub :contacts/blocked-set :contacts/blocked) @@ -2309,11 +2310,11 @@ :contacts/current-contact :<- [:contacts/contacts] :<- [:contacts/current-contact-identity] - (fn [[contacts identity]] + :<- [:contacts/current-contact-ens-name] + (fn [[contacts identity ens-name]] (or (get contacts identity) - (-> identity - contact.db/public-key->new-contact - contact.db/enrich-contact)))) + (contact.db/enrich-contact + (contact.db/public-key-and-ens-name->new-contact identity ens-name))))) (re-frame/reg-sub :contacts/contact-by-identity diff --git a/src/status_im/ui/screens/profile/contact/views.cljs b/src/status_im/ui/screens/profile/contact/views.cljs index e268d2c0cc..f231af70b5 100644 --- a/src/status_im/ui/screens/profile/contact/views.cljs +++ b/src/status_im/ui/screens/profile/contact/views.cljs @@ -24,10 +24,11 @@ (:require-macros [status-im.utils.views :as views])) (defn actions - [{:keys [public-key added? blocked?] :as contact} muted?] + [{:keys [public-key added? blocked? ens-name] :as contact} muted?] (concat [{:label (i18n/label :t/chat) :icon :main-icons/message - :action #(re-frame/dispatch [:contact.ui/send-message-pressed {:public-key public-key}]) + :action #(re-frame/dispatch [:contact.ui/send-message-pressed {:public-key public-key + :ens-name ens-name}]) :accessibility-label :start-conversation-button}] (if added? [{:label (i18n/label :t/remove-from-contacts) @@ -38,7 +39,7 @@ [{:label (i18n/label :t/add-to-contacts) :icon :main-icons/add-contact :accessibility-label :add-to-contacts-button - :action #(re-frame/dispatch [:contact.ui/add-to-contact-pressed public-key])}]) + :action #(re-frame/dispatch [:contact.ui/add-to-contact-pressed public-key nil ens-name])}]) (when platform/ios? [{:label (i18n/label (if (or muted? blocked?) :t/unmute :t/mute)) :icon :main-icons/notification diff --git a/src/status_im/utils/universal_links/core.cljs b/src/status_im/utils/universal_links/core.cljs index b8e7b59170..99bcf79e87 100644 --- a/src/status_im/utils/universal_links/core.cljs +++ b/src/status_im/utils/universal_links/core.cljs @@ -80,15 +80,17 @@ (chat/start-public-chat cofx topic {}))) (fx/defn handle-view-profile - [{:keys [db] :as cofx} {:keys [public-key]}] + [{:keys [db] :as cofx} {:keys [public-key ens-name]}] (log/info "universal-links: handling view profile" public-key) (cond (and public-key (new-chat.db/own-public-key? db public-key)) - {:navigate-change-tab-fx :profile + {:change-tab-fx :profile :pop-to-root-tab-fx :profile-stack} public-key - (navigation/navigate-to-cofx (assoc-in cofx [:db :contacts/identity] public-key) + (navigation/navigate-to-cofx (-> cofx + (assoc-in [:db :contacts/identity] public-key) + (assoc-in [:db :contacts/ens-name] ens-name)) :profile {})))