fix(wallet): Validation of addresses in send-to screen (#20570)
* Fix validation of addresses in send-to screen
This commit is contained in:
parent
e8e05e58e0
commit
e221e23255
|
@ -309,7 +309,7 @@
|
||||||
[]
|
[]
|
||||||
(filter #(string/starts-with? (or (:ens-name %) "") input) contacts))]
|
(filter #(string/starts-with? (or (:ens-name %) "") input) contacts))]
|
||||||
(if (and input (empty? result))
|
(if (and input (empty? result))
|
||||||
(rf/dispatch [:wallet/search-ens input on-error-fn ".stateofus.eth"])
|
{:fx [[:dispatch [:wallet/search-ens input on-error-fn ".stateofus.eth"]]]}
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
(assoc-in [:wallet :ui :search-address :local-suggestions]
|
(assoc-in [:wallet :ui :search-address :local-suggestions]
|
||||||
(map #(assoc % :type item-types/saved-address) result))
|
(map #(assoc % :type item-types/saved-address) result))
|
||||||
|
|
|
@ -31,11 +31,10 @@
|
||||||
(defn- validate-address
|
(defn- validate-address
|
||||||
[address]
|
[address]
|
||||||
(debounce/debounce-and-dispatch
|
(debounce/debounce-and-dispatch
|
||||||
(if (and (> (count address) 0)
|
(cond
|
||||||
(not (or (validation/ens-name? address)
|
(<= (count address) 0) [:wallet/address-validation-failed address]
|
||||||
(validation/eth-address? address))))
|
(validation/eth-address? address) [:wallet/address-validation-success address]
|
||||||
[:wallet/address-validation-failed address]
|
:else [:wallet/address-validation-failed address])
|
||||||
[:wallet/address-validation-success address])
|
|
||||||
300))
|
300))
|
||||||
|
|
||||||
(defn- address-input
|
(defn- address-input
|
||||||
|
@ -59,12 +58,13 @@
|
||||||
:ens-regex constants/regx-ens
|
:ens-regex constants/regx-ens
|
||||||
:scanned-value (or (when recipient-plain-address? send-address) scanned-address)
|
:scanned-value (or (when recipient-plain-address? send-address) scanned-address)
|
||||||
:address-regex constants/regx-multichain-address
|
:address-regex constants/regx-multichain-address
|
||||||
:on-detect-address #(when (or (= current-screen-id :screen/wallet.select-address)
|
:on-detect-address (fn [address]
|
||||||
|
(when (or (= current-screen-id :screen/wallet.select-address)
|
||||||
(= current-screen-id :screen/wallet.scan-address))
|
(= current-screen-id :screen/wallet.scan-address))
|
||||||
; ^ this check is to prevent effect being triggered when screen is
|
; ^ this check is to prevent effect being triggered when screen
|
||||||
; loaded but not being shown to the user (deep in the navigation
|
; is loaded but not being shown to the user (deep in the
|
||||||
; stack) and avoid undesired behaviors
|
; navigation stack) and avoid undesired behaviors
|
||||||
(validate-address %))
|
(validate-address address)))
|
||||||
:on-detect-ens (fn [text cb]
|
:on-detect-ens (fn [text cb]
|
||||||
(when (or (= current-screen-id :screen/wallet.select-address)
|
(when (or (= current-screen-id :screen/wallet.select-address)
|
||||||
(= current-screen-id :screen/wallet.scan-address))
|
(= current-screen-id :screen/wallet.scan-address))
|
||||||
|
@ -75,8 +75,7 @@
|
||||||
[:wallet/find-ens text contacts cb]
|
[:wallet/find-ens text contacts cb]
|
||||||
300)))
|
300)))
|
||||||
:on-change-text (fn [text]
|
:on-change-text (fn [text]
|
||||||
(when (empty? text)
|
(rf/dispatch [:wallet/clean-local-suggestions])
|
||||||
(rf/dispatch [:wallet/clean-local-suggestions]))
|
|
||||||
(validate-address text)
|
(validate-address text)
|
||||||
(reset! input-value text))
|
(reset! input-value text))
|
||||||
:valid-ens-or-address? valid-ens-or-address?}])))
|
:valid-ens-or-address? valid-ens-or-address?}])))
|
||||||
|
@ -101,8 +100,9 @@
|
||||||
|
|
||||||
(defn- suggestion-component
|
(defn- suggestion-component
|
||||||
[]
|
[]
|
||||||
(fn [{:keys [type ens address accounts primary-name public-key ens-name color] :as local-suggestion} _
|
(fn [{:keys [type ens address accounts primary-name public-key ens-name color]
|
||||||
_ _]
|
:as local-suggestion}
|
||||||
|
_ _ _]
|
||||||
(let [props {:on-press (fn []
|
(let [props {:on-press (fn []
|
||||||
(let [address (if accounts (:address (first accounts)) address)]
|
(let [address (if accounts (:address (first accounts)) address)]
|
||||||
(when-not ens
|
(when-not ens
|
||||||
|
@ -114,11 +114,12 @@
|
||||||
(cond
|
(cond
|
||||||
(= type types/saved-address)
|
(= type types/saved-address)
|
||||||
[quo/saved-address
|
[quo/saved-address
|
||||||
(merge props
|
(assoc props
|
||||||
{:user-props {:name primary-name
|
:user-props
|
||||||
|
{:name primary-name
|
||||||
:address public-key
|
:address public-key
|
||||||
:ens ens-name
|
:ens ens-name
|
||||||
:customization-color color}})]
|
:customization-color color})]
|
||||||
(= type types/saved-contact-address)
|
(= type types/saved-contact-address)
|
||||||
[quo/saved-contact-address (merge props local-suggestion)]
|
[quo/saved-contact-address (merge props local-suggestion)]
|
||||||
(and (not ens) (= type types/address))
|
(and (not ens) (= type types/address))
|
||||||
|
@ -208,9 +209,7 @@
|
||||||
[rn/keyboard-avoiding-view
|
[rn/keyboard-avoiding-view
|
||||||
{:style {:flex 1}
|
{:style {:flex 1}
|
||||||
:keyboard-vertical-offset 26}
|
:keyboard-vertical-offset 26}
|
||||||
[rn/view
|
[rn/view {:style {:flex 1 :padding 8}}
|
||||||
{:style {:flex 1
|
|
||||||
:padding 8}}
|
|
||||||
[local-suggestions-list]]]
|
[local-suggestions-list]]]
|
||||||
[:<>
|
[:<>
|
||||||
[quo/tabs
|
[quo/tabs
|
||||||
|
|
Loading…
Reference in New Issue