From 8f94332d591859ead2d477988c8ff9eef9fc89d9 Mon Sep 17 00:00:00 2001 From: Ulises Manuel <90291778+ulisesmac@users.noreply.github.com> Date: Mon, 9 Sep 2024 14:24:00 -0600 Subject: [PATCH] feat(wallet): Hide account switcher in send flow (#20892) * Fix input amount step skipped while sending a token * Rename events to remove the `wallet` unnecessary suffix * Code style fixes * Fix React warnings: 1. About unique key in `select-address.tabs.view` along with a refactor 2. The deprecated `:keyboard-should-persist-taps` as `true` in `send.select-address.view` * Hide account switcher while sending a collectible * Fix tests --- .../wallet/common/account_switcher/view.cljs | 14 ++++--- src/status_im/contexts/wallet/events.cljs | 5 ++- src/status_im/contexts/wallet/home/view.cljs | 2 +- .../contexts/wallet/send/events.cljs | 31 +++++++++++++++- .../contexts/wallet/send/flow_config.cljs | 2 +- .../send/input_amount/component_spec.cljs | 3 +- .../wallet/send/select_address/tabs/view.cljs | 37 +++++++++++-------- .../wallet/send/select_address/view.cljs | 4 +- .../wallet/send/select_asset/view.cljs | 3 +- .../send/select_collectible_amount/view.cljs | 8 ++-- .../send/transaction_confirmation/view.cljs | 2 +- .../contexts/wallet/swap/events.cljs | 3 +- src/status_im/subs/wallet/send.cljs | 15 +++++++- 13 files changed, 89 insertions(+), 40 deletions(-) diff --git a/src/status_im/contexts/wallet/common/account_switcher/view.cljs b/src/status_im/contexts/wallet/common/account_switcher/view.cljs index bf7f1decab..60d994b951 100644 --- a/src/status_im/contexts/wallet/common/account_switcher/view.cljs +++ b/src/status_im/contexts/wallet/common/account_switcher/view.cljs @@ -26,7 +26,8 @@ switcher-type :account-options type :no-title}}] (let [{:keys [color emoji watch-only?]} (rf/sub [:wallet/current-viewing-account]) - networks (rf/sub [:wallet/selected-network-details])] + networks (rf/sub [:wallet/selected-network-details]) + sending-collectible? (rf/sub [:wallet/sending-collectible?])] [quo/page-nav {:type type :icon-name icon-name @@ -41,8 +42,9 @@ (not watch-only?)) {:icon-name :i/dapps :on-press #(rf/dispatch [:navigate-to :screen/wallet.connected-dapps])}) - {:content-type :account-switcher - :customization-color color - :on-press #(on-dapps-press switcher-type) - :emoji emoji - :type (when watch-only? :watch-only)}]}])) + (when-not sending-collectible? + {:content-type :account-switcher + :customization-color color + :on-press #(on-dapps-press switcher-type) + :emoji emoji + :type (when watch-only? :watch-only)})]}])) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index d9fdcdcf43..04bd83f257 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -85,8 +85,9 @@ (rf/reg-event-fx :wallet/close-account-page (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]]]})))) + {:db (update db :wallet dissoc :current-viewing-account-address) + :fx [(when-not just-completed-transaction? + [:dispatch [:wallet/clear-account-tab]])]}))) (defn log-rpc-error [_ [{:keys [event params]} error]] diff --git a/src/status_im/contexts/wallet/home/view.cljs b/src/status_im/contexts/wallet/home/view.cljs index 4fdb0b0794..a4cbee8c10 100644 --- a/src/status_im/contexts/wallet/home/view.cljs +++ b/src/status_im/contexts/wallet/home/view.cljs @@ -60,7 +60,7 @@ :size 32 :default-active default-active :data data - :on-change #(on-change %)}]) + :on-change on-change}]) (defn view [] diff --git a/src/status_im/contexts/wallet/send/events.cljs b/src/status_im/contexts/wallet/send/events.cljs index 807455c792..29ba9cdbeb 100644 --- a/src/status_im/contexts/wallet/send/events.cljs +++ b/src/status_im/contexts/wallet/send/events.cljs @@ -263,9 +263,12 @@ (rf/reg-event-fx :wallet/set-collectible-to-send - (fn [{db :db} [{:keys [collectible current-screen start-flow?]}]] + (fn [{db :db} [{:keys [collectible current-screen start-flow? entry-point]}]] (let [viewing-account? (some? (-> db :wallet :current-viewing-account-address)) - entry-point (when-not viewing-account? :wallet-stack) + entry-point (cond + entry-point entry-point + viewing-account? :account-collectible-tab + :else :wallet-stack) collection-data (:collection-data collectible) collectible-data (:collectible-data collectible) contract-type (:contract-type collectible) @@ -702,3 +705,27 @@ {:current-screen stack-id :start-flow? start-flow? :flow-id flow-id}]]]}))) + +(rf/reg-event-fx + :wallet/transaction-confirmation-navigate-back + (fn [{db :db} [{:keys []}]] + (let [tx-type (-> db :wallet :ui :send :tx-type) + keep-tx-data? (#{:account-collectible-tab :wallet-stack} + (-> db :wallet :ui :send :entry-point))] + {:db (cond-> db + (and (= tx-type :tx/collectible-erc-721) (not keep-tx-data?)) + (update-in [:wallet :ui :send] dissoc :tx-type :amount :route :suggested-routes) + + (= tx-type :tx/collectible-erc-1155) + (update-in [:wallet :ui :send] dissoc :route :suggested-routes)) + :fx [[:dispatch [:navigate-back]]]}))) + +(rf/reg-event-fx + :wallet/collectible-amount-navigate-back + (fn [{db :db} [{:keys []}]] + (let [keep-tx-data? (#{:account-collectible-tab :wallet-stack} + (-> db :wallet :ui :send :entry-point))] + {:db (cond-> db + :always (update-in [:wallet :ui :send] dissoc :amount :route) + (not keep-tx-data?) (update-in [:wallet :ui :send] dissoc :tx-type)) + :fx [[:dispatch [:navigate-back]]]}))) diff --git a/src/status_im/contexts/wallet/send/flow_config.cljs b/src/status_im/contexts/wallet/send/flow_config.cljs index 60092e1d23..d8a6e717ce 100644 --- a/src/status_im/contexts/wallet/send/flow_config.cljs +++ b/src/status_im/contexts/wallet/send/flow_config.cljs @@ -22,7 +22,7 @@ :skip-step? (fn [db] (or (token-selected? db) (collectible-selected? db)))} {:screen-id :screen/wallet.send-input-amount :skip-step? (fn [db] - (send-utils/tx-type-collectible? (get-in db [:wallet :ui :send :tx-type])))} + (-> db :wallet :ui :send :tx-type send-utils/tx-type-collectible?))} {:screen-id :screen/wallet.select-collectible-amount :skip-step? (fn [db] (or (not (collectible-selected? db)) diff --git a/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs b/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs index 0d085f029f..d04dc6b256 100644 --- a/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs +++ b/src/status_im/contexts/wallet/send/input_amount/component_spec.cljs @@ -98,9 +98,10 @@ :related-chain-id 1 :layer 1}] :wallet/wallet-send-enabled-from-chain-ids [1] - :wallet/wallet-send-amount nil + :wallet/send-amount nil :wallet/wallet-send-tx-type :tx/send :wallet/wallet-send-fee-fiat-formatted "$5,00" + :wallet/sending-collectible? false :wallet/total-amount (money/bignumber "250")}) (h/describe "Send > input amount screen" diff --git a/src/status_im/contexts/wallet/send/select_address/tabs/view.cljs b/src/status_im/contexts/wallet/send/select_address/tabs/view.cljs index 02b81fd65d..622b399ab5 100644 --- a/src/status_im/contexts/wallet/send/select_address/tabs/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/tabs/view.cljs @@ -9,6 +9,25 @@ [utils.i18n :as i18n] [utils.re-frame :as rf])) +(defn other-account-item + [{:keys [address color emoji network-preferences-names] + account-name :name + :as account}] + (let [full-address (rf/sub [:wallet/account-address address network-preferences-names])] + [quo/account-item + {:account-props (assoc account + :customization-color color + :address full-address + :full-address? true) + :on-press (fn [] + (rf/dispatch [:wallet/select-send-address + {:address address + :recipient {:recipient-type :account + :label account-name + :customization-color color + :emoji emoji} + :stack-id :screen/wallet.select-address}]))}])) + (defn- my-accounts [theme] (let [other-accounts (rf/sub [:wallet/accounts-without-current-viewing-account])] @@ -20,22 +39,8 @@ :container-style style/empty-container-style}] [rn/view {:style style/my-accounts-container} (doall - (for [{:keys [color address] :as account} other-accounts] - ^{:key (str address)} - (let [transformed-address (rf/sub [:wallet/account-address address - (:network-preferences-names account)])] - [quo/account-item - {:account-props (assoc account - :customization-color color - :address transformed-address - :full-address? true) - :on-press #(rf/dispatch [:wallet/select-send-address - {:address address - :recipient {:recipient-type :account - :label (:name account) - :customization-color (:color account) - :emoji (:emoji account)} - :stack-id :screen/wallet.select-address}])}])))]))) + (for [{:keys [address] :as account} other-accounts] + ^{:key (str address)} [other-account-item account]))]))) (defn- recent-transactions [theme] 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 4c2e91579f..8997d8c39d 100644 --- a/src/status_im/contexts/wallet/send/select_address/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/view.cljs @@ -44,7 +44,7 @@ (let [current-screen-id (rf/sub [:view-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 (rf/sub [:wallet/send-recipient]) recipient-plain-address? (= send-address recipient) valid-ens-or-address? (rf/sub [:wallet/valid-ens-or-address?]) contacts (rf/sub [:contacts/active])] @@ -191,7 +191,7 @@ [floating-button-page/view {:content-container-style {:flex 1} :footer-container-padding 0 - :keyboard-should-persist-taps true + :keyboard-should-persist-taps :always :header [account-switcher/view {:on-press #(rf/dispatch [:navigate-back]) :margin-top (safe-area/get-top) 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 f12912f44a..0d3a7923af 100644 --- a/src/status_im/contexts/wallet/send/select_asset/view.cljs +++ b/src/status_im/contexts/wallet/send/select_asset/view.cljs @@ -36,7 +36,8 @@ :on-collectible-press (fn [{:keys [collectible]}] (rf/dispatch [:wallet/set-collectible-to-send {:collectible collectible - :current-screen :screen/wallet.select-asset}]))}])) + :current-screen :screen/wallet.select-asset + :entry-point :account-send-button}]))}])) (defn- tab-view [search-text selected-tab on-change-text] diff --git a/src/status_im/contexts/wallet/send/select_collectible_amount/view.cljs b/src/status_im/contexts/wallet/send/select_collectible_amount/view.cljs index 3c5373bc9b..d9548aacfe 100644 --- a/src/status_im/contexts/wallet/send/select_collectible_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/select_collectible_amount/view.cljs @@ -11,7 +11,8 @@ (defn view [] - (let [on-close (rn/use-callback #(rf/dispatch [:navigate-back])) + (let [on-close (rn/use-callback + #(rf/dispatch [:wallet/collectible-amount-navigate-back])) send-transaction-data (rf/sub [:wallet/wallet-send]) collectible (:collectible send-transaction-data) balance (utils/collectible-balance collectible) @@ -23,8 +24,9 @@ increase-value (rn/use-callback #(set-value controlled-input/increase)) decrease-value (rn/use-callback #(set-value controlled-input/decrease)) delete-character (rn/use-callback #(set-value controlled-input/delete-last)) - add-character (rn/use-callback (fn [c] - (set-value #(controlled-input/add-character % c))))] + add-character (rn/use-callback + (fn [c] + (set-value #(controlled-input/add-character % c))))] (rn/use-effect (fn [] (set-value #(controlled-input/set-upper-limit % balance))) diff --git a/src/status_im/contexts/wallet/send/transaction_confirmation/view.cljs b/src/status_im/contexts/wallet/send/transaction_confirmation/view.cljs index d405d1c250..004a9dd01a 100644 --- a/src/status_im/contexts/wallet/send/transaction_confirmation/view.cljs +++ b/src/status_im/contexts/wallet/send/transaction_confirmation/view.cljs @@ -195,7 +195,7 @@ (defn view [_] - (let [on-close #(rf/dispatch [:navigate-back])] + (let [on-close #(rf/dispatch [:wallet/transaction-confirmation-navigate-back])] (fn [] (let [theme (quo.theme/use-theme) send-transaction-data (rf/sub [:wallet/wallet-send]) diff --git a/src/status_im/contexts/wallet/swap/events.cljs b/src/status_im/contexts/wallet/swap/events.cljs index 9e14ba29a9..63bd770da0 100644 --- a/src/status_im/contexts/wallet/swap/events.cljs +++ b/src/status_im/contexts/wallet/swap/events.cljs @@ -43,8 +43,7 @@ (rf/reg-event-fx :wallet.swap/set-default-slippage (fn [{:keys [db]}] - {:db - (assoc-in db [:wallet :ui :swap :max-slippage] constants/default-slippage)})) + {:db (assoc-in db [:wallet :ui :swap :max-slippage] constants/default-slippage)})) (rf/reg-event-fx :wallet.swap/set-max-slippage (fn [{:keys [db]} [max-slippage]] diff --git a/src/status_im/subs/wallet/send.cljs b/src/status_im/subs/wallet/send.cljs index 783adbda0f..aea21aa7bb 100644 --- a/src/status_im/subs/wallet/send.cljs +++ b/src/status_im/subs/wallet/send.cljs @@ -2,6 +2,7 @@ (:require [re-frame.core :as rf] [status-im.contexts.wallet.common.activity-tab.constants :as constants] + [status-im.contexts.wallet.send.utils :as send-utils] [utils.number])) (rf/reg-sub @@ -16,7 +17,7 @@ :-> :send) (rf/reg-sub - :wallet/wallet-send-recipient + :wallet/send-recipient :<- [:wallet/wallet-send] :-> :recipient) @@ -31,10 +32,20 @@ :-> :just-completed-transaction?) (rf/reg-sub - :wallet/wallet-send-amount + :wallet/send-amount :<- [:wallet/wallet-send] :-> :amount) +(rf/reg-sub + :wallet/send-tx-type + :<- [:wallet/wallet-send] + :-> :tx-type) + +(rf/reg-sub + :wallet/sending-collectible? + :<- [:wallet/send-tx-type] + #(send-utils/tx-type-collectible? %)) + (rf/reg-sub :wallet/send-transaction-progress :<- [:wallet/send-transaction-ids]