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:
parent
cec46f985a
commit
3b446963ef
|
@ -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")
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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)))))
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue