[#9213] ENS addr is checked instead of owner

This commit is contained in:
Andrey Shovkoplyas 2019-11-28 13:07:02 +01:00
parent d930c51dfa
commit 831f7f05f3
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
5 changed files with 53 additions and 33 deletions

View File

@ -31,6 +31,11 @@
(fn [[registry name cb]]
(ens/get-addr registry name cb)))
(re-frame/reg-fx
::resolve-owner
(fn [[registry name cb]]
(ens/get-owner registry name cb)))
(re-frame/reg-fx
::resolve-pubkey
(fn [[registry name cb]]
@ -99,9 +104,14 @@
:actions [{:routeName :my-profile}
{:routeName :ens-confirmation}]}))
(defn- on-resolve
(defn- on-resolve-owner
[registry custom-domain? username address public-key response]
(cond
;; No address for a stateofus subdomain: it can be registered
(and (= response ens/default-address) (not custom-domain?))
(re-frame/dispatch [::name-resolved username :available])
;; if we get an address back, we try to get the public key associated
;; with the username as well
(= (eip55/address->checksum address)
@ -113,10 +123,6 @@
(= % public-key) :connected
:else :connected-with-different-key)]))
;; No address for a stateofus subdomain: it can be registered
(and (nil? response) (not custom-domain?))
(re-frame/dispatch [::name-resolved username :available])
:else
(re-frame/dispatch [::name-resolved username :taken])))
@ -183,9 +189,9 @@
{:keys [public-key]} multiaccount
address (ethereum/default-address db)
registry (get ens/ens-registries (ethereum/chain-keyword db))]
{::resolve-address [registry
(fullname custom-domain? username)
#(on-resolve registry custom-domain? username address public-key %)]})))))
{::resolve-owner [registry
(fullname custom-domain? username)
#(on-resolve-owner registry custom-domain? username address public-key %)]})))))
(fx/defn return-to-ens-main-screen
{:events [::got-it-pressed ::cancel-pressed]}

View File

@ -160,4 +160,7 @@
ens-name
#(addr % ens-name cb)))
;; TODO ABI, pubkey
(defn get-owner
[registry ens-name cb]
{:pre [(is-valid-eth-name? ens-name)]}
(owner registry ens-name cb))

View File

@ -20,17 +20,12 @@
[status-im.utils.http :as http]
[status-im.utils.js-resources :as js-res]
[status-im.ui.components.chat-icon.screen :as chat-icon]
[status-im.ui.screens.browser.accounts :as accounts])
[status-im.ui.screens.browser.accounts :as accounts]
[status-im.utils.debounce :as debounce])
(:require-macros
[status-im.utils.slurp :refer [slurp]]
[status-im.utils.views :as views]))
(def timeout (atom {}))
(defn debounce [event]
(when @timeout (js/clearTimeout @timeout))
(reset! timeout (js/setTimeout #(re-frame/dispatch event) 500)))
(def browser-config-edn
(slurp "./src/status_im/utils/browser_config.edn"))
@ -69,7 +64,7 @@
{:browser? true}
[toolbar.view/nav-button
(actions/close (fn []
(when @timeout (js/clearTimeout @timeout))
(debounce/clear)
(re-frame/dispatch [:navigate-back])
(when error?
(re-frame/dispatch [:browser.ui/remove-browser-pressed browser-id]))))]
@ -146,7 +141,9 @@
:bounces false
:local-storage-enabled true
:render-error web-view-error
:on-navigation-state-change #(debounce [:browser/navigation-state-changed % error?])
:on-navigation-state-change #(do
(re-frame/dispatch [:set-in [:ens/registration :state] :searching])
(debounce/debounce [:browser/navigation-state-changed % error?] 500))
:on-bridge-message #(re-frame/dispatch [:browser/bridge-message-received %])
:on-load #(re-frame/dispatch [:browser/loading-started])
:on-error #(re-frame/dispatch [:browser/error-occured])

View File

@ -22,7 +22,8 @@
[status-im.utils.navigation :as navigation]
[status-im.ui.components.list-item.views :as list-item]
[status-im.ui.screens.chat.photos :as photos]
[status-im.multiaccounts.core :as multiaccounts])
[status-im.multiaccounts.core :as multiaccounts]
[status-im.utils.debounce :as debounce])
(:require-macros [status-im.utils.views :as views]))
(defn- button
@ -195,21 +196,23 @@
;;disappearing when switching between stateofus and custom domain
^{:key placeholder}
[react/text-input
{:ref #(reset! input-ref %)
:on-change-text #(re-frame/dispatch [::ens/set-username-candidate %])
:on-submit-editing #(re-frame/dispatch [::ens/input-submitted])
:auto-capitalize :none
:auto-complete-type "off"
:auto-focus true
:auto-correct false
:keyboard-type :visible-password
:default-value ""
:text-align :center
:placeholder placeholder
{:ref #(reset! input-ref %)
:on-change-text #(do
(re-frame/dispatch [:set-in [:ens/registration :state] :searching])
(debounce/debounce [::ens/set-username-candidate %] 600))
:on-submit-editing #(re-frame/dispatch [::ens/input-submitted])
:auto-capitalize :none
:auto-complete-type "off"
:auto-focus true
:auto-correct false
:keyboard-type :visible-password
:default-value ""
:text-align :center
:placeholder placeholder
:placeholder-text-color colors/text-gray
:style {:flex 1
:font-size 22
:padding-left 48}}]
:style {:flex 1
:font-size 22
:padding-left 48}}]
[input-icon state]])))
(views/defview search []

View File

@ -0,0 +1,11 @@
(ns status-im.utils.debounce
(:require [re-frame.core :as re-frame]))
(def timeout (atom {}))
(defn debounce [event time]
(when @timeout (js/clearTimeout @timeout))
(reset! timeout (js/setTimeout #(re-frame/dispatch event) time)))
(defn clear []
(when @timeout (js/clearTimeout @timeout)))