Root keys named :wallet/... moved as nested under :wallet root key (#19152)

This commit is contained in:
Volodymyr Kozieiev 2024-03-11 21:19:48 +00:00 committed by GitHub
parent 459bf1621a
commit e4997a2088
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 70 additions and 32 deletions

View File

@ -282,10 +282,11 @@
(filter #(string/starts-with? (or (:ens-name %) "") input) contacts))]
(if (and input (empty? result))
(rf/dispatch [:wallet/search-ens input chain-id cb ".stateofus.eth"])
{:db (assoc db
:wallet/local-suggestions
(map #(assoc % :type item-types/saved-address) result)
:wallet/valid-ens-or-address? (not-empty result))}))))
{:db (-> db
(assoc-in [:wallet :ui :search-address :local-suggestions]
(map #(assoc % :type item-types/saved-address) result))
(assoc-in [:wallet :ui :search-address :valid-ens-or-address?]
(not-empty result)))}))))
(rf/reg-event-fx :wallet/search-ens
(fn [_ [input chain-id cb domain]]
@ -303,62 +304,67 @@
(rf/reg-event-fx :wallet/set-ens-address
(fn [{:keys [db]} [result ens]]
{:db (assoc db
:wallet/local-suggestions (if result
{:db
(-> db
(assoc-in [:wallet :ui :search-address :local-suggestions]
(if result
[{:type item-types/address
:ens ens
:address (eip55/address->checksum result)
:networks [:ethereum :optimism]}]
[])
:wallet/valid-ens-or-address? (boolean result))}))
[]))
(assoc-in [:wallet :ui :search-address :valid-ens-or-address?]
(boolean result)))}))
(rf/reg-event-fx :wallet/fetch-address-suggestions
(fn [{:keys [db]} [_address]]
{:db (assoc db
:wallet/local-suggestions nil
:wallet/valid-ens-or-address? false)}))
{:db (-> db
(assoc-in [:wallet :ui :search-address :local-suggestions] nil)
(assoc-in [:wallet :ui :search-address :valid-ens-or-address?] false))}))
(rf/reg-event-fx :wallet/ens-validation-success
(fn [{:keys [db]} [_ens]]
{:db (assoc db
:wallet/local-suggestions nil
:wallet/valid-ens-or-address? true)}))
{:db (-> db
(assoc-in [:wallet :ui :search-address :local-suggestions] nil)
(assoc-in [:wallet :ui :search-address :valid-ens-or-address?] true))}))
(rf/reg-event-fx :wallet/address-validation-success
(fn [{:keys [db]} [_]]
{:db (assoc db :wallet/valid-ens-or-address? true)}))
{:db (assoc-in db [:wallet :ui :search-address :valid-ens-or-address?] true)}))
(rf/reg-event-fx :wallet/validate-address
(fn [{:keys [db]} [address]]
(let [current-timeout (get db :wallet/search-timeout)
(let [current-timeout (get-in db [:wallet :ui :search-address :search-timeout])
timeout (background-timer/set-timeout
#(rf/dispatch [:wallet/address-validation-success address])
2000)]
(background-timer/clear-timeout current-timeout)
{:db (assoc db
:wallet/valid-ens-or-address? false
:wallet/search-timeout timeout)})))
{:db (-> db
(assoc-in [:wallet :ui :search-address :search-timeout] timeout)
(assoc-in [:wallet :ui :search-address :valid-ens-or-address?] false))})))
(rf/reg-event-fx :wallet/validate-ens
(fn [{:keys [db]} [ens]]
(let [current-timeout (get db :wallet/search-timeout)
(let [current-timeout (get-in db [:wallet :ui :search-address :search-timeout])
timeout (background-timer/set-timeout
#(rf/dispatch [:wallet/ens-validation-success ens])
2000)]
(background-timer/clear-timeout current-timeout)
{:db (assoc db
:wallet/valid-ens-or-address? false
:wallet/search-timeout timeout)})))
{:db (-> db
(assoc-in [:wallet :ui :search-address :search-timeout] timeout)
(assoc-in [:wallet :ui :search-address :valid-ens-or-address?] false))})))
(rf/reg-event-fx :wallet/clean-local-suggestions
(fn [{:keys [db]}]
(let [current-timeout (get db :wallet/search-timeout)]
(let [current-timeout (get-in db [:wallet :ui :search-address :search-timeout])]
(background-timer/clear-timeout current-timeout)
{:db (assoc db :wallet/local-suggestions [] :wallet/valid-ens-or-address? false)})))
{:db (-> db
(assoc-in [:wallet :ui :search-address :local-suggestions] [])
(assoc-in [:wallet :ui :search-address :valid-ens-or-address?] false))})))
(rf/reg-event-fx :wallet/clean-ens-or-address-validation
(fn [{:keys [db]}]
{:db (assoc db :wallet/valid-ens-or-address? false)}))
{:db (assoc-in db [:wallet :ui :search-address :valid-ens-or-address?] false)}))
(rf/reg-event-fx
:wallet/navigate-to-chain-explorer-from-bottom-sheet

View File

@ -156,8 +156,6 @@
;;wallet
(reg-root-key-sub :wallet :wallet)
(reg-root-key-sub :wallet/local-suggestions :wallet/local-suggestions)
(reg-root-key-sub :wallet/valid-ens-or-address? :wallet/valid-ens-or-address?)
;;debug
(when js/goog.DEBUG

View File

@ -267,3 +267,18 @@
:wallet/transactions
:<- [:wallet]
:-> :transactions)
(rf/reg-sub
:wallet/search-address
:<- [:wallet/ui]
:-> :search-address)
(rf/reg-sub
:wallet/local-suggestions
:<- [:wallet/search-address]
:-> :local-suggestions)
(rf/reg-sub
:wallet/valid-ens-or-address?
:<- [:wallet/search-address]
:-> :valid-ens-or-address?)

View File

@ -516,3 +516,22 @@
(is
(= keypairs
(rf/sub [sub-name])))))
(def local-suggestions ["a" "b"])
(h/deftest-sub :wallet/local-suggestions
[sub-name]
(testing "returns local suggestions:"
(swap! rf-db/app-db
#(assoc-in % [:wallet :ui :search-address :local-suggestions] local-suggestions))
(is
(= local-suggestions
(rf/sub [sub-name])))))
(h/deftest-sub :wallet/valid-ens-or-address?
[sub-name]
(testing "returns local suggestions:"
(swap! rf-db/app-db
#(assoc-in % [:wallet :ui :search-address :valid-ens-or-address?] true))
(is
(rf/sub [sub-name]))))