diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 4299c6bb59..ccee37f4d9 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -293,6 +293,8 @@ (def ^:const transaction-pending-type-wallet-connect-transfer "WalletConnectTransfer") +(def ^:const token-sort-priority {"SNT" 1 "STT" 1 "ETH" 2 "DAI" 3}) + (def ^:const dapp-permission-contact-code "contact-code") (def ^:const dapp-permission-web3 "web3") (def ^:const dapp-permission-qr-code "qr-code") diff --git a/src/status_im/contexts/wallet/common/utils.cljs b/src/status_im/contexts/wallet/common/utils.cljs index 5232d1a4b9..65f3844f65 100644 --- a/src/status_im/contexts/wallet/common/utils.cljs +++ b/src/status_im/contexts/wallet/common/utils.cljs @@ -307,10 +307,14 @@ :color color :currency currency :currency-symbol currency-symbol})) - calculated-tokens (map calculate-token tokens) - token-priority {"SNT" 1 "STT" 1 "ETH" 2 "DAI" 3}] + calculated-tokens (map calculate-token tokens)] (sort-by (fn [token] (let [fiat-value (get-in token [:values :fiat-unformatted-value]) - priority (get token-priority (:token token) 999)] + priority (get constants/token-sort-priority (:token token) ##Inf)] [(- fiat-value) priority])) calculated-tokens))) + +(defn sort-tokens + [tokens] + (let [priority #(get constants/token-sort-priority (:symbol %) ##Inf)] + (sort-by (juxt (comp - :balance) priority) tokens))) diff --git a/src/status_im/contexts/wallet/common/utils_test.cljs b/src/status_im/contexts/wallet/common/utils_test.cljs index 281f8f06fd..f72f9bbb37 100644 --- a/src/status_im/contexts/wallet/common/utils_test.cljs +++ b/src/status_im/contexts/wallet/common/utils_test.cljs @@ -149,5 +149,14 @@ expected-order ["DAI" "ETH" "SNT"]] (is (= expected-order sorted-tokens)))))))) +(deftest sort-tokens-test + (testing "sort-tokens function" + (let [mock-tokens [{:symbol "ETH" :balance 5} + {:symbol "DAI" :balance 10} + {:symbol "SNT" :balance 1}] + sorted-tokens (map :symbol (utils/sort-tokens mock-tokens)) + expected-order ["DAI" "ETH" "SNT"]] + (is (= expected-order sorted-tokens))))) + diff --git a/src/status_im/subs/wallet/wallet.cljs b/src/status_im/subs/wallet/wallet.cljs index b8b9b8bc75..bebb790b90 100644 --- a/src/status_im/subs/wallet/wallet.cljs +++ b/src/status_im/subs/wallet/wallet.cljs @@ -416,7 +416,7 @@ :total-balance (utils/calculate-total-token-balance token chain-ids))) (:tokens account)) - sorted-tokens (sort-by :name compare tokens)] + sorted-tokens (utils/sort-tokens tokens)] (if query (let [query-string (string/lower-case query)] (filter #(or (string/starts-with? (string/lower-case (:name %)) query-string)