fix: hardware induced back actions (#20183)

* fix: hardware induced back actions (#20183)
This commit is contained in:
Omar Basem 2024-07-12 17:09:42 +04:00 committed by GitHub
parent 087fcb1010
commit 0e6d59b312
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 56 additions and 32 deletions

View File

@ -7,6 +7,7 @@
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher] [status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
[status-im.contexts.wallet.sheets.buy-token.view :as buy-token] [status-im.contexts.wallet.sheets.buy-token.view :as buy-token]
[status-im.feature-flags :as ff] [status-im.feature-flags :as ff]
[status-im.setup.hot-reload :as hot-reload]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -28,14 +29,15 @@
{:keys [name color formatted-balance {:keys [name color formatted-balance
watch-only?]} (rf/sub [:wallet/current-viewing-account]) watch-only?]} (rf/sub [:wallet/current-viewing-account])
customization-color (rf/sub [:profile/customization-color])] 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 (rn/use-mount
#(rf/dispatch [:wallet/fetch-activities-for-current-account])) #(rf/dispatch [:wallet/fetch-activities-for-current-account]))
[rn/view {:style {:flex 1}} [rn/view {:style {:flex 1}}
[account-switcher/view [account-switcher/view
{:type :wallet-networks {:type :wallet-networks
:on-press (fn [] :on-press #(rf/dispatch [:pop-to-root :shell-stack])}]
(rf/dispatch [:wallet/close-account-page]))}]
[quo/account-overview [quo/account-overview
{:container-style style/account-overview {:container-style style/account-overview
:current-value formatted-balance :current-value formatted-balance

View File

@ -8,6 +8,7 @@
[status-im.common.floating-button-page.view :as floating-button-page] [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.add-account.create-account.import-private-key.style :as style]
[status-im.contexts.wallet.common.validation :as v] [status-im.contexts.wallet.common.validation :as v]
[status-im.setup.hot-reload :as hot-reload]
[utils.debounce :as debounce] [utils.debounce :as debounce]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -112,7 +113,7 @@
public-address (rf/sub [:wallet/public-address]) public-address (rf/sub [:wallet/public-address])
[flow-state set-flow-state] (rn/use-state nil) [flow-state set-flow-state] (rn/use-state nil)
error? (= :invalid-private-key flow-state)] error? (= :invalid-private-key flow-state)]
(rn/use-unmount on-unmount) (hot-reload/use-safe-unmount on-unmount)
[rn/view {:flex 1} [rn/view {:flex 1}
[floating-button-page/view [floating-button-page/view
{:customization-color customization-color {:customization-color customization-color

View File

@ -15,6 +15,7 @@
[status-im.contexts.wallet.common.utils :as common.utils] [status-im.contexts.wallet.common.utils :as common.utils]
[status-im.contexts.wallet.sheets.account-origin.view :as account-origin] [status-im.contexts.wallet.sheets.account-origin.view :as account-origin]
[status-im.feature-flags :as ff] [status-im.feature-flags :as ff]
[status-im.setup.hot-reload :as hot-reload]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[utils.responsiveness :as responsiveness] [utils.responsiveness :as responsiveness]
@ -313,7 +314,7 @@
error (or @account-name-error @emoji-and-color-error?)] error (or @account-name-error @emoji-and-color-error?)]
(rn/use-mount #(check-emoji-and-color-error @emoji @account-color)) (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 (if keypair-name
[add-new-keypair-variant [add-new-keypair-variant

View File

@ -9,6 +9,7 @@
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher] [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 :as utils]
[status-im.contexts.wallet.common.utils.networks :as network-utils] [status-im.contexts.wallet.common.utils.networks :as network-utils]
[status-im.setup.hot-reload :as hot-reload]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -52,7 +53,7 @@
bridge-to-title (i18n/label :t/bridge-to bridge-to-title (i18n/label :t/bridge-to
{:name (string/upper-case (str token-symbol))})] {: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 [rn/view
[account-switcher/view [account-switcher/view

View File

@ -3,12 +3,13 @@
[react-native.core :as rn] [react-native.core :as rn]
[status-im.contexts.wallet.bridge.input-amount.style :as style] [status-im.contexts.wallet.bridge.input-amount.style :as style]
[status-im.contexts.wallet.send.input-amount.view :as input-amount] [status-im.contexts.wallet.send.input-amount.view :as input-amount]
[status-im.setup.hot-reload :as hot-reload]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn view (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} [rn/view {:style style/bridge-send-wrapper}
[input-amount/view [input-amount/view
{:current-screen-id :screen/wallet.bridge-input-amount {:current-screen-id :screen/wallet.bridge-input-amount
@ -20,5 +21,4 @@
:stack-id :screen/wallet.bridge-input-amount}])) :stack-id :screen/wallet.bridge-input-amount}]))
:on-navigate-back (fn [] :on-navigate-back (fn []
(rf/dispatch [:wallet/clean-disabled-from-networks]) (rf/dispatch [:wallet/clean-disabled-from-networks])
(rf/dispatch [:wallet/clean-send-amount]) (rf/dispatch [:wallet/clean-send-amount]))}]])
(rf/dispatch [:navigate-back]))}]])

View File

@ -66,13 +66,15 @@
(rf/reg-event-fx :wallet/clean-current-viewing-account (rf/reg-event-fx :wallet/clean-current-viewing-account
(fn [{:keys [db]}] (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 (rf/reg-event-fx :wallet/close-account-page
(fn [_] (fn [{:keys [db]}]
{:fx [[:dispatch [:wallet/clean-current-viewing-account]] (let [just-completed-transaction? (get-in db [:wallet :ui :send :just-completed-transaction?])]
[:dispatch [:wallet/clear-account-tab]] (when-not just-completed-transaction?
[:dispatch [:pop-to-root :shell-stack]]]})) {:fx [[:dispatch [:wallet/clear-account-tab]]]}))))
(defn log-rpc-error (defn log-rpc-error
[_ [{:keys [event params]} error]] [_ [{:keys [event params]} error]]

View File

@ -487,10 +487,18 @@
transaction-details (send-utils/map-multitransaction-by-ids transaction-batch-id transaction-details (send-utils/map-multitransaction-by-ids transaction-batch-id
transaction-hashes)] transaction-hashes)]
{:db (-> db {:db (-> db
(assoc-in [:wallet :ui :send :just-completed-transaction?] true)
(assoc-in [:wallet :transactions] transaction-details) (assoc-in [:wallet :transactions] transaction-details)
(assoc-in [:wallet :ui :send :transaction-ids] transaction-ids)) (assoc-in [:wallet :ui :send :transaction-ids] transaction-ids))
:fx [[:dispatch :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 (rf/reg-event-fx :wallet/clean-up-transaction-flow
(fn [_] (fn [_]
@ -659,8 +667,8 @@
{:json-rpc/call [{:method "wallet_createMultiTransaction" {:json-rpc/call [{:method "wallet_createMultiTransaction"
:params request-params :params request-params
:on-success (fn [result] :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] :on-error (fn [error]
(log/error "failed to send transaction" (log/error "failed to send transaction"
{:event :wallet/send-transaction {:event :wallet/send-transaction

View File

@ -6,6 +6,7 @@
[status-im.common.floating-button-page.view :as floating-button-page] [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.common.account-switcher.view :as account-switcher]
[status-im.contexts.wallet.send.from.style :as style] [status-im.contexts.wallet.send.from.style :as style]
[status-im.setup.hot-reload :as hot-reload]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -18,9 +19,7 @@
(defn- on-close (defn- on-close
[] []
(rf/dispatch [:wallet/clean-current-viewing-account]) (rf/dispatch [:wallet/clean-current-viewing-account]))
(rf/dispatch [:wallet/clean-send-data])
(rf/dispatch [:navigate-back]))
(defn- render-fn (defn- render-fn
[item _ _ {:keys [network-details]}] [item _ _ {:keys [network-details]}]
@ -36,10 +35,11 @@
[] []
(let [accounts (rf/sub [:wallet/accounts-with-current-asset]) (let [accounts (rf/sub [:wallet/accounts-with-current-asset])
network-details (rf/sub [:wallet/network-details])] network-details (rf/sub [:wallet/network-details])]
(hot-reload/use-safe-unmount on-close)
[floating-button-page/view [floating-button-page/view
{:footer-container-padding 0 {:footer-container-padding 0
:header [account-switcher/view :header [account-switcher/view
{:on-press on-close {:on-press #(rf/dispatch [:navigate-back])
:margin-top (safe-area/get-top) :margin-top (safe-area/get-top)
:switcher-type :select-account}]} :switcher-type :select-account}]}

View File

@ -16,6 +16,7 @@
[status-im.contexts.wallet.sheets.buy-token.view :as buy-token] [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.contexts.wallet.sheets.unpreferred-networks-alert.view :as unpreferred-networks-alert]
[status-im.feature-flags :as ff] [status-im.feature-flags :as ff]
[status-im.setup.hot-reload :as hot-reload]
[utils.debounce :as debounce] [utils.debounce :as debounce]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.money :as money] [utils.money :as money]
@ -322,6 +323,7 @@
(let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!)) (let [dismiss-keyboard-fn #(when (= % "active") (rn/dismiss-keyboard!))
app-keyboard-listener (.addEventListener rn/app-state "change" dismiss-keyboard-fn)] app-keyboard-listener (.addEventListener rn/app-state "change" dismiss-keyboard-fn)]
#(.remove app-keyboard-listener)))) #(.remove app-keyboard-listener))))
(hot-reload/use-safe-unmount on-navigate-back)
(rn/use-effect (rn/use-effect
(fn [] (fn []
(set-input-state #(controlled-input/set-upper-limit % current-limit))) (set-input-state #(controlled-input/set-upper-limit % current-limit)))
@ -346,7 +348,7 @@
(when (controlled-input/input-error input-state) "-error"))} (when (controlled-input/input-error input-state) "-error"))}
[account-switcher/view [account-switcher/view
{:icon-name :i/arrow-left {:icon-name :i/arrow-left
:on-press on-navigate-back :on-press #(rf/dispatch [:navigate-back])
:switcher-type :select-account}] :switcher-type :select-account}]
[quo/token-input [quo/token-input
{:container-style style/input-container {:container-style style/input-container

View File

@ -17,6 +17,7 @@
[status-im.contexts.wallet.send.select-address.style :as style] [status-im.contexts.wallet.send.select-address.style :as style]
[status-im.contexts.wallet.send.select-address.tabs.view :as tabs] [status-im.contexts.wallet.send.select-address.tabs.view :as tabs]
[status-im.feature-flags :as ff] [status-im.feature-flags :as ff]
[status-im.setup.hot-reload :as hot-reload]
[utils.debounce :as debounce] [utils.debounce :as debounce]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -176,8 +177,7 @@
(rf/dispatch [:wallet/clean-selected-collectible]) (rf/dispatch [:wallet/clean-selected-collectible])
(rf/dispatch [:wallet/clean-send-address]) (rf/dispatch [:wallet/clean-send-address])
(rf/dispatch [:wallet/clean-disabled-from-networks]) (rf/dispatch [:wallet/clean-disabled-from-networks])
(rf/dispatch [:wallet/select-address-tab nil]) (rf/dispatch [:wallet/select-address-tab nil]))
(rf/dispatch [:navigate-back]))
on-change-tab #(rf/dispatch [:wallet/select-address-tab %]) on-change-tab #(rf/dispatch [:wallet/select-address-tab %])
input-value (reagent/atom "") input-value (reagent/atom "")
input-focused? (reagent/atom false)] input-focused? (reagent/atom false)]
@ -185,12 +185,13 @@
(let [selected-tab (or (rf/sub [:wallet/send-tab]) (:id (first tabs-data))) (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?])) valid-ens-or-address? (boolean (rf/sub [:wallet/valid-ens-or-address?]))
searching-address? (rf/sub [:wallet/searching-address?])] searching-address? (rf/sub [:wallet/searching-address?])]
(hot-reload/use-safe-unmount on-close)
[floating-button-page/view [floating-button-page/view
{:content-container-style {:flex 1} {:content-container-style {:flex 1}
:footer-container-padding 0 :footer-container-padding 0
:keyboard-should-persist-taps true :keyboard-should-persist-taps true
:header [account-switcher/view :header [account-switcher/view
{:on-press on-close {:on-press #(rf/dispatch [:navigate-back])
:margin-top (safe-area/get-top) :margin-top (safe-area/get-top)
:switcher-type :select-account}] :switcher-type :select-account}]
:footer (when-not (string/blank? @input-value) :footer (when-not (string/blank? @input-value)

View File

@ -7,6 +7,7 @@
[status-im.contexts.wallet.common.asset-list.view :as asset-list] [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.common.collectibles-tab.view :as collectibles-tab]
[status-im.contexts.wallet.send.select-asset.style :as style] [status-im.contexts.wallet.send.select-asset.style :as style]
[status-im.setup.hot-reload :as hot-reload]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -66,9 +67,9 @@
(rf/dispatch [:wallet/clean-selected-token]) (rf/dispatch [:wallet/clean-selected-token])
(rf/dispatch [:wallet/clean-selected-collectible]) (rf/dispatch [:wallet/clean-selected-collectible])
(rf/dispatch [:navigate-back]))] (rf/dispatch [:navigate-back]))]
(rn/use-unmount (fn [] (hot-reload/use-safe-unmount (fn []
(rf/dispatch [:wallet/clean-selected-token]) (rf/dispatch [:wallet/clean-selected-token])
(rf/dispatch [:wallet/clean-selected-collectible]))) (rf/dispatch [:wallet/clean-selected-collectible])))
[rn/safe-area-view {:style style/container} [rn/safe-area-view {:style style/container}
[account-switcher/view [account-switcher/view
{:icon-name :i/arrow-left {:icon-name :i/arrow-left

View File

@ -13,5 +13,4 @@
:on-navigate-back (fn [] :on-navigate-back (fn []
(rf/dispatch [:wallet/clean-disabled-from-networks]) (rf/dispatch [:wallet/clean-disabled-from-networks])
(rf/dispatch [:wallet/clean-from-locked-amounts]) (rf/dispatch [:wallet/clean-from-locked-amounts])
(rf/dispatch [:wallet/clean-send-amount]) (rf/dispatch [:wallet/clean-send-amount]))}])
(rf/dispatch [:navigate-back]))}])

View File

@ -5,6 +5,7 @@
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher] [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.common.asset-list.view :as asset-list]
[status-im.contexts.wallet.swap.select-asset-to-pay.style :as style] [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.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -40,8 +41,8 @@
on-close (fn [] on-close (fn []
(rf/dispatch [:wallet.swap/clean-asset-to-pay]) (rf/dispatch [:wallet.swap/clean-asset-to-pay])
(rf/dispatch [:navigate-back]))] (rf/dispatch [:navigate-back]))]
(rn/use-unmount (fn [] (hot-reload/use-safe-unmount (fn []
(rf/dispatch [:wallet.swap/clean-asset-to-pay]))) (rf/dispatch [:wallet.swap/clean-asset-to-pay])))
[rn/safe-area-view {:style style/container} [rn/safe-area-view {:style style/container}
[account-switcher/view [account-switcher/view
{:on-press on-close {:on-press on-close

View File

@ -25,6 +25,11 @@
:<- [:wallet/wallet-send] :<- [:wallet/wallet-send]
:-> :transaction-ids) :-> :transaction-ids)
(rf/reg-sub
:wallet/just-completed-transaction
:<- [:wallet/wallet-send]
:-> :just-completed-transaction?)
(rf/reg-sub (rf/reg-sub
:wallet/wallet-send-amount :wallet/wallet-send-amount
:<- [:wallet/wallet-send] :<- [:wallet/wallet-send]