Skip to content

Commit

Permalink
Merge branch 'develop' into refresh-control-test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmilad75 committed May 6, 2024
2 parents 920a198 + b907881 commit ef0d376
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 47 deletions.
1 change: 1 addition & 0 deletions src/status_im/common/bottom_sheet/style.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
(defn sheet
[{:keys [max-height]}]
{:position :absolute
:overflow :hidden
:bottom 0
:left 0
:right 0
Expand Down
51 changes: 7 additions & 44 deletions src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:require
[camel-snake-kebab.extras :as cske]
[clojure.string :as string]
[react-native.background-timer :as background-timer]
[react-native.platform :as platform]
[status-im.constants :as constants]
[status-im.contexts.wallet.common.utils.networks :as network-utils]
Expand Down Expand Up @@ -329,55 +328,19 @@
(assoc-in [:wallet :ui :search-address :local-suggestions] suggestion)
(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 (-> 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 (-> 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]} [_]]
(fn [{:keys [db]}]
{: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-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 (-> 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-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 (-> 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
(rf/reg-event-fx :wallet/address-validation-failed
(fn [{:keys [db]}]
(let [current-timeout (get-in db [:wallet :ui :search-address :search-timeout])]
(background-timer/clear-timeout current-timeout)
{:db (-> db
(assoc-in [:wallet :ui :search-address :local-suggestions] [])
(assoc-in [:wallet :ui :search-address :valid-ens-or-address?] false))})))
{:db (assoc-in db [:wallet :ui :search-address :valid-ens-or-address?] false)}))

(rf/reg-event-fx :wallet/clean-ens-or-address-validation
(rf/reg-event-fx :wallet/clean-local-suggestions
(fn [{:keys [db]}]
{:db (assoc-in db [:wallet :ui :search-address :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/navigate-to-chain-explorer-from-bottom-sheet
Expand Down
23 changes: 20 additions & 3 deletions src/status_im/contexts/wallet/send/select_address/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.constants :as constants]
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
[status-im.contexts.wallet.common.validation :as validation]
[status-im.contexts.wallet.item-types :as types]
[status-im.contexts.wallet.send.select-address.style :as style]
[status-im.contexts.wallet.send.select-address.tabs.view :as tabs]
Expand All @@ -23,6 +24,16 @@
{:id :tab/contacts :label (i18n/label :t/contacts) :accessibility-label :contacts-tab})
{:id :tab/my-accounts :label (i18n/label :t/my-accounts) :accessibility-label :my-accounts-tab}])

(defn- validate-address
[address]
(debounce/debounce-and-dispatch
(if (and (> (count address) 0)
(not (or (validation/ens-name? address)
(validation/eth-address? address))))
[:wallet/address-validation-failed address]
[:wallet/address-validation-success address])
300))

(defn- address-input
[input-value input-focused?]
(fn []
Expand All @@ -49,9 +60,7 @@
; ^ this check is to prevent effect being triggered when screen is
; loaded but not being shown to the user (deep in the navigation
; stack) and avoid undesired behaviors
(debounce/debounce-and-dispatch
[:wallet/validate-address %]
300))
(validate-address %))
:on-detect-ens (fn [text cb]
(when (or (= current-screen-id :screen/wallet.select-address)
(= current-screen-id :screen/wallet.scan-address))
Expand All @@ -64,6 +73,7 @@
:on-change-text (fn [text]
(when (empty? text)
(rf/dispatch [:wallet/clean-local-suggestions]))
(validate-address text)
(reset! input-value text))
:valid-ens-or-address? valid-ens-or-address?}])))

Expand Down Expand Up @@ -167,6 +177,13 @@
:title-accessibility-label :title-label}]
[address-input input-value input-focused?]
[quo/divider-line]
(when (and (not valid-ens-or-address?) (> (count @input-value) 0))
[rn/view {:style {:padding 20}}
[quo/info-message
{:type :error
:icon :i/info
:size :default}
(i18n/label :t/invalid-address)]])
(if (or @input-focused? (> (count @input-value) 0))
[rn/keyboard-avoiding-view
{:style {:flex 1}
Expand Down

0 comments on commit ef0d376

Please sign in to comment.