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 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-contact-code "contact-code")
|
||||||
(def ^:const dapp-permission-web3 "web3")
|
(def ^:const dapp-permission-web3 "web3")
|
||||||
(def ^:const dapp-permission-qr-code "qr-code")
|
(def ^:const dapp-permission-qr-code "qr-code")
|
||||||
|
|
|
@ -307,10 +307,14 @@
|
||||||
:color color
|
:color color
|
||||||
:currency currency
|
:currency currency
|
||||||
:currency-symbol currency-symbol}))
|
:currency-symbol currency-symbol}))
|
||||||
calculated-tokens (map calculate-token tokens)
|
calculated-tokens (map calculate-token tokens)]
|
||||||
token-priority {"SNT" 1 "STT" 1 "ETH" 2 "DAI" 3}]
|
|
||||||
(sort-by (fn [token]
|
(sort-by (fn [token]
|
||||||
(let [fiat-value (get-in token [:values :fiat-unformatted-value])
|
(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]))
|
[(- fiat-value) priority]))
|
||||||
calculated-tokens)))
|
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"]]
|
expected-order ["DAI" "ETH" "SNT"]]
|
||||||
(is (= expected-order sorted-tokens))))))))
|
(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
|
:total-balance (utils/calculate-total-token-balance token
|
||||||
chain-ids)))
|
chain-ids)))
|
||||||
(:tokens account))
|
(:tokens account))
|
||||||
sorted-tokens (sort-by :name compare tokens)]
|
sorted-tokens (utils/sort-tokens tokens)]
|
||||||
(if query
|
(if query
|
||||||
(let [query-string (string/lower-case query)]
|
(let [query-string (string/lower-case query)]
|
||||||
(filter #(or (string/starts-with? (string/lower-case (:name %)) query-string)
|
(filter #(or (string/starts-with? (string/lower-case (:name %)) query-string)
|
||||||
|
|
Loading…
Reference in New Issue