fix(wallet): Validation of addresses in send-to screen (#20570)

* Fix validation of addresses in send-to screen
This commit is contained in:
Ulises Manuel 2024-07-02 13:57:31 -06:00 committed by GitHub
parent e8e05e58e0
commit e221e23255
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 24 deletions

View File

@ -309,7 +309,7 @@
[]
(filter #(string/starts-with? (or (:ens-name %) "") input) contacts))]
(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
(assoc-in [:wallet :ui :search-address :local-suggestions]
(map #(assoc % :type item-types/saved-address) result))

View File

@ -31,11 +31,10 @@
(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])
(cond
(<= (count address) 0) [:wallet/address-validation-failed address]
(validation/eth-address? address) [:wallet/address-validation-success address]
:else [:wallet/address-validation-failed address])
300))
(defn- address-input
@ -59,12 +58,13 @@
:ens-regex constants/regx-ens
:scanned-value (or (when recipient-plain-address? send-address) scanned-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))
; ^ 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
(validate-address %))
; ^ 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
(validate-address address)))
:on-detect-ens (fn [text cb]
(when (or (= current-screen-id :screen/wallet.select-address)
(= current-screen-id :screen/wallet.scan-address))
@ -75,8 +75,7 @@
[:wallet/find-ens text contacts cb]
300)))
:on-change-text (fn [text]
(when (empty? text)
(rf/dispatch [:wallet/clean-local-suggestions]))
(rf/dispatch [:wallet/clean-local-suggestions])
(validate-address text)
(reset! input-value text))
:valid-ens-or-address? valid-ens-or-address?}])))
@ -101,8 +100,9 @@
(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 [address (if accounts (:address (first accounts)) address)]
(when-not ens
@ -114,11 +114,12 @@
(cond
(= type types/saved-address)
[quo/saved-address
(merge props
{:user-props {:name primary-name
(assoc props
:user-props
{:name primary-name
:address public-key
:ens ens-name
:customization-color color}})]
:customization-color color})]
(= type types/saved-contact-address)
[quo/saved-contact-address (merge props local-suggestion)]
(and (not ens) (= type types/address))
@ -208,9 +209,7 @@
[rn/keyboard-avoiding-view
{:style {:flex 1}
:keyboard-vertical-offset 26}
[rn/view
{:style {:flex 1
:padding 8}}
[rn/view {:style {:flex 1 :padding 8}}
[local-suggestions-list]]]
[:<>
[quo/tabs