fix ens resolve issue while following deep link (#13080)

This commit is contained in:
Parvesh Monu 2022-02-10 00:21:47 +05:30 committed by GitHub
parent e59a2663f7
commit 9850dd5160
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 39 additions and 24 deletions

View File

@ -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

View File

@ -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

View File

@ -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)))

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
{})))