fix sorting

This commit is contained in:
Omar Basem 2024-07-05 08:55:36 +04:00
parent a13975f3f6
commit db6a014bbd
No known key found for this signature in database
GPG Key ID: 62420DCCB9645167
2 changed files with 35 additions and 29 deletions

View File

@ -177,7 +177,7 @@
"This function returns token values in the props of token-value (quo) component"
[{:keys [token color currency currency-symbol]}]
(let [balance (calculate-total-token-balance token)
fiat-value (calculate-token-fiat-value
fiat-unformatted-value (calculate-token-fiat-value
{:currency currency
:balance balance
:token token})
@ -191,7 +191,7 @@
crypto-value (get-standard-crypto-format token balance)
fiat-value (get-standard-fiat-format crypto-value
currency-symbol
fiat-value)]
fiat-unformatted-value)]
{:token (:symbol token)
:token-name (:name token)
:state :default
@ -203,6 +203,7 @@
:customization-color color
:values {:crypto-value crypto-value
:fiat-value fiat-value
:fiat-unformatted-value fiat-unformatted-value
:fiat-change formatted-token-price
:percentage-change percentage-change}}))

View File

@ -490,17 +490,19 @@
(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)))
: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]]
(let [calculated-tokens (mapv #(utils/calculate-token-value {:token %
:color color
:currency currency
:currency-symbol currency-symbol})
tokens)]
(vec (sort-by #(get-in % [:values :fiat-unformatted-value]) > calculated-tokens)))))
(rf/reg-sub
:wallet/aggregated-tokens
@ -516,22 +518,25 @@
(utils/filter-tokens-in-chains aggregated-tokens chain-ids)))
(rf/reg-sub
:wallet/aggregated-token-values-and-balance
:<- [:wallet/aggregated-tokens-in-selected-networks]
:<- [:profile/customization-color]
:<- [:profile/currency]
:<- [:profile/currency-symbol]
(fn [[aggregated-tokens color currency currency-symbol]]
(let [balance (utils/calculate-balance-from-tokens {:currency currency
:tokens aggregated-tokens})
formatted-balance (utils/prettify-balance currency-symbol balance)]
{:balance balance
:formatted-balance formatted-balance
:tokens (mapv #(utils/calculate-token-value {:token %
:color color
:currency currency
:currency-symbol currency-symbol})
aggregated-tokens)})))
:wallet/aggregated-token-values-and-balance
:<- [:wallet/aggregated-tokens-in-selected-networks]
:<- [:profile/customization-color]
:<- [:profile/currency]
:<- [:profile/currency-symbol]
(fn [[aggregated-tokens color currency currency-symbol]]
(let [balance (utils/calculate-balance-from-tokens {:currency currency
:tokens aggregated-tokens})
formatted-balance (utils/prettify-balance currency-symbol balance)
token-values (mapv #(utils/calculate-token-value {:token %
:color color
:currency currency
:currency-symbol currency-symbol})
aggregated-tokens)
sorted-token-values (sort-by #(-> % :values :fiat-unformatted-value) > token-values)]
{:balance balance
:formatted-balance formatted-balance
:tokens sorted-token-values})))
(rf/reg-sub
:wallet/network-preference-details