handle only last resolve , chill button
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
831f7f05f3
commit
67f64f3816
|
@ -18,7 +18,8 @@
|
|||
[status-im.utils.money :as money]
|
||||
[status-im.signing.core :as signing]
|
||||
[status-im.multiaccounts.update.core :as multiaccounts.update]
|
||||
[taoensso.timbre :as log])
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.utils.random :as random])
|
||||
(:refer-clojure :exclude [name]))
|
||||
|
||||
(defn fullname [custom-domain? username]
|
||||
|
@ -105,7 +106,8 @@
|
|||
{:routeName :ens-confirmation}]}))
|
||||
|
||||
(defn- on-resolve-owner
|
||||
[registry custom-domain? username address public-key response]
|
||||
[registry custom-domain? username address public-key response resolve-last-id* resolve-last-id]
|
||||
(when (= @resolve-last-id* resolve-last-id)
|
||||
(cond
|
||||
|
||||
;; No address for a stateofus subdomain: it can be registered
|
||||
|
@ -124,7 +126,7 @@
|
|||
:else :connected-with-different-key)]))
|
||||
|
||||
:else
|
||||
(re-frame/dispatch [::name-resolved username :taken])))
|
||||
(re-frame/dispatch [::name-resolved username :taken]))))
|
||||
|
||||
(defn registration-cost
|
||||
[chain-id]
|
||||
|
@ -174,12 +176,16 @@
|
|||
:searching)
|
||||
:else :invalid))
|
||||
|
||||
;;NOTE we want to handle only last resolve
|
||||
(def resolve-last-id (atom nil))
|
||||
|
||||
(fx/defn set-username-candidate
|
||||
{:events [::set-username-candidate]}
|
||||
[{:keys [db]} username]
|
||||
(let [{:keys [custom-domain?]} (:ens/registration db)
|
||||
usernames (into #{} (get-in db [:multiaccount :usernames]))
|
||||
state (state custom-domain? username usernames)]
|
||||
(reset! resolve-last-id (random/id))
|
||||
(merge
|
||||
{:db (update db :ens/registration assoc
|
||||
:username username
|
||||
|
@ -191,7 +197,9 @@
|
|||
registry (get ens/ens-registries (ethereum/chain-keyword db))]
|
||||
{::resolve-owner [registry
|
||||
(fullname custom-domain? username)
|
||||
#(on-resolve-owner registry custom-domain? username address public-key %)]})))))
|
||||
#(on-resolve-owner
|
||||
registry custom-domain? username address public-key %
|
||||
resolve-last-id @resolve-last-id)]})))))
|
||||
|
||||
(fx/defn return-to-ens-main-screen
|
||||
{:events [::got-it-pressed ::cancel-pressed]}
|
||||
|
|
|
@ -143,7 +143,9 @@
|
|||
:render-error web-view-error
|
||||
:on-navigation-state-change #(do
|
||||
(re-frame/dispatch [:set-in [:ens/registration :state] :searching])
|
||||
(debounce/debounce [:browser/navigation-state-changed % error?] 500))
|
||||
(debounce/debounce-and-dispatch
|
||||
[: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])
|
||||
|
|
|
@ -118,7 +118,7 @@
|
|||
|
||||
(:available :connected :connected-with-different-key :owned)
|
||||
[react/touchable-highlight
|
||||
{:on-press #(re-frame/dispatch [::ens/input-icon-pressed])}
|
||||
{:on-press #(debounce/dispatch-and-chill [::ens/input-icon-pressed] 3000)}
|
||||
[icon-wrapper colors/blue
|
||||
[vector-icons/icon :main-icons/arrow-right {:color colors/white}]]]
|
||||
|
||||
|
@ -199,7 +199,7 @@
|
|||
{:ref #(reset! input-ref %)
|
||||
:on-change-text #(do
|
||||
(re-frame/dispatch [:set-in [:ens/registration :state] :searching])
|
||||
(debounce/debounce [::ens/set-username-candidate %] 600))
|
||||
(debounce/debounce-and-dispatch [::ens/set-username-candidate %] 600))
|
||||
:on-submit-editing #(re-frame/dispatch [::ens/input-submitted])
|
||||
:auto-capitalize :none
|
||||
:auto-complete-type "off"
|
||||
|
|
|
@ -1,11 +1,24 @@
|
|||
(ns status-im.utils.debounce
|
||||
(:require [re-frame.core :as re-frame]))
|
||||
|
||||
(def timeout (atom {}))
|
||||
(def timeout (atom nil))
|
||||
|
||||
(defn debounce [event time]
|
||||
(defn debounce-and-dispatch
|
||||
"Dispatches event only if there were no calls of this function in period of *time* ms"
|
||||
[event time]
|
||||
(when @timeout (js/clearTimeout @timeout))
|
||||
(reset! timeout (js/setTimeout #(re-frame/dispatch event) time)))
|
||||
|
||||
(defn clear []
|
||||
(when @timeout (js/clearTimeout @timeout)))
|
||||
|
||||
(def chill? (atom false))
|
||||
|
||||
(defn dispatch-and-chill
|
||||
"Dispateches event and ignores next calls in period of *time* ms"
|
||||
[event time]
|
||||
(when-not @chill?
|
||||
(reset! chill? true)
|
||||
(js/setTimeout #(reset! chill? false) time)
|
||||
(re-frame/dispatch event)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue