From ba68ccdbacbed83bf9e0e09a3060ba4ff614f45c Mon Sep 17 00:00:00 2001 From: Brian Sztamfater Date: Mon, 4 Mar 2024 16:47:24 -0300 Subject: [PATCH] fix address input scan --- .../contexts/shell/jump_to/events.cljs | 10 ++- .../wallet/send/select_address/view.cljs | 87 ++++++++++--------- src/status_im/navigation/events.cljs | 10 ++- 3 files changed, 58 insertions(+), 49 deletions(-) diff --git a/src/status_im/contexts/shell/jump_to/events.cljs b/src/status_im/contexts/shell/jump_to/events.cljs index e352dab22d..935c836da6 100644 --- a/src/status_im/contexts/shell/jump_to/events.cljs +++ b/src/status_im/contexts/shell/jump_to/events.cljs @@ -150,10 +150,12 @@ (not hidden-screen?) (:current-chat-id db)) (conj [:chat/close]))}) - {:db (-> db - (assoc :view-id go-to-view-id) - (dissoc :modal-view-ids)) - :navigate-to go-to-view-id})) + (let [modal-view-ids (navigation.utils/remove-current-modal-stack (:modal-view-ids db))] + {:navigate-to go-to-view-id + :db (cond-> db + true (assoc :view-id go-to-view-id) + (seq modal-view-ids) (assoc :modal-view-ids modal-view-ids) + (not (seq modal-view-ids)) (dissoc :modal-view-ids))}))) (rf/defn shell-navigate-back {:events [:shell/navigate-back]} 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 da218485d1..e1eca33f5a 100644 --- a/src/status_im/contexts/wallet/send/select_address/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/view.cljs @@ -23,47 +23,52 @@ (defn- address-input [input-value input-focused?] - (fn [] - (let [current-screen-id (rf/sub [:navigation/current-screen-id]) - scanned-address (rf/sub [:wallet/scanned-address]) - send-address (rf/sub [:wallet/wallet-send-to-address]) - recipient (rf/sub [:wallet/wallet-send-recipient]) - recipient-plain-address? (= send-address recipient) - valid-ens-or-address? (rf/sub [:wallet/valid-ens-or-address?]) - chain-id (rf/sub [:chain-id]) - contacts (rf/sub [:contacts/active])] - [quo/address-input - {:on-focus #(reset! input-focused? true) - :on-blur #(reset! input-focused? false) - :on-scan (fn [] - (rn/dismiss-keyboard!) - (rf/dispatch [:wallet/clean-scanned-address]) - (rf/dispatch [:open-modal :scan-address])) - :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 :wallet-select-address) - (= current-screen-id :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 - (debounce/debounce-and-dispatch - [:wallet/validate-address %] - 300)) - :on-detect-ens (fn [text cb] - (when (or (= current-screen-id :wallet-select-address) - (= current-screen-id :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 - (debounce/debounce-and-dispatch - [:wallet/find-ens text contacts chain-id cb] - 300))) - :on-change-text (fn [text] - (when (empty? text) - (rf/dispatch [:wallet/clean-local-suggestions])) - (reset! input-value text)) - :valid-ens-or-address? valid-ens-or-address?}]))) + (let [set-value-fn (atom nil)] + (fn [] + (let [current-screen-id (rf/sub [:navigation/current-screen-id]) + scanned-address (rf/sub [:wallet/scanned-address]) + send-address (rf/sub [:wallet/wallet-send-to-address]) + recipient (rf/sub [:wallet/wallet-send-recipient]) + recipient-plain-address? (= send-address recipient) + valid-ens-or-address? (rf/sub [:wallet/valid-ens-or-address?]) + chain-id (rf/sub [:chain-id]) + contacts (rf/sub [:contacts/active])] + (when (and @set-value-fn scanned-address) + (@set-value-fn scanned-address) + (reset! set-value-fn nil)) + [quo/address-input + {:on-focus #(reset! input-focused? true) + :on-blur #(reset! input-focused? false) + :on-scan (fn [set-value] + (reset! set-value-fn set-value) + (rn/dismiss-keyboard!) + (rf/dispatch [:wallet/clean-scanned-address]) + (rf/dispatch [:open-modal :scan-address])) + :ens-regex constants/regx-ens + :default-value (when recipient-plain-address? send-address) + :address-regex constants/regx-multichain-address + :on-detect-address #(when (or (= current-screen-id :wallet-select-address) + (= current-screen-id :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 + (debounce/debounce-and-dispatch + [:wallet/validate-address %] + 300)) + :on-detect-ens (fn [text cb] + (when (or (= current-screen-id :wallet-select-address) + (= current-screen-id :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 + (debounce/debounce-and-dispatch + [:wallet/find-ens text contacts chain-id cb] + 300))) + :on-change-text (fn [text] + (when (empty? text) + (rf/dispatch [:wallet/clean-local-suggestions])) + (reset! input-value text)) + :valid-ens-or-address? valid-ens-or-address?}])))) (defn- ens-linked-address [{:keys [address networks theme]}] diff --git a/src/status_im/navigation/events.cljs b/src/status_im/navigation/events.cljs index fe7442d40d..6a88ada28a 100644 --- a/src/status_im/navigation/events.cljs +++ b/src/status_im/navigation/events.cljs @@ -81,13 +81,15 @@ (rf/defn init-root {:events [:init-root]} - [_ root-id] - {:set-root root-id}) + [{:keys [db]} root-id] + {:set-root root-id + :db (dissoc db :modal-view-ids)}) (rf/defn set-stack-root {:events [:set-stack-root]} - [_ stack root] - {:set-stack-root-fx [stack root]}) + [{:keys [db]} stack root] + {:set-stack-root-fx [stack root] + :db (dissoc db :modal-view-ids)}) (rf/defn change-tab {:events [:navigate-change-tab]}