fix(wallet): asset sorting (#20659)
* fix(wallet): asset sorting (#20659)
This commit is contained in:
parent
3521421098
commit
6c352397ab
|
@ -177,7 +177,7 @@
|
||||||
"This function returns token values in the props of token-value (quo) component"
|
"This function returns token values in the props of token-value (quo) component"
|
||||||
[{:keys [token color currency currency-symbol]}]
|
[{:keys [token color currency currency-symbol]}]
|
||||||
(let [balance (calculate-total-token-balance token)
|
(let [balance (calculate-total-token-balance token)
|
||||||
fiat-value (calculate-token-fiat-value
|
fiat-unformatted-value (calculate-token-fiat-value
|
||||||
{:currency currency
|
{:currency currency
|
||||||
:balance balance
|
:balance balance
|
||||||
:token token})
|
:token token})
|
||||||
|
@ -191,7 +191,7 @@
|
||||||
crypto-value (get-standard-crypto-format token balance)
|
crypto-value (get-standard-crypto-format token balance)
|
||||||
fiat-value (get-standard-fiat-format crypto-value
|
fiat-value (get-standard-fiat-format crypto-value
|
||||||
currency-symbol
|
currency-symbol
|
||||||
fiat-value)]
|
fiat-unformatted-value)]
|
||||||
{:token (:symbol token)
|
{:token (:symbol token)
|
||||||
:token-name (:name token)
|
:token-name (:name token)
|
||||||
:state :default
|
:state :default
|
||||||
|
@ -201,10 +201,11 @@
|
||||||
(neg? change-pct-24hour) :negative
|
(neg? change-pct-24hour) :negative
|
||||||
:else :empty)
|
:else :empty)
|
||||||
:customization-color color
|
:customization-color color
|
||||||
:values {:crypto-value crypto-value
|
:values {:crypto-value crypto-value
|
||||||
:fiat-value fiat-value
|
:fiat-value fiat-value
|
||||||
:fiat-change formatted-token-price
|
:fiat-unformatted-value fiat-unformatted-value
|
||||||
:percentage-change percentage-change}}))
|
:fiat-change formatted-token-price
|
||||||
|
:percentage-change percentage-change}}))
|
||||||
|
|
||||||
(defn get-multichain-address
|
(defn get-multichain-address
|
||||||
[networks address]
|
[networks address]
|
||||||
|
@ -298,3 +299,18 @@
|
||||||
(utils.string/contains-emoji? s) :emoji
|
(utils.string/contains-emoji? s) :emoji
|
||||||
(existing-account-names s) :existing-name
|
(existing-account-names s) :existing-name
|
||||||
(utils.string/contains-special-character? s) :special-character))
|
(utils.string/contains-special-character? s) :special-character))
|
||||||
|
|
||||||
|
(defn calculate-and-sort-tokens
|
||||||
|
[{:keys [tokens color currency currency-symbol]}]
|
||||||
|
(let [calculate-token (fn [token]
|
||||||
|
(calculate-token-value {:token token
|
||||||
|
:color color
|
||||||
|
:currency currency
|
||||||
|
:currency-symbol currency-symbol}))
|
||||||
|
calculated-tokens (map calculate-token tokens)
|
||||||
|
token-priority {"SNT" 1 "STT" 1 "ETH" 2 "DAI" 3}]
|
||||||
|
(sort-by (fn [token]
|
||||||
|
(let [fiat-value (get-in token [:values :fiat-unformatted-value])
|
||||||
|
priority (get token-priority (:token token) 999)]
|
||||||
|
[(- fiat-value) priority]))
|
||||||
|
calculated-tokens)))
|
||||||
|
|
|
@ -115,3 +115,39 @@
|
||||||
(is (= (utils/prettify-percentage-change 1.113454) "1.11"))
|
(is (= (utils/prettify-percentage-change 1.113454) "1.11"))
|
||||||
(is (= (utils/prettify-percentage-change -0.35) "0.35"))
|
(is (= (utils/prettify-percentage-change -0.35) "0.35"))
|
||||||
(is (= (utils/prettify-percentage-change -0.78234) "0.78"))))
|
(is (= (utils/prettify-percentage-change -0.78234) "0.78"))))
|
||||||
|
|
||||||
|
(deftest calculate-and-sort-tokens-test
|
||||||
|
(testing "calculate-and-sort-tokens function"
|
||||||
|
(let [mock-color "blue"
|
||||||
|
mock-currency "USD"
|
||||||
|
mock-currency-symbol "$"]
|
||||||
|
|
||||||
|
(with-redefs [utils/calculate-token-value
|
||||||
|
(fn [{:keys [token]}]
|
||||||
|
(case (:symbol token)
|
||||||
|
"ETH" {:token "ETH" :values {:fiat-unformatted-value 5}}
|
||||||
|
"DAI" {:token "DAI" :values {:fiat-unformatted-value 10}}
|
||||||
|
"SNT" {:token "SNT" :values {:fiat-unformatted-value 1}}))]
|
||||||
|
(testing "Standard case with different fiat-unformatted-values"
|
||||||
|
(let [mock-tokens [{:symbol "ETH"
|
||||||
|
:name "Ethereum"
|
||||||
|
:balances-per-chain {:mock-chain 5}
|
||||||
|
:decimals 18}
|
||||||
|
{:symbol "DAI"
|
||||||
|
:name "Dai"
|
||||||
|
:balances-per-chain {:mock-chain 10}
|
||||||
|
:decimals 18}
|
||||||
|
{:symbol "SNT"
|
||||||
|
:name "Status Network Token"
|
||||||
|
:balances-per-chain {:mock-chain 1}
|
||||||
|
:decimals 18}]
|
||||||
|
mock-input {:tokens mock-tokens
|
||||||
|
:color mock-color
|
||||||
|
:currency mock-currency
|
||||||
|
:currency-symbol mock-currency-symbol}
|
||||||
|
sorted-tokens (map :token (utils/calculate-and-sort-tokens mock-input))
|
||||||
|
expected-order ["DAI" "ETH" "SNT"]]
|
||||||
|
(is (= expected-order sorted-tokens))))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -489,19 +489,6 @@
|
||||||
(fn [ui]
|
(fn [ui]
|
||||||
(get-in ui [:account-page :active-tab])))
|
(get-in ui [:account-page :active-tab])))
|
||||||
|
|
||||||
(rf/reg-sub
|
|
||||||
:wallet/current-viewing-account-token-values
|
|
||||||
:<- [:wallet/current-viewing-account]
|
|
||||||
:<- [:wallet/current-viewing-account-tokens-in-selected-networks]
|
|
||||||
:<- [:profile/currency]
|
|
||||||
:<- [:profile/currency-symbol]
|
|
||||||
(fn [[{:keys [color]} tokens currency currency-symbol]]
|
|
||||||
(mapv #(utils/calculate-token-value {:token %
|
|
||||||
:color color
|
|
||||||
:currency currency
|
|
||||||
:currency-symbol currency-symbol})
|
|
||||||
tokens)))
|
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/aggregated-tokens
|
:wallet/aggregated-tokens
|
||||||
:<- [:wallet/accounts-without-watched-accounts]
|
:<- [:wallet/accounts-without-watched-accounts]
|
||||||
|
@ -515,6 +502,18 @@
|
||||||
(fn [[aggregated-tokens chain-ids]]
|
(fn [[aggregated-tokens chain-ids]]
|
||||||
(utils/filter-tokens-in-chains aggregated-tokens chain-ids)))
|
(utils/filter-tokens-in-chains aggregated-tokens chain-ids)))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:wallet/current-viewing-account-token-values
|
||||||
|
:<- [:wallet/current-viewing-account]
|
||||||
|
:<- [:wallet/current-viewing-account-tokens-in-selected-networks]
|
||||||
|
:<- [:profile/currency]
|
||||||
|
:<- [:profile/currency-symbol]
|
||||||
|
(fn [[{:keys [color]} tokens currency currency-symbol]]
|
||||||
|
(utils/calculate-and-sort-tokens {:tokens tokens
|
||||||
|
:color color
|
||||||
|
:currency currency
|
||||||
|
:currency-symbol currency-symbol})))
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/aggregated-token-values-and-balance
|
:wallet/aggregated-token-values-and-balance
|
||||||
:<- [:wallet/aggregated-tokens-in-selected-networks]
|
:<- [:wallet/aggregated-tokens-in-selected-networks]
|
||||||
|
@ -522,16 +521,17 @@
|
||||||
:<- [:profile/currency]
|
:<- [:profile/currency]
|
||||||
:<- [:profile/currency-symbol]
|
:<- [:profile/currency-symbol]
|
||||||
(fn [[aggregated-tokens color currency currency-symbol]]
|
(fn [[aggregated-tokens color currency currency-symbol]]
|
||||||
(let [balance (utils/calculate-balance-from-tokens {:currency currency
|
(let [balance (utils/calculate-balance-from-tokens {:currency currency
|
||||||
:tokens aggregated-tokens})
|
:tokens aggregated-tokens})
|
||||||
formatted-balance (utils/prettify-balance currency-symbol balance)]
|
formatted-balance (utils/prettify-balance currency-symbol balance)
|
||||||
|
sorted-token-values (utils/calculate-and-sort-tokens {:tokens aggregated-tokens
|
||||||
|
:color color
|
||||||
|
:currency currency
|
||||||
|
:currency-symbol currency-symbol})]
|
||||||
{:balance balance
|
{:balance balance
|
||||||
:formatted-balance formatted-balance
|
:formatted-balance formatted-balance
|
||||||
:tokens (mapv #(utils/calculate-token-value {:token %
|
:tokens sorted-token-values})))
|
||||||
:color color
|
|
||||||
:currency currency
|
|
||||||
:currency-symbol currency-symbol})
|
|
||||||
aggregated-tokens)})))
|
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:wallet/network-preference-details
|
:wallet/network-preference-details
|
||||||
|
|
Loading…
Reference in New Issue