Skip to content

Commit 9850dd5

Browse files
authored
fix ens resolve issue while following deep link (#13080)
1 parent e59a266 commit 9850dd5

File tree

9 files changed

+39
-24
lines changed

9 files changed

+39
-24
lines changed

src/status_im/add_new/core.cljs

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
(fx/defn qr-code-handled
7070
{:events [::qr-code-handled]}
71-
[{:keys [db] :as cofx} {:keys [type public-key chat-id data]} {:keys [new-contact?] :as opts}]
71+
[{:keys [db] :as cofx} {:keys [type public-key chat-id data ens-name]} {:keys [new-contact?] :as opts}]
7272
(let [public-key? (and (string? data)
7373
(string/starts-with? data "0x"))
7474
chat-key (cond
@@ -80,9 +80,9 @@
8080
(if-not validation-result
8181
(if new-contact?
8282
(fx/merge cofx
83-
(contact/add-contact chat-key nil nil)
83+
(contact/add-contact chat-key nil ens-name)
8484
(navigation/navigate-to-cofx :contacts-list {}))
85-
(chat/start-chat cofx chat-key nil))
85+
(chat/start-chat cofx chat-key ens-name))
8686
{:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
8787
:content (case validation-result
8888
:invalid

src/status_im/chat/models.cljs

+4-2
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,14 @@
387387

388388
(fx/defn show-profile
389389
{:events [:chat.ui/show-profile]}
390-
[{:keys [db] :as cofx} identity]
390+
[{:keys [db] :as cofx} identity ens-name]
391391
(let [my-public-key (get-in db [:multiaccount :public-key])]
392392
(when (not= my-public-key identity)
393393
(fx/merge
394394
cofx
395-
{:db (assoc db :contacts/identity identity)}
395+
{:db (-> db
396+
(assoc :contacts/identity identity)
397+
(assoc :contacts/ens-name ens-name))}
396398
(start-profile-chat identity true)))))
397399

398400
(fx/defn clear-history-pressed

src/status_im/contact/chat.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
(fx/defn send-message-pressed
1010
{:events [:contact.ui/send-message-pressed]
1111
:interceptors [(re-frame/inject-cofx :random-id-generator)]}
12-
[cofx {:keys [public-key]}]
12+
[cofx {:keys [public-key ens-name]}]
1313
(fx/merge cofx
14-
{:dispatch-later [{:ms 1000 :dispatch [:chat.ui/start-chat public-key]}]}
14+
{:dispatch-later [{:ms 1000 :dispatch [:chat.ui/start-chat public-key ens-name]}]}
1515
(notification-center/accept-all-activity-center-notifications-from-chat public-key)
1616
(navigation/pop-to-root-tab :chat-stack)))
1717

src/status_im/contact/db.cljs

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
:identicon (identicon/identicon public-key)
1515
:public-key public-key}))
1616

17+
(defn public-key-and-ens-name->new-contact [public-key ens-name]
18+
(let [contact (public-key->new-contact public-key)]
19+
(if ens-name (-> contact
20+
(assoc :ens-name ens-name)
21+
(assoc :ens-verified true)
22+
(assoc :name ens-name))
23+
contact)))
24+
1725
(defn public-key->contact
1826
[contacts public-key]
1927
(when public-key

src/status_im/qr_scanner/core.cljs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@
5555
(group-chats/create-from-link cofx params))
5656

5757
(fx/defn handle-view-profile
58-
[{:keys [db] :as cofx} {:keys [public-key]}]
58+
[{:keys [db] :as cofx} {:keys [public-key ens-name]}]
5959
(let [own (new-chat.db/own-public-key? db public-key)]
6060
(cond
6161
(and public-key own)
62-
{:navigate-change-tab-fx :profile
62+
{:change-tab-fx :profile
6363
:pop-to-root-tab-fx :profile-stack}
6464

6565
(and public-key (not own))
6666
(fx/merge cofx
67-
{:dispatch [:chat.ui/show-profile public-key]}
67+
{:dispatch [:chat.ui/show-profile public-key ens-name]}
6868
(navigation/navigate-back))
6969

7070
:else

src/status_im/router/core.cljs

+5-4
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,20 @@
6262
(assoc (bidi/match-route routes uri) :uri uri :query-params (parse-query-params uri)))
6363

6464
(defn match-contact-async
65-
[chain {:keys [user-id]} callback]
65+
[chain {:keys [user-id ens-name]} callback]
6666
(let [valid-key (and (spec/valid? :global/public-key user-id)
6767
(not= user-id ens/default-key))]
6868
(cond
69-
(and valid-key)
69+
valid-key
7070
(callback {:type :contact
71-
:public-key user-id})
71+
:public-key user-id
72+
:ens-name ens-name})
7273

7374
(and (not valid-key) (string? user-id) (not (string/blank? user-id))
7475
(not= user-id "0x"))
7576
(let [chain-id (ethereum/chain-keyword->chain-id chain)
7677
ens-name (stateofus/ens-name-parse user-id)
77-
on-success #(match-contact-async chain {:user-id %} callback)]
78+
on-success #(match-contact-async chain {:user-id % :ens-name ens-name} callback)]
7879
(ens/pubkey chain-id ens-name on-success))
7980

8081
:else

src/status_im/subs.cljs

+5-4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@
152152
;;contacts
153153
(reg-root-key-sub ::contacts :contacts/contacts)
154154
(reg-root-key-sub :contacts/current-contact-identity :contacts/identity)
155+
(reg-root-key-sub :contacts/current-contact-ens-name :contacts/ens-name)
155156
(reg-root-key-sub :contacts/new-identity :contacts/new-identity)
156157
(reg-root-key-sub :group/selected-contacts :group/selected-contacts)
157158
(reg-root-key-sub :contacts/blocked-set :contacts/blocked)
@@ -2309,11 +2310,11 @@
23092310
:contacts/current-contact
23102311
:<- [:contacts/contacts]
23112312
:<- [:contacts/current-contact-identity]
2312-
(fn [[contacts identity]]
2313+
:<- [:contacts/current-contact-ens-name]
2314+
(fn [[contacts identity ens-name]]
23132315
(or (get contacts identity)
2314-
(-> identity
2315-
contact.db/public-key->new-contact
2316-
contact.db/enrich-contact))))
2316+
(contact.db/enrich-contact
2317+
(contact.db/public-key-and-ens-name->new-contact identity ens-name)))))
23172318

23182319
(re-frame/reg-sub
23192320
:contacts/contact-by-identity

src/status_im/ui/screens/profile/contact/views.cljs

+4-3
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
(:require-macros [status-im.utils.views :as views]))
2525

2626
(defn actions
27-
[{:keys [public-key added? blocked?] :as contact} muted?]
27+
[{:keys [public-key added? blocked? ens-name] :as contact} muted?]
2828
(concat [{:label (i18n/label :t/chat)
2929
:icon :main-icons/message
30-
:action #(re-frame/dispatch [:contact.ui/send-message-pressed {:public-key public-key}])
30+
:action #(re-frame/dispatch [:contact.ui/send-message-pressed {:public-key public-key
31+
:ens-name ens-name}])
3132
:accessibility-label :start-conversation-button}]
3233
(if added?
3334
[{:label (i18n/label :t/remove-from-contacts)
@@ -38,7 +39,7 @@
3839
[{:label (i18n/label :t/add-to-contacts)
3940
:icon :main-icons/add-contact
4041
:accessibility-label :add-to-contacts-button
41-
:action #(re-frame/dispatch [:contact.ui/add-to-contact-pressed public-key])}])
42+
:action #(re-frame/dispatch [:contact.ui/add-to-contact-pressed public-key nil ens-name])}])
4243
(when platform/ios?
4344
[{:label (i18n/label (if (or muted? blocked?) :t/unmute :t/mute))
4445
:icon :main-icons/notification

src/status_im/utils/universal_links/core.cljs

+5-3
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,17 @@
8080
(chat/start-public-chat cofx topic {})))
8181

8282
(fx/defn handle-view-profile
83-
[{:keys [db] :as cofx} {:keys [public-key]}]
83+
[{:keys [db] :as cofx} {:keys [public-key ens-name]}]
8484
(log/info "universal-links: handling view profile" public-key)
8585
(cond
8686
(and public-key (new-chat.db/own-public-key? db public-key))
87-
{:navigate-change-tab-fx :profile
87+
{:change-tab-fx :profile
8888
:pop-to-root-tab-fx :profile-stack}
8989

9090
public-key
91-
(navigation/navigate-to-cofx (assoc-in cofx [:db :contacts/identity] public-key)
91+
(navigation/navigate-to-cofx (-> cofx
92+
(assoc-in [:db :contacts/identity] public-key)
93+
(assoc-in [:db :contacts/ens-name] ens-name))
9294
:profile
9395
{})))
9496

0 commit comments

Comments
 (0)