[#11379] Add a watch only account from an ENS name
This commit is contained in:
parent
4f4f6cf29e
commit
8e288aea56
|
@ -1,6 +1,8 @@
|
|||
(ns status-im.ethereum.resolver
|
||||
(:refer-clojure :exclude [name])
|
||||
(:require [status-im.ethereum.ens :as ens]))
|
||||
(:require [status-im.ethereum.ens :as ens]
|
||||
[status-im.ethereum.stateofus :as stateofus]
|
||||
[clojure.string :as string]))
|
||||
|
||||
(def default-hash "0x0000000000000000000000000000000000000000000000000000000000000000")
|
||||
(defn contenthash [registry ens-name cb]
|
||||
|
@ -24,3 +26,10 @@
|
|||
(ens/resolver registry
|
||||
ens-name
|
||||
#(ens/pubkey % ens-name cb)))
|
||||
|
||||
(defn ens-name-parse [contact-identity]
|
||||
(when (string? contact-identity)
|
||||
(string/lower-case
|
||||
(if (ens/is-valid-eth-name? contact-identity)
|
||||
contact-identity
|
||||
(stateofus/subdomain contact-identity)))))
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
[status-im.ethereum.eip681 :as eip681]
|
||||
[status-im.ethereum.ens :as ens]
|
||||
[status-im.ethereum.resolver :as resolver]
|
||||
[status-im.ethereum.stateofus :as stateofus]
|
||||
[cljs.spec.alpha :as spec]
|
||||
[status-im.ethereum.core :as ethereum]
|
||||
[status-im.utils.db :as utils.db]
|
||||
|
@ -58,17 +57,10 @@
|
|||
(defn match-uri [uri]
|
||||
(assoc (bidi/match-route routes uri) :uri uri :query-params (parse-query-params uri)))
|
||||
|
||||
(defn- ens-name-parse [contact-identity]
|
||||
(when (string? contact-identity)
|
||||
(string/lower-case
|
||||
(if (ens/is-valid-eth-name? contact-identity)
|
||||
contact-identity
|
||||
(stateofus/subdomain contact-identity)))))
|
||||
|
||||
(defn resolve-public-key
|
||||
[{:keys [chain contact-identity cb]}]
|
||||
(let [registry (get ens/ens-registries chain)
|
||||
ens-name (ens-name-parse contact-identity)]
|
||||
ens-name (resolver/ens-name-parse contact-identity)]
|
||||
(resolver/pubkey registry ens-name cb)))
|
||||
|
||||
(defn match-contact-async
|
||||
|
@ -84,7 +76,7 @@
|
|||
|
||||
(and (not public-key?) (string? user-id))
|
||||
(let [registry (get ens/ens-registries chain)
|
||||
ens-name (ens-name-parse user-id)
|
||||
ens-name (resolver/ens-name-parse user-id)
|
||||
on-success #(match-contact-async chain {:user-id %} callback)]
|
||||
(resolver/pubkey registry ens-name on-success))
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
[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.ethereum.stateofus :as stateofus]
|
||||
[status-im.utils.random :as random]
|
||||
[status-im.utils.utils :as utils]
|
||||
[status-im.utils.fx :as fx]
|
||||
|
@ -16,18 +15,11 @@
|
|||
[status-im.router.core :as router]
|
||||
[status-im.navigation :as navigation]))
|
||||
|
||||
(defn- ens-name-parse [contact-identity]
|
||||
(when (string? contact-identity)
|
||||
(string/lower-case
|
||||
(if (ens/is-valid-eth-name? contact-identity)
|
||||
contact-identity
|
||||
(stateofus/subdomain contact-identity)))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:resolve-public-key
|
||||
(fn [{:keys [chain contact-identity cb]}]
|
||||
(let [registry (get ens/ens-registries chain)
|
||||
ens-name (ens-name-parse contact-identity)]
|
||||
ens-name (resolver/ens-name-parse contact-identity)]
|
||||
(resolver/pubkey registry ens-name cb))))
|
||||
|
||||
;;NOTE we want to handle only last resolve
|
||||
|
@ -56,7 +48,7 @@
|
|||
:else
|
||||
:valid)
|
||||
:error error
|
||||
:ens-name (ens-name-parse new-ens-name)})}
|
||||
:ens-name (resolver/ens-name-parse new-ens-name)})}
|
||||
(when is-ens?
|
||||
(reset! resolve-last-id (random/id))
|
||||
(let [chain (ethereum/chain-keyword db)]
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
:monospace true
|
||||
:placeholder (i18n/label :t/enter-address)
|
||||
:accessibility-label :add-account-enter-watch-address
|
||||
:on-change-text #(re-frame/dispatch [:set-in [:add-account :address] %])}]
|
||||
:on-change-text #(re-frame/dispatch [:wallet.accounts/set-account-to-watch %])}]
|
||||
[quo/text-input
|
||||
{:label (i18n/label :t/password)
|
||||
:show-cancel false
|
||||
|
|
|
@ -19,7 +19,11 @@
|
|||
[status-im.multiaccounts.recover.core :as recover]
|
||||
[status-im.ethereum.mnemonic :as mnemonic]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.wallet.prices :as prices]))
|
||||
[status-im.wallet.prices :as prices]
|
||||
[status-im.utils.hex :as hex]
|
||||
[status-im.ethereum.ens :as ens]
|
||||
[status-im.ens.core :as ens.core]
|
||||
[status-im.ethereum.resolver :as resolver]))
|
||||
|
||||
(fx/defn start-adding-new-account
|
||||
{:events [:wallet.accounts/start-adding-new-account]}
|
||||
|
@ -231,6 +235,24 @@
|
|||
::verify-password {:address (get-in db [:multiaccount :wallet-root-address])
|
||||
:hashed-password hashed-password}})
|
||||
|
||||
(fx/defn set-account-to-watch
|
||||
{:events [:wallet.accounts/set-account-to-watch]}
|
||||
[{:keys [db] :as cofx} account]
|
||||
(let [name? (and (>= (count account) 3)
|
||||
(not (hex/valid-hex? account)))
|
||||
chain (ethereum/chain-keyword db)]
|
||||
(log/debug "[wallet] set-account-to-watch" account
|
||||
"name?" name?)
|
||||
(cond-> {:db (assoc-in db [:add-account :address] account)}
|
||||
name?
|
||||
(assoc ::ens.core/resolve-address
|
||||
(let [registry (get ens/ens-registries chain)
|
||||
ens-name (resolver/ens-name-parse account)]
|
||||
[registry
|
||||
ens-name
|
||||
#(re-frame/dispatch
|
||||
[:wallet.accounts/set-account-to-watch %])])))))
|
||||
|
||||
(fx/defn add-new-account
|
||||
{:events [:wallet.accounts/add-new-account]}
|
||||
[{:keys [db] :as cofx} hashed-password]
|
||||
|
|
Loading…
Reference in New Issue