Skip to content

Commit

Permalink
implement functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mmilad75 authored and mariia-skrypnyk committed Apr 19, 2024
1 parent 702899a commit 16c5740
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/status_im/contexts/wallet/common/utils.cljs
Expand Up @@ -130,6 +130,13 @@
:token %}))
(reduce money/add)))

(defn calculate-balance-from-accounts
[accounts balances]
(reduce (fn [acc item]
(money/add acc (get balances (:address item))))
(money/bignumber 0)
accounts))

(defn- add-balances-per-chain
[b1 b2]
{:raw-balance (money/add (:raw-balance b1) (:raw-balance b2))
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/contexts/wallet/home/view.cljs
Expand Up @@ -43,7 +43,7 @@
networks (rf/sub [:wallet/selected-network-details])
account-cards-data (rf/sub [:wallet/account-cards-data])
cards (conj account-cards-data (new-account-card-data))
{:keys [formatted-balance]} (rf/sub [:wallet/aggregated-token-values-and-balance])]
{:keys [formatted-balance]} (rf/sub [:wallet/total-owned-accounts-balance])]
(rn/use-effect (fn []
(when (and @account-list-ref (pos? (count cards)))
(.scrollToOffset ^js @account-list-ref
Expand Down
11 changes: 11 additions & 0 deletions src/status_im/subs/wallet/wallet.cljs
Expand Up @@ -312,6 +312,17 @@
:currency-symbol currency-symbol})
aggregated-tokens)})))

(rf/reg-sub
:wallet/total-owned-accounts-balance
:<- [:wallet/accounts-without-watched-accounts]
:<- [:wallet/balances-in-selected-networks]
:<- [:profile/currency-symbol]
(fn [[accounts balances currency-symbol]]
(let [raw-balance (utils/calculate-balance-from-accounts accounts balances)
formatted-balance (utils/prettify-balance currency-symbol raw-balance)]
{:balance raw-balance
:formatted-balance formatted-balance})))

(rf/reg-sub
:wallet/network-preference-details
:<- [:wallet/current-viewing-account]
Expand Down

0 comments on commit 16c5740

Please sign in to comment.