From 0e6d59b31262b74a0991240e83075f638c42b833 Mon Sep 17 00:00:00 2001 From: Omar Basem Date: Fri, 12 Jul 2024 17:09:42 +0400 Subject: [PATCH] fix: hardware induced back actions (#20183) * fix: hardware induced back actions (#20183) --- src/status_im/contexts/wallet/account/view.cljs | 8 +++++--- .../create_account/import_private_key/view.cljs | 3 ++- .../wallet/add_account/create_account/view.cljs | 3 ++- .../contexts/wallet/bridge/bridge_to/view.cljs | 3 ++- .../contexts/wallet/bridge/input_amount/view.cljs | 6 +++--- src/status_im/contexts/wallet/events.cljs | 12 +++++++----- src/status_im/contexts/wallet/send/events.cljs | 14 +++++++++++--- src/status_im/contexts/wallet/send/from/view.cljs | 8 ++++---- .../contexts/wallet/send/input_amount/view.cljs | 4 +++- .../contexts/wallet/send/select_address/view.cljs | 7 ++++--- .../contexts/wallet/send/select_asset/view.cljs | 7 ++++--- .../contexts/wallet/send/send_amount/view.cljs | 3 +-- .../wallet/swap/select_asset_to_pay/view.cljs | 5 +++-- src/status_im/subs/wallet/send.cljs | 5 +++++ 14 files changed, 56 insertions(+), 32 deletions(-) diff --git a/src/status_im/contexts/wallet/account/view.cljs b/src/status_im/contexts/wallet/account/view.cljs index a466345f8b..f11421d1ef 100644 --- a/src/status_im/contexts/wallet/account/view.cljs +++ b/src/status_im/contexts/wallet/account/view.cljs @@ -7,6 +7,7 @@ [status-im.contexts.wallet.common.account-switcher.view :as account-switcher] [status-im.contexts.wallet.sheets.buy-token.view :as buy-token] [status-im.feature-flags :as ff] + [status-im.setup.hot-reload :as hot-reload] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -28,14 +29,15 @@ {:keys [name color formatted-balance watch-only?]} (rf/sub [:wallet/current-viewing-account]) customization-color (rf/sub [:profile/customization-color])] - (rn/use-unmount #(rf/dispatch [:wallet/clean-send-data])) + (hot-reload/use-safe-unmount (fn [] + (rf/dispatch [:wallet/close-account-page]) + (rf/dispatch [:wallet/clean-current-viewing-account]))) (rn/use-mount #(rf/dispatch [:wallet/fetch-activities-for-current-account])) [rn/view {:style {:flex 1}} [account-switcher/view {:type :wallet-networks - :on-press (fn [] - (rf/dispatch [:wallet/close-account-page]))}] + :on-press #(rf/dispatch [:pop-to-root :shell-stack])}] [quo/account-overview {:container-style style/account-overview :current-value formatted-balance diff --git a/src/status_im/contexts/wallet/add_account/create_account/import_private_key/view.cljs b/src/status_im/contexts/wallet/add_account/create_account/import_private_key/view.cljs index 0b7d205d75..508f8e90d1 100644 --- a/src/status_im/contexts/wallet/add_account/create_account/import_private_key/view.cljs +++ b/src/status_im/contexts/wallet/add_account/create_account/import_private_key/view.cljs @@ -8,6 +8,7 @@ [status-im.common.floating-button-page.view :as floating-button-page] [status-im.contexts.wallet.add-account.create-account.import-private-key.style :as style] [status-im.contexts.wallet.common.validation :as v] + [status-im.setup.hot-reload :as hot-reload] [utils.debounce :as debounce] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -112,7 +113,7 @@ public-address (rf/sub [:wallet/public-address]) [flow-state set-flow-state] (rn/use-state nil) error? (= :invalid-private-key flow-state)] - (rn/use-unmount on-unmount) + (hot-reload/use-safe-unmount on-unmount) [rn/view {:flex 1} [floating-button-page/view {:customization-color customization-color diff --git a/src/status_im/contexts/wallet/add_account/create_account/view.cljs b/src/status_im/contexts/wallet/add_account/create_account/view.cljs index c0af91a51f..4fca1cca93 100644 --- a/src/status_im/contexts/wallet/add_account/create_account/view.cljs +++ b/src/status_im/contexts/wallet/add_account/create_account/view.cljs @@ -15,6 +15,7 @@ [status-im.contexts.wallet.common.utils :as common.utils] [status-im.contexts.wallet.sheets.account-origin.view :as account-origin] [status-im.feature-flags :as ff] + [status-im.setup.hot-reload :as hot-reload] [utils.i18n :as i18n] [utils.re-frame :as rf] [utils.responsiveness :as responsiveness] @@ -313,7 +314,7 @@ error (or @account-name-error @emoji-and-color-error?)] (rn/use-mount #(check-emoji-and-color-error @emoji @account-color)) - (rn/use-unmount #(rf/dispatch [:wallet/clear-create-account])) + (hot-reload/use-safe-unmount #(rf/dispatch [:wallet/clear-create-account])) (if keypair-name [add-new-keypair-variant diff --git a/src/status_im/contexts/wallet/bridge/bridge_to/view.cljs b/src/status_im/contexts/wallet/bridge/bridge_to/view.cljs index 8a8387146f..1aa2d9e339 100644 --- a/src/status_im/contexts/wallet/bridge/bridge_to/view.cljs +++ b/src/status_im/contexts/wallet/bridge/bridge_to/view.cljs @@ -9,6 +9,7 @@ [status-im.contexts.wallet.common.account-switcher.view :as account-switcher] [status-im.contexts.wallet.common.utils :as utils] [status-im.contexts.wallet.common.utils.networks :as network-utils] + [status-im.setup.hot-reload :as hot-reload] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -52,7 +53,7 @@ bridge-to-title (i18n/label :t/bridge-to {:name (string/upper-case (str token-symbol))})] - (rn/use-unmount #(rf/dispatch [:wallet/clean-bridge-to-selection])) + (hot-reload/use-safe-unmount #(rf/dispatch [:wallet/clean-bridge-to-selection])) [rn/view [account-switcher/view diff --git a/src/status_im/contexts/wallet/bridge/input_amount/view.cljs b/src/status_im/contexts/wallet/bridge/input_amount/view.cljs index 6826191cb5..78a1902aff 100644 --- a/src/status_im/contexts/wallet/bridge/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/bridge/input_amount/view.cljs @@ -3,12 +3,13 @@ [react-native.core :as rn] [status-im.contexts.wallet.bridge.input-amount.style :as style] [status-im.contexts.wallet.send.input-amount.view :as input-amount] + [status-im.setup.hot-reload :as hot-reload] [utils.i18n :as i18n] [utils.re-frame :as rf])) (defn view [] - (rn/use-unmount #(rf/dispatch [:wallet/clean-routes-calculation])) + (hot-reload/use-safe-unmount #(rf/dispatch [:wallet/clean-routes-calculation])) [rn/view {:style style/bridge-send-wrapper} [input-amount/view {:current-screen-id :screen/wallet.bridge-input-amount @@ -20,5 +21,4 @@ :stack-id :screen/wallet.bridge-input-amount}])) :on-navigate-back (fn [] (rf/dispatch [:wallet/clean-disabled-from-networks]) - (rf/dispatch [:wallet/clean-send-amount]) - (rf/dispatch [:navigate-back]))}]]) + (rf/dispatch [:wallet/clean-send-amount]))}]]) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 4cefbcec2f..1bcdc760b3 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -66,13 +66,15 @@ (rf/reg-event-fx :wallet/clean-current-viewing-account (fn [{:keys [db]}] - {:db (update db :wallet dissoc :current-viewing-account-address)})) + (let [just-completed-transaction? (get-in db [:wallet :ui :send :just-completed-transaction?])] + (when-not just-completed-transaction? + {:db (update db :wallet dissoc :current-viewing-account-address)})))) (rf/reg-event-fx :wallet/close-account-page - (fn [_] - {:fx [[:dispatch [:wallet/clean-current-viewing-account]] - [:dispatch [:wallet/clear-account-tab]] - [:dispatch [:pop-to-root :shell-stack]]]})) + (fn [{:keys [db]}] + (let [just-completed-transaction? (get-in db [:wallet :ui :send :just-completed-transaction?])] + (when-not just-completed-transaction? + {:fx [[:dispatch [:wallet/clear-account-tab]]]})))) (defn log-rpc-error [_ [{:keys [event params]} error]] diff --git a/src/status_im/contexts/wallet/send/events.cljs b/src/status_im/contexts/wallet/send/events.cljs index 0582c8ac8f..43e035a178 100644 --- a/src/status_im/contexts/wallet/send/events.cljs +++ b/src/status_im/contexts/wallet/send/events.cljs @@ -487,10 +487,18 @@ transaction-details (send-utils/map-multitransaction-by-ids transaction-batch-id transaction-hashes)] {:db (-> db + (assoc-in [:wallet :ui :send :just-completed-transaction?] true) (assoc-in [:wallet :transactions] transaction-details) (assoc-in [:wallet :ui :send :transaction-ids] transaction-ids)) :fx [[:dispatch - [:wallet/end-transaction-flow]]]}))) + [:wallet/end-transaction-flow]] + [:dispatch-later + [{:ms 2000 + :dispatch [:wallet/clean-just-completed-transaction]}]]]}))) + +(rf/reg-event-fx :wallet/clean-just-completed-transaction + (fn [{:keys [db]}] + {:db (update-in db [:wallet :ui :send] dissoc :just-completed-transaction?)})) (rf/reg-event-fx :wallet/clean-up-transaction-flow (fn [_] @@ -659,8 +667,8 @@ {:json-rpc/call [{:method "wallet_createMultiTransaction" :params request-params :on-success (fn [result] - (rf/dispatch [:hide-bottom-sheet]) - (rf/dispatch [:wallet/add-authorized-transaction result])) + (rf/dispatch [:wallet/add-authorized-transaction result]) + (rf/dispatch [:hide-bottom-sheet])) :on-error (fn [error] (log/error "failed to send transaction" {:event :wallet/send-transaction diff --git a/src/status_im/contexts/wallet/send/from/view.cljs b/src/status_im/contexts/wallet/send/from/view.cljs index 81fa2652f6..43fc1b78a9 100644 --- a/src/status_im/contexts/wallet/send/from/view.cljs +++ b/src/status_im/contexts/wallet/send/from/view.cljs @@ -6,6 +6,7 @@ [status-im.common.floating-button-page.view :as floating-button-page] [status-im.contexts.wallet.common.account-switcher.view :as account-switcher] [status-im.contexts.wallet.send.from.style :as style] + [status-im.setup.hot-reload :as hot-reload] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -18,9 +19,7 @@ (defn- on-close [] - (rf/dispatch [:wallet/clean-current-viewing-account]) - (rf/dispatch [:wallet/clean-send-data]) - (rf/dispatch [:navigate-back])) + (rf/dispatch [:wallet/clean-current-viewing-account])) (defn- render-fn [item _ _ {:keys [network-details]}] @@ -36,10 +35,11 @@ [] (let [accounts (rf/sub [:wallet/accounts-with-current-asset]) network-details (rf/sub [:wallet/network-details])] + (hot-reload/use-safe-unmount on-close) [floating-button-page/view {:footer-container-padding 0 :header [account-switcher/view - {:on-press on-close + {:on-press #(rf/dispatch [:navigate-back]) :margin-top (safe-area/get-top) :switcher-type :select-account}]} diff --git a/src/status_im/contexts/wallet/send/input_amount/view.cljs b/src/status_im/contexts/wallet/send/input_amount/view.cljs index fef06ff4fd..5bfd9bc244 100644 --- a/src/status_im/contexts/wallet/send/input_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/view.cljs @@ -16,6 +16,7 @@ [status-im.contexts.wallet.sheets.buy-token.view :as buy-token] [status-im.contexts.wallet.sheets.unpreferred-networks-alert.view :as unpreferred-networks-alert] [status-im.feature-flags :as ff] + [status-im.setup.hot-reload :as hot-reload] [utils.debounce :as debounce] [utils.i18n :as i18n] [utils.money :as money] @@ -322,6 +323,7 @@ (let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!)) app-keyboard-listener (.addEventListener rn/app-state "change" dismiss-keyboard-fn)] #(.remove app-keyboard-listener)))) + (hot-reload/use-safe-unmount on-navigate-back) (rn/use-effect (fn [] (set-input-state #(controlled-input/set-upper-limit % current-limit))) @@ -346,7 +348,7 @@ (when (controlled-input/input-error input-state) "-error"))} [account-switcher/view {:icon-name :i/arrow-left - :on-press on-navigate-back + :on-press #(rf/dispatch [:navigate-back]) :switcher-type :select-account}] [quo/token-input {:container-style style/input-container 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 a92e372d97..8e7d0ca2ac 100644 --- a/src/status_im/contexts/wallet/send/select_address/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/view.cljs @@ -17,6 +17,7 @@ [status-im.contexts.wallet.send.select-address.style :as style] [status-im.contexts.wallet.send.select-address.tabs.view :as tabs] [status-im.feature-flags :as ff] + [status-im.setup.hot-reload :as hot-reload] [utils.debounce :as debounce] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -176,8 +177,7 @@ (rf/dispatch [:wallet/clean-selected-collectible]) (rf/dispatch [:wallet/clean-send-address]) (rf/dispatch [:wallet/clean-disabled-from-networks]) - (rf/dispatch [:wallet/select-address-tab nil]) - (rf/dispatch [:navigate-back])) + (rf/dispatch [:wallet/select-address-tab nil])) on-change-tab #(rf/dispatch [:wallet/select-address-tab %]) input-value (reagent/atom "") input-focused? (reagent/atom false)] @@ -185,12 +185,13 @@ (let [selected-tab (or (rf/sub [:wallet/send-tab]) (:id (first tabs-data))) valid-ens-or-address? (boolean (rf/sub [:wallet/valid-ens-or-address?])) searching-address? (rf/sub [:wallet/searching-address?])] + (hot-reload/use-safe-unmount on-close) [floating-button-page/view {:content-container-style {:flex 1} :footer-container-padding 0 :keyboard-should-persist-taps true :header [account-switcher/view - {:on-press on-close + {:on-press #(rf/dispatch [:navigate-back]) :margin-top (safe-area/get-top) :switcher-type :select-account}] :footer (when-not (string/blank? @input-value) diff --git a/src/status_im/contexts/wallet/send/select_asset/view.cljs b/src/status_im/contexts/wallet/send/select_asset/view.cljs index 15ef6b0d18..f12912f44a 100644 --- a/src/status_im/contexts/wallet/send/select_asset/view.cljs +++ b/src/status_im/contexts/wallet/send/select_asset/view.cljs @@ -7,6 +7,7 @@ [status-im.contexts.wallet.common.asset-list.view :as asset-list] [status-im.contexts.wallet.common.collectibles-tab.view :as collectibles-tab] [status-im.contexts.wallet.send.select-asset.style :as style] + [status-im.setup.hot-reload :as hot-reload] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -66,9 +67,9 @@ (rf/dispatch [:wallet/clean-selected-token]) (rf/dispatch [:wallet/clean-selected-collectible]) (rf/dispatch [:navigate-back]))] - (rn/use-unmount (fn [] - (rf/dispatch [:wallet/clean-selected-token]) - (rf/dispatch [:wallet/clean-selected-collectible]))) + (hot-reload/use-safe-unmount (fn [] + (rf/dispatch [:wallet/clean-selected-token]) + (rf/dispatch [:wallet/clean-selected-collectible]))) [rn/safe-area-view {:style style/container} [account-switcher/view {:icon-name :i/arrow-left diff --git a/src/status_im/contexts/wallet/send/send_amount/view.cljs b/src/status_im/contexts/wallet/send/send_amount/view.cljs index 37276f122c..1277caf7d6 100644 --- a/src/status_im/contexts/wallet/send/send_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/send_amount/view.cljs @@ -13,5 +13,4 @@ :on-navigate-back (fn [] (rf/dispatch [:wallet/clean-disabled-from-networks]) (rf/dispatch [:wallet/clean-from-locked-amounts]) - (rf/dispatch [:wallet/clean-send-amount]) - (rf/dispatch [:navigate-back]))}]) + (rf/dispatch [:wallet/clean-send-amount]))}]) diff --git a/src/status_im/contexts/wallet/swap/select_asset_to_pay/view.cljs b/src/status_im/contexts/wallet/swap/select_asset_to_pay/view.cljs index f3c3412311..c24963bcfd 100644 --- a/src/status_im/contexts/wallet/swap/select_asset_to_pay/view.cljs +++ b/src/status_im/contexts/wallet/swap/select_asset_to_pay/view.cljs @@ -5,6 +5,7 @@ [status-im.contexts.wallet.common.account-switcher.view :as account-switcher] [status-im.contexts.wallet.common.asset-list.view :as asset-list] [status-im.contexts.wallet.swap.select-asset-to-pay.style :as style] + [status-im.setup.hot-reload :as hot-reload] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -40,8 +41,8 @@ on-close (fn [] (rf/dispatch [:wallet.swap/clean-asset-to-pay]) (rf/dispatch [:navigate-back]))] - (rn/use-unmount (fn [] - (rf/dispatch [:wallet.swap/clean-asset-to-pay]))) + (hot-reload/use-safe-unmount (fn [] + (rf/dispatch [:wallet.swap/clean-asset-to-pay]))) [rn/safe-area-view {:style style/container} [account-switcher/view {:on-press on-close diff --git a/src/status_im/subs/wallet/send.cljs b/src/status_im/subs/wallet/send.cljs index 31c8eae142..24f98ffda2 100644 --- a/src/status_im/subs/wallet/send.cljs +++ b/src/status_im/subs/wallet/send.cljs @@ -25,6 +25,11 @@ :<- [:wallet/wallet-send] :-> :transaction-ids) +(rf/reg-sub + :wallet/just-completed-transaction + :<- [:wallet/wallet-send] + :-> :just-completed-transaction?) + (rf/reg-sub :wallet/wallet-send-amount :<- [:wallet/wallet-send]