From 1e703cdc817157e9f155f5b640797002bd8a62f4 Mon Sep 17 00:00:00 2001 From: Ulises Manuel <90291778+ulisesmac@users.noreply.github.com> Date: Thu, 20 Jun 2024 17:14:26 -0600 Subject: [PATCH] feat(wallet): Remove non-operable accounts from account switcher (#20457) * feat(wallet): Remove non-operable accounts from account switcher * Remove non-operable accounts in the From page --- src/status_im/contexts/wallet/send/events.cljs | 9 +++------ .../wallet/sheets/account_options/view.cljs | 5 +++-- .../wallet/sheets/select_account/view.cljs | 2 +- src/status_im/subs/wallet/wallet.cljs | 18 +++++++++++++++++- src/status_im/subs/wallet/wallet_test.cljs | 12 ++++++++---- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/status_im/contexts/wallet/send/events.cljs b/src/status_im/contexts/wallet/send/events.cljs index 8442c915c8..6f2e52b87c 100644 --- a/src/status_im/contexts/wallet/send/events.cljs +++ b/src/status_im/contexts/wallet/send/events.cljs @@ -210,12 +210,10 @@ :always (assoc-in [:wallet :ui :send :token-display-name] (:symbol token)) :always (assoc-in - [:wallet :ui :send - :token-not-supported-in-receiver-networks?] + [:wallet :ui :send :token-not-supported-in-receiver-networks?] token-not-supported-in-receiver-networks?) token (assoc-in [:wallet :ui :send :token] token) - token-symbol (assoc-in [:wallet :ui :send :token-symbol] - token-symbol)) + token-symbol (assoc-in [:wallet :ui :send :token-symbol] token-symbol)) :fx [[:dispatch [:wallet/clean-suggested-routes]] [:dispatch [:wallet/wizard-navigate-forward @@ -253,8 +251,7 @@ :collectible :token-display-name :amount - (when (send-utils/tx-type-collectible? - transaction-type) + (when (send-utils/tx-type-collectible? transaction-type) :tx-type))}))) (rf/reg-event-fx diff --git a/src/status_im/contexts/wallet/sheets/account_options/view.cljs b/src/status_im/contexts/wallet/sheets/account_options/view.cljs index 981224cb5d..248f180a46 100644 --- a/src/status_im/contexts/wallet/sheets/account_options/view.cljs +++ b/src/status_im/contexts/wallet/sheets/account_options/view.cljs @@ -108,8 +108,9 @@ [] (let [options-height (reagent/atom 0)] (fn [] - (let [theme (quo.theme/use-theme) - accounts (rf/sub [:wallet/accounts-without-current-viewing-account]) + (let [theme (quo.theme/use-theme) + accounts (rf/sub + [:wallet/fully-or-partially-operable-accounts-without-current-viewing-account]) show-account-selector? (pos? (count accounts))] [:<> (when show-account-selector? diff --git a/src/status_im/contexts/wallet/sheets/select_account/view.cljs b/src/status_im/contexts/wallet/sheets/select_account/view.cljs index 5a3df1d0f0..3e79abe671 100644 --- a/src/status_im/contexts/wallet/sheets/select_account/view.cljs +++ b/src/status_im/contexts/wallet/sheets/select_account/view.cljs @@ -20,7 +20,7 @@ (defn view [] (let [selected-account-address (rf/sub [:wallet/current-viewing-account-address]) - accounts (rf/sub [:wallet/accounts-without-watched-accounts])] + accounts (rf/sub [:wallet/fully-or-partially-operable-accounts-without-watched-accounts])] [:<> [quo/drawer-top {:title (i18n/label :t/select-account)}] [gesture/flat-list diff --git a/src/status_im/subs/wallet/wallet.cljs b/src/status_im/subs/wallet/wallet.cljs index 1f8995d553..81eaeb29a7 100644 --- a/src/status_im/subs/wallet/wallet.cljs +++ b/src/status_im/subs/wallet/wallet.cljs @@ -446,9 +446,25 @@ (fn [accounts] (remove :watch-only? accounts))) +(defn- keep-fully-or-partially-operable-accounts + [accounts] + (filter (fn fully-or-partially-operable? [{:keys [operable]}] + (#{:fully :partially} operable)) + accounts)) + +(rf/reg-sub + :wallet/fully-or-partially-operable-accounts-without-current-viewing-account + :<- [:wallet/accounts-without-current-viewing-account] + keep-fully-or-partially-operable-accounts) + +(rf/reg-sub + :wallet/fully-or-partially-operable-accounts-without-watched-accounts + :<- [:wallet/accounts-without-watched-accounts] + keep-fully-or-partially-operable-accounts) + (rf/reg-sub :wallet/accounts-with-current-asset - :<- [:wallet/accounts-without-watched-accounts] + :<- [:wallet/fully-or-partially-operable-accounts-without-watched-accounts] :<- [:wallet/wallet-send-token-symbol] :<- [:wallet/wallet-send-token] (fn [[accounts token-symbol token]] diff --git a/src/status_im/subs/wallet/wallet_test.cljs b/src/status_im/subs/wallet/wallet_test.cljs index 6b258af24f..9d719f25bd 100644 --- a/src/status_im/subs/wallet/wallet_test.cljs +++ b/src/status_im/subs/wallet/wallet_test.cljs @@ -15,10 +15,12 @@ (def ^:private accounts-with-tokens {:0x1 {:tokens [{:symbol "ETH"} {:symbol "SNT"}] :network-preferences-names #{} - :customization-color nil} + :customization-color nil + :operable :fully} :0x2 {:tokens [{:symbol "SNT"}] :network-preferences-names #{} - :customization-color nil}}) + :customization-color nil + :operable :partially}}) (def tokens-0x1 [{:decimals 1 @@ -481,7 +483,8 @@ (is (match? result [{:tokens [{:symbol "ETH"} {:symbol "SNT"}] :network-preferences-names #{} - :customization-color nil}])))) + :customization-color nil + :operable :fully}])))) (testing "returns the accounts list with the current asset using token" (swap! rf-db/app-db @@ -492,7 +495,8 @@ (is (match? result [{:tokens [{:symbol "ETH"} {:symbol "SNT"}] :network-preferences-names #{} - :customization-color nil}])))) + :customization-color nil + :operable :fully}])))) (testing "returns the full accounts list with the current asset using token-symbol if each account has the asset"