From 47f6bda5639c1300e37dd48a7bec83e09842b6c3 Mon Sep 17 00:00:00 2001 From: mmilad75 <55688834+mmilad75@users.noreply.github.com> Date: Tue, 28 May 2024 18:16:23 +0200 Subject: [PATCH] The select assets screen is shown when token is going to be sent which available on both watch-only and regular account #19745 (#20050) --- .../contexts/wallet/send/from/view.cljs | 2 +- .../wallet/send/select_address/view.cljs | 1 - src/status_im/subs/wallet/wallet.cljs | 18 +++++++ src/status_im/subs/wallet/wallet_test.cljs | 48 +++++++++++++++++++ 4 files changed, 67 insertions(+), 2 deletions(-) diff --git a/src/status_im/contexts/wallet/send/from/view.cljs b/src/status_im/contexts/wallet/send/from/view.cljs index fa5117eb58..45f50a1f86 100644 --- a/src/status_im/contexts/wallet/send/from/view.cljs +++ b/src/status_im/contexts/wallet/send/from/view.cljs @@ -30,7 +30,7 @@ (defn view [] - (let [accounts (rf/sub [:wallet/accounts-without-watched-accounts])] + (let [accounts (rf/sub [:wallet/accounts-with-current-asset])] [floating-button-page/view {:footer-container-padding 0 :header [account-switcher/view 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 498e03c09f..e887504dbb 100644 --- a/src/status_im/contexts/wallet/send/select_address/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/view.cljs @@ -141,7 +141,6 @@ (let [on-close (fn [] (rf/dispatch [:wallet/clean-scanned-address]) (rf/dispatch [:wallet/clean-local-suggestions]) - (rf/dispatch [:wallet/clean-selected-token]) (rf/dispatch [:wallet/clean-selected-collectible]) (rf/dispatch [:wallet/clean-send-address]) (rf/dispatch [:wallet/clean-disabled-from-networks]) diff --git a/src/status_im/subs/wallet/wallet.cljs b/src/status_im/subs/wallet/wallet.cljs index 304def5962..ae213daf0c 100644 --- a/src/status_im/subs/wallet/wallet.cljs +++ b/src/status_im/subs/wallet/wallet.cljs @@ -120,6 +120,11 @@ :available-balance (utils/calculate-total-token-balance token) :total-balance (utils/calculate-total-token-balance token enabled-from-chain-ids))))) +(rf/reg-sub + :wallet/wallet-send-token-symbol + :<- [:wallet/wallet-send] + :-> :token-symbol) + (rf/reg-sub :wallet/wallet-send-disabled-from-chain-ids :<- [:wallet/wallet-send] @@ -400,6 +405,19 @@ (fn [accounts] (remove :watch-only? accounts))) +(rf/reg-sub + :wallet/accounts-with-current-asset + :<- [:wallet/accounts-without-watched-accounts] + :<- [:wallet/wallet-send-token-symbol] + :<- [:wallet/wallet-send-token] + (fn [[accounts token-symbol token]] + (let [asset-symbol (or token-symbol (:symbol token))] + (if asset-symbol + (filter (fn [account] + (some #(= (:symbol %) asset-symbol) (:tokens account))) + accounts) + accounts)))) + (rf/reg-sub :wallet/current-viewing-account-token-values :<- [:wallet/current-viewing-account] diff --git a/src/status_im/subs/wallet/wallet_test.cljs b/src/status_im/subs/wallet/wallet_test.cljs index 2349a67cbd..3d6b86c4ce 100644 --- a/src/status_im/subs/wallet/wallet_test.cljs +++ b/src/status_im/subs/wallet/wallet_test.cljs @@ -12,6 +12,14 @@ (use-fixtures :each {:before #(reset! rf-db/app-db {})}) +(def ^:private accounts-with-tokens + {:0x1 {:tokens [{:symbol "ETH"} {:symbol "SNT"}] + :network-preferences-names #{} + :customization-color nil} + :0x2 {:tokens [{:symbol "SNT"}] + :network-preferences-names #{} + :customization-color nil}}) + (def tokens-0x1 [{:decimals 1 :symbol "ETH" @@ -456,6 +464,46 @@ :tokens tokens-0x2}) (rf/sub [sub-name]))))) +(h/deftest-sub :wallet/accounts-with-current-asset + [sub-name] + (testing "returns the accounts list with the current asset using token-symbol" + (swap! rf-db/app-db + #(-> % + (assoc-in [:wallet :accounts] accounts-with-tokens) + (assoc-in [:wallet :ui :send :token-symbol] "ETH"))) + (let [result (rf/sub [sub-name])] + (is (match? result + [{:tokens [{:symbol "ETH"} {:symbol "SNT"}] + :network-preferences-names #{} + :customization-color nil}])))) + + (testing "returns the accounts list with the current asset using token" + (swap! rf-db/app-db + #(-> % + (assoc-in [:wallet :accounts] accounts-with-tokens) + (assoc-in [:wallet :ui :send :token] {:symbol "ETH"}))) + (let [result (rf/sub [sub-name])] + (is (match? result + [{:tokens [{:symbol "ETH"} {:symbol "SNT"}] + :network-preferences-names #{} + :customization-color nil}])))) + + (testing + "returns the full accounts list with the current asset using token-symbol if each account has the asset" + (swap! rf-db/app-db + #(-> % + (assoc-in [:wallet :accounts] accounts-with-tokens) + (assoc-in [:wallet :ui :send :token-symbol] "SNT"))) + (let [result (rf/sub [sub-name])] + (is (match? result (vals accounts-with-tokens))))) + + (testing "returns the accounts list when there is no current asset" + (swap! rf-db/app-db + #(-> % + (assoc-in [:wallet :accounts] accounts-with-tokens))) + (let [result (rf/sub [sub-name])] + (is (match? result (vals accounts-with-tokens)))))) + (h/deftest-sub :wallet/network-preference-details [sub-name] (testing "returns current viewing account address"