From db6a014bbdb5ad8f42208b390dd3c2a892a063f3 Mon Sep 17 00:00:00 2001 From: Omar Basem Date: Fri, 5 Jul 2024 08:55:36 +0400 Subject: [PATCH] fix sorting --- .../contexts/wallet/common/utils.cljs | 5 +- src/status_im/subs/wallet/wallet.cljs | 59 ++++++++++--------- 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/src/status_im/contexts/wallet/common/utils.cljs b/src/status_im/contexts/wallet/common/utils.cljs index 3e2e9660e5..e47b709a14 100644 --- a/src/status_im/contexts/wallet/common/utils.cljs +++ b/src/status_im/contexts/wallet/common/utils.cljs @@ -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}})) diff --git a/src/status_im/subs/wallet/wallet.cljs b/src/status_im/subs/wallet/wallet.cljs index e481c1c7fb..b74f93a635 100644 --- a/src/status_im/subs/wallet/wallet.cljs +++ b/src/status_im/subs/wallet/wallet.cljs @@ -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