show ens name for chats created using ens name

This commit is contained in:
Andrey Shovkoplyas 2019-12-18 12:07:08 +01:00
parent a21454039b
commit 3e19f929e9
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
5 changed files with 34 additions and 21 deletions

View File

@ -13,7 +13,8 @@
[status-im.tribute-to-talk.whitelist :as whitelist]
[status-im.ui.screens.navigation :as navigation]
[status-im.utils.config :as config]
[status-im.utils.fx :as fx]))
[status-im.utils.fx :as fx]
[status-im.utils.datetime :as time]))
(fx/defn load-contacts
{:events [::contacts-loaded]}
@ -71,7 +72,7 @@
(update :system-tags
(fnil #(conj % :contact/added) #{})))]
(fx/merge cofx
{:db (assoc-in db [:contacts/new-identity] "")}
{:db (dissoc db :contacts/new-identity)}
(upsert-contact contact)
(whitelist/add-to-whitelist public-key)
(send-contact-request contact)
@ -94,7 +95,7 @@
(when (not= (get-in db [:multiaccount :public-key]) public-key)
(let [contact (build-contact cofx public-key)]
(fx/merge cofx
{:db (assoc-in db [:contacts/new-identity] "")}
{:db (dissoc db :contacts/new-identity)}
(upsert-contact contact)))))
(fx/defn handle-contact-update
@ -176,3 +177,12 @@
{:events [:contacts/ens-names-verified]}
[{:keys [db]} names]
{:db (update db :contacts/contacts add-ens-names names)})
(fx/defn name-verified
{:events [:contacts/ens-name-verified]}
[{:keys [db]} public-key ens-name]
{:db (update-in db [:contacts/contacts public-key]
merge
{:name ens-name
:ens-verified-at (quot (time/timestamp) 1000)
:ens-verified true})})

View File

@ -46,7 +46,7 @@
(spec/def :contacts/contacts (spec/nilable (spec/map-of :global/not-empty-string :contact/contact)))
;;public key of new contact during adding this new contact
(spec/def :contacts/new-identity (spec/nilable string?))
(spec/def :contacts/new-identity (spec/nilable map?))
(spec/def :contacts/new-identity-error (spec/nilable string?))
;;on showing this contact's profile (andrey: better to move into profile ns)
(spec/def :contacts/identity (spec/nilable :global/not-empty-string))

View File

@ -1210,17 +1210,13 @@
(handlers/register-handler-fx
:contact/qr-code-scanned
[(re-frame/inject-cofx :random-id-generator)]
(fn [{:keys [db] :as cofx} [_ contact-identity _]]
(let [current-multiaccount (:multiaccount db)
fx {:db (assoc db :contacts/new-identity contact-identity)}
validation-result (new-chat.db/validate-pub-key db contact-identity)]
(fn [{:keys [db] :as cofx} [_ contact-identity _]]
(let [validation-result (new-chat.db/validate-pub-key db contact-identity)]
(if (some? validation-result)
{:utils/show-popup {:title (i18n/label :t/unable-to-read-this-code)
:content validation-result
:on-dismiss #(re-frame/dispatch [:navigate-to-clean :home])}}
(fx/merge cofx
fx
(chat/start-chat contact-identity {:navigation-reset? true}))))))
(chat/start-chat cofx contact-identity {:navigation-reset? true})))))
(handlers/register-handler-fx
:contact.ui/start-group-chat-pressed
@ -1237,7 +1233,11 @@
:contact.ui/contact-code-submitted
[(re-frame/inject-cofx :random-id-generator)]
(fn [{{:contacts/keys [new-identity]} :db :as cofx} _]
(chat/start-chat cofx new-identity {:navigation-reset? true})))
(let [{:keys [public-key ens-name]} new-identity]
(fx/merge cofx
(chat/start-chat public-key {:navigation-reset? true})
#(when ens-name
(contact/name-verified % public-key ens-name))))))
;; search module

View File

@ -5,7 +5,8 @@
[status-im.ethereum.ens :as ens]
[status-im.ethereum.resolver :as resolver]
[status-im.ui.screens.add-new.new-chat.db :as db]
[status-im.utils.handlers :as handlers]))
[status-im.utils.handlers :as handlers]
[status-im.ethereum.stateofus :as stateofus]))
(re-frame/reg-fx
:resolve-public-key
@ -14,17 +15,19 @@
(handlers/register-handler-fx
:new-chat/set-new-identity
(fn [{{:keys [network-status] :as db} :db} [_ new-identity]]
(fn [{db :db} [_ new-identity new-ens-name]]
(let [is-public-key? (and (string? new-identity)
(string/starts-with? new-identity "0x"))]
(merge {:db (assoc db
:contacts/new-identity new-identity
:contacts/new-identity {:public-key new-identity :ens-name new-ens-name}
:contacts/new-identity-error (db/validate-pub-key db new-identity))}
(when (and (not is-public-key?)
(ens/valid-eth-name-prefix? new-identity))
(let [chain (ethereum/chain-keyword db)]
(let [chain (ethereum/chain-keyword db)
ens-name (string/lower-case
(if (ens/is-valid-eth-name? new-identity)
new-identity
(stateofus/subdomain new-identity)))]
{:resolve-public-key {:registry (get ens/ens-registries chain)
:ens-name (if (ens/is-valid-eth-name? new-identity)
new-identity
(str new-identity ".stateofus.eth"))
:cb #(re-frame/dispatch [:new-chat/set-new-identity %])}}))))))
:ens-name ens-name
:cb #(re-frame/dispatch [:new-chat/set-new-identity % ens-name])}}))))))

View File

@ -3,4 +3,4 @@
(defmethod navigation/preload-data! :new-chat
[db _]
(assoc db :contacts/new-identity nil))
(dissoc db :contacts/new-identity :contacts/new-identity-error))