[#12071] Some ENS names starting with 0x are not picked up as universal links
Signed-off-by: andrey <motor4ik@gmail.com>
This commit is contained in:
parent
a6eee856cf
commit
82f7fbf7e4
|
@ -12,7 +12,8 @@
|
||||||
[status-im.i18n.i18n :as i18n]
|
[status-im.i18n.i18n :as i18n]
|
||||||
[status-im.contact.core :as contact]
|
[status-im.contact.core :as contact]
|
||||||
[status-im.router.core :as router]
|
[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
|
(re-frame/reg-fx
|
||||||
:resolve-public-key
|
:resolve-public-key
|
||||||
|
@ -27,37 +28,42 @@
|
||||||
(fx/defn new-chat-set-new-identity
|
(fx/defn new-chat-set-new-identity
|
||||||
{:events [:new-chat/set-new-identity]}
|
{:events [:new-chat/set-new-identity]}
|
||||||
[{db :db} new-identity-raw new-ens-name id]
|
[{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)
|
||||||
(let [new-identity (utils/safe-trim new-identity-raw)
|
ens-error (and (= new-identity-raw "0x") (not (string/blank? new-ens-name)))]
|
||||||
is-public-key? (and (string? new-identity)
|
(when (and (or (not id) (= id @resolve-last-id))
|
||||||
(string/starts-with? new-identity "0x"))
|
(or ens-error (> (count new-identity) 4)))
|
||||||
is-ens? (and (not is-public-key?)
|
(if ens-error
|
||||||
(ens/valid-eth-name-prefix? new-identity))
|
{:db (assoc-in db [:contacts/new-identity :state] :error)}
|
||||||
error (db/validate-pub-key db new-identity)]
|
(let [new-identity (utils/safe-trim new-identity-raw)
|
||||||
(reset! resolve-last-id nil)
|
is-public-key? (and (string? new-identity)
|
||||||
(merge {:db (assoc db
|
(utils.db/valid-public-key? new-identity))
|
||||||
:contacts/new-identity
|
is-ens? (and (not is-public-key?)
|
||||||
{:public-key new-identity
|
(ens/valid-eth-name-prefix? new-identity))
|
||||||
:state (cond is-ens?
|
error (db/validate-pub-key db new-identity)]
|
||||||
:searching
|
(reset! resolve-last-id nil)
|
||||||
(and (string/blank? new-identity) (not new-ens-name))
|
(merge {:db (assoc db
|
||||||
:empty
|
:contacts/new-identity
|
||||||
error
|
{:public-key new-identity
|
||||||
:error
|
:state (cond is-ens?
|
||||||
:else
|
:searching
|
||||||
:valid)
|
(and (string/blank? new-identity) (not new-ens-name))
|
||||||
:error error
|
:empty
|
||||||
:ens-name (resolver/ens-name-parse new-ens-name)})}
|
error
|
||||||
(when is-ens?
|
:error
|
||||||
(reset! resolve-last-id (random/id))
|
:else
|
||||||
(let [chain (ethereum/chain-keyword db)]
|
:valid)
|
||||||
{:resolve-public-key
|
:error error
|
||||||
{:chain chain
|
:ens-name (resolver/ens-name-parse new-ens-name)})}
|
||||||
:contact-identity new-identity
|
(when is-ens?
|
||||||
:cb #(re-frame/dispatch [:new-chat/set-new-identity
|
(reset! resolve-last-id (random/id))
|
||||||
%
|
(let [chain (ethereum/chain-keyword db)]
|
||||||
new-identity
|
{:resolve-public-key
|
||||||
@resolve-last-id])}}))))))
|
{: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
|
(fx/defn clear-new-identity
|
||||||
{:events [::clear-new-identity ::new-chat-focus]}
|
{:events [::clear-new-identity ::new-chat-focus]}
|
||||||
|
|
|
@ -69,16 +69,14 @@
|
||||||
|
|
||||||
(defn match-contact-async
|
(defn match-contact-async
|
||||||
[chain {:keys [user-id]} callback]
|
[chain {:keys [user-id]} callback]
|
||||||
(let [public-key? (and (string? user-id)
|
(let [valid-key (and (spec/valid? :global/public-key user-id)
|
||||||
(string/starts-with? user-id "0x"))
|
|
||||||
valid-key (and (spec/valid? :global/public-key user-id)
|
|
||||||
(not= user-id ens/default-key))]
|
(not= user-id ens/default-key))]
|
||||||
(cond
|
(cond
|
||||||
(and public-key? valid-key)
|
(and valid-key)
|
||||||
(callback {:type :contact
|
(callback {:type :contact
|
||||||
:public-key user-id})
|
: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)
|
(let [registry (get ens/ens-registries chain)
|
||||||
ens-name (resolver/ens-name-parse user-id)
|
ens-name (resolver/ens-name-parse user-id)
|
||||||
on-success #(match-contact-async chain {:user-id %} callback)]
|
on-success #(match-contact-async chain {:user-id %} callback)]
|
||||||
|
|
|
@ -142,7 +142,7 @@
|
||||||
{:on-change-text
|
{:on-change-text
|
||||||
#(do
|
#(do
|
||||||
(reset! search-value %)
|
(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))
|
(debounce/debounce-and-dispatch [:new-chat/set-new-identity %] 600))
|
||||||
:on-submit-editing
|
:on-submit-editing
|
||||||
#(when (= state :valid)
|
#(when (= state :valid)
|
||||||
|
|
Loading…
Reference in New Issue