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

View File

@ -160,4 +160,7 @@
ens-name ens-name
#(addr % ens-name cb))) #(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.http :as http]
[status-im.utils.js-resources :as js-res] [status-im.utils.js-resources :as js-res]
[status-im.ui.components.chat-icon.screen :as chat-icon] [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 (:require-macros
[status-im.utils.slurp :refer [slurp]] [status-im.utils.slurp :refer [slurp]]
[status-im.utils.views :as views])) [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 (def browser-config-edn
(slurp "./src/status_im/utils/browser_config.edn")) (slurp "./src/status_im/utils/browser_config.edn"))
@ -69,7 +64,7 @@
{:browser? true} {:browser? true}
[toolbar.view/nav-button [toolbar.view/nav-button
(actions/close (fn [] (actions/close (fn []
(when @timeout (js/clearTimeout @timeout)) (debounce/clear)
(re-frame/dispatch [:navigate-back]) (re-frame/dispatch [:navigate-back])
(when error? (when error?
(re-frame/dispatch [:browser.ui/remove-browser-pressed browser-id]))))] (re-frame/dispatch [:browser.ui/remove-browser-pressed browser-id]))))]
@ -146,7 +141,9 @@
:bounces false :bounces false
:local-storage-enabled true :local-storage-enabled true
:render-error web-view-error :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-bridge-message #(re-frame/dispatch [:browser/bridge-message-received %])
:on-load #(re-frame/dispatch [:browser/loading-started]) :on-load #(re-frame/dispatch [:browser/loading-started])
:on-error #(re-frame/dispatch [:browser/error-occured]) :on-error #(re-frame/dispatch [:browser/error-occured])

View File

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