The select assets screen is shown when token is going to be sent which available on both watch-only and regular account #19745 (#20050)

This commit is contained in:
mmilad75 2024-05-28 18:16:23 +02:00 committed by GitHub
parent 158ed083da
commit 47f6bda563
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 67 additions and 2 deletions

View File

@ -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

View File

@ -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])

View File

@ -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]

View File

@ -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"