diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index ee785ca67e3..680e7171333 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -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] @@ -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 diff --git a/src/status_im/contexts/wallet/send/select_address/view.cljs b/src/status_im/contexts/wallet/send/select_address/view.cljs index ad14c40d3cd..12db42ee7b8 100644 --- a/src/status_im/contexts/wallet/send/select_address/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/view.cljs @@ -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] @@ -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 [] @@ -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)) @@ -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?}]))) @@ -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}