fix: assets sort order on bridge and assets screen (#20813)

* fix: assets sort order on bridge and assets screen (#20813)
This commit is contained in:
Omar Basem 2024-07-22 14:16:40 +04:00 committed by GitHub
parent cec46f985a
commit 3b446963ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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