mirror of
https://github.com/status-im/status-react.git
synced 2025-01-23 01:09:49 +00:00
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.utils.money :as money]
|
||||||
[status-im.signing.core :as signing]
|
[status-im.signing.core :as signing]
|
||||||
[status-im.multiaccounts.update.core :as multiaccounts.update]
|
[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]))
|
(:refer-clojure :exclude [name]))
|
||||||
|
|
||||||
(defn fullname [custom-domain? username]
|
(defn fullname [custom-domain? username]
|
||||||
@ -105,26 +106,27 @@
|
|||||||
{:routeName :ens-confirmation}]}))
|
{:routeName :ens-confirmation}]}))
|
||||||
|
|
||||||
(defn- on-resolve-owner
|
(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]
|
||||||
(cond
|
(when (= @resolve-last-id* resolve-last-id)
|
||||||
|
(cond
|
||||||
|
|
||||||
;; No address for a stateofus subdomain: it can be registered
|
;; No address for a stateofus subdomain: it can be registered
|
||||||
(and (= response ens/default-address) (not custom-domain?))
|
(and (= response ens/default-address) (not custom-domain?))
|
||||||
(re-frame/dispatch [::name-resolved username :available])
|
(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)
|
||||||
(eip55/address->checksum response))
|
(eip55/address->checksum response))
|
||||||
(resolver/pubkey registry (fullname custom-domain? username)
|
(resolver/pubkey registry (fullname custom-domain? username)
|
||||||
#(re-frame/dispatch [::name-resolved username
|
#(re-frame/dispatch [::name-resolved username
|
||||||
(cond
|
(cond
|
||||||
(not public-key) :owned
|
(not public-key) :owned
|
||||||
(= % public-key) :connected
|
(= % public-key) :connected
|
||||||
:else :connected-with-different-key)]))
|
:else :connected-with-different-key)]))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(re-frame/dispatch [::name-resolved username :taken])))
|
(re-frame/dispatch [::name-resolved username :taken]))))
|
||||||
|
|
||||||
(defn registration-cost
|
(defn registration-cost
|
||||||
[chain-id]
|
[chain-id]
|
||||||
@ -174,12 +176,16 @@
|
|||||||
:searching)
|
:searching)
|
||||||
:else :invalid))
|
:else :invalid))
|
||||||
|
|
||||||
|
;;NOTE we want to handle only last resolve
|
||||||
|
(def resolve-last-id (atom nil))
|
||||||
|
|
||||||
(fx/defn set-username-candidate
|
(fx/defn set-username-candidate
|
||||||
{:events [::set-username-candidate]}
|
{:events [::set-username-candidate]}
|
||||||
[{:keys [db]} username]
|
[{:keys [db]} username]
|
||||||
(let [{:keys [custom-domain?]} (:ens/registration db)
|
(let [{:keys [custom-domain?]} (:ens/registration db)
|
||||||
usernames (into #{} (get-in db [:multiaccount :usernames]))
|
usernames (into #{} (get-in db [:multiaccount :usernames]))
|
||||||
state (state custom-domain? username usernames)]
|
state (state custom-domain? username usernames)]
|
||||||
|
(reset! resolve-last-id (random/id))
|
||||||
(merge
|
(merge
|
||||||
{:db (update db :ens/registration assoc
|
{:db (update db :ens/registration assoc
|
||||||
:username username
|
:username username
|
||||||
@ -191,7 +197,9 @@
|
|||||||
registry (get ens/ens-registries (ethereum/chain-keyword db))]
|
registry (get ens/ens-registries (ethereum/chain-keyword db))]
|
||||||
{::resolve-owner [registry
|
{::resolve-owner [registry
|
||||||
(fullname custom-domain? username)
|
(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
|
(fx/defn return-to-ens-main-screen
|
||||||
{:events [::got-it-pressed ::cancel-pressed]}
|
{:events [::got-it-pressed ::cancel-pressed]}
|
||||||
|
@ -143,7 +143,9 @@
|
|||||||
:render-error web-view-error
|
:render-error web-view-error
|
||||||
:on-navigation-state-change #(do
|
:on-navigation-state-change #(do
|
||||||
(re-frame/dispatch [:set-in [:ens/registration :state] :searching])
|
(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-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])
|
||||||
|
@ -118,7 +118,7 @@
|
|||||||
|
|
||||||
(:available :connected :connected-with-different-key :owned)
|
(:available :connected :connected-with-different-key :owned)
|
||||||
[react/touchable-highlight
|
[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
|
[icon-wrapper colors/blue
|
||||||
[vector-icons/icon :main-icons/arrow-right {:color colors/white}]]]
|
[vector-icons/icon :main-icons/arrow-right {:color colors/white}]]]
|
||||||
|
|
||||||
@ -199,7 +199,7 @@
|
|||||||
{:ref #(reset! input-ref %)
|
{:ref #(reset! input-ref %)
|
||||||
:on-change-text #(do
|
:on-change-text #(do
|
||||||
(re-frame/dispatch [:set-in [:ens/registration :state] :searching])
|
(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])
|
:on-submit-editing #(re-frame/dispatch [::ens/input-submitted])
|
||||||
:auto-capitalize :none
|
:auto-capitalize :none
|
||||||
:auto-complete-type "off"
|
:auto-complete-type "off"
|
||||||
|
@ -1,11 +1,24 @@
|
|||||||
(ns status-im.utils.debounce
|
(ns status-im.utils.debounce
|
||||||
(:require [re-frame.core :as re-frame]))
|
(: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))
|
(when @timeout (js/clearTimeout @timeout))
|
||||||
(reset! timeout (js/setTimeout #(re-frame/dispatch event) time)))
|
(reset! timeout (js/setTimeout #(re-frame/dispatch event) time)))
|
||||||
|
|
||||||
(defn clear []
|
(defn clear []
|
||||||
(when @timeout (js/clearTimeout @timeout)))
|
(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…
x
Reference in New Issue
Block a user