diff --git a/src/status_im/ens/core.cljs b/src/status_im/ens/core.cljs index 87c15ba55f..d0e2a63bb2 100644 --- a/src/status_im/ens/core.cljs +++ b/src/status_im/ens/core.cljs @@ -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]} diff --git a/src/status_im/ethereum/ens.cljs b/src/status_im/ethereum/ens.cljs index b06f542838..b8355faf8c 100644 --- a/src/status_im/ethereum/ens.cljs +++ b/src/status_im/ethereum/ens.cljs @@ -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)) \ No newline at end of file diff --git a/src/status_im/ui/screens/browser/views.cljs b/src/status_im/ui/screens/browser/views.cljs index 5aac2cae3f..53f77404c5 100644 --- a/src/status_im/ui/screens/browser/views.cljs +++ b/src/status_im/ui/screens/browser/views.cljs @@ -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]) diff --git a/src/status_im/ui/screens/ens/views.cljs b/src/status_im/ui/screens/ens/views.cljs index ec1047100b..136462641f 100644 --- a/src/status_im/ui/screens/ens/views.cljs +++ b/src/status_im/ui/screens/ens/views.cljs @@ -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 [] diff --git a/src/status_im/utils/debounce.cljs b/src/status_im/utils/debounce.cljs new file mode 100644 index 0000000000..c8f4751e7f --- /dev/null +++ b/src/status_im/utils/debounce.cljs @@ -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))) \ No newline at end of file