From 80bab0f976c33930199b0021489a8fbd3c1c1b24 Mon Sep 17 00:00:00 2001 From: Brian Sztamfater Date: Thu, 19 Dec 2024 00:00:51 -0300 Subject: [PATCH] add token-with-balances utils functions Signed-off-by: Brian Sztamfater --- src/status_im/contexts/wallet/common/utils.cljs | 16 +++++++++++----- src/status_im/contexts/wallet/events.cljs | 9 +-------- src/status_im/contexts/wallet/send/events.cljs | 10 +--------- 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/status_im/contexts/wallet/common/utils.cljs b/src/status_im/contexts/wallet/common/utils.cljs index 669e65a50f..69da2c00c7 100644 --- a/src/status_im/contexts/wallet/common/utils.cljs +++ b/src/status_im/contexts/wallet/common/utils.cljs @@ -546,14 +546,20 @@ (let [priority #(get constants/token-sort-priority (:symbol %) ##Inf)] (sort-by (juxt :symbol priority) tokens))) +(defn token-with-balance + ([token networks] + (token-with-balance token networks nil)) + ([token networks chain-ids] + (assoc token + :networks (network-utils/network-list-with-positive-balance token networks) + :supported-networks (network-utils/network-list token networks) + :available-balance (calculate-total-token-balance token) + :total-balance (calculate-total-token-balance token chain-ids)))) + (defn tokens-with-balance [tokens networks chain-ids] (map (fn [token] - (assoc token - :networks (network-utils/network-list-with-positive-balance token networks) - :supported-networks (network-utils/network-list token networks) - :available-balance (calculate-total-token-balance token) - :total-balance (calculate-total-token-balance token chain-ids))) + (token-with-balance token networks chain-ids)) tokens)) (defn estimated-time-format diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index eda53353b5..7cf13ee9a7 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -366,14 +366,7 @@ (let [token (utils/get-token-from-account db token-symbol unique-owner)] - (assoc token - :networks (network-utils/network-list-with-positive-balance - token - network-details) - :supported-networks (network-utils/network-list - token - network-details) - :total-balance (utils/calculate-total-token-balance token))) + (utils/token-with-balance token network-details)) token) missing-recipient? (-> db :wallet :ui :send :to-address nil?) to-address (or unique-owner diff --git a/src/status_im/contexts/wallet/send/events.cljs b/src/status_im/contexts/wallet/send/events.cljs index dc40a10bd3..cf6360046d 100644 --- a/src/status_im/contexts/wallet/send/events.cljs +++ b/src/status_im/contexts/wallet/send/events.cljs @@ -5,7 +5,6 @@ [status-im.contexts.wallet.collectible.utils :as collectible.utils] [status-im.contexts.wallet.common.utils :as utils] [status-im.contexts.wallet.common.utils.networks :as network-utils] - [status-im.contexts.wallet.common.wizard.utils :as wizard-utils] [status-im.contexts.wallet.data-store :as data-store] [status-im.contexts.wallet.send.utils :as send-utils] [status-im.contexts.wallet.sheets.network-selection.view :as network-selection] @@ -667,14 +666,7 @@ ;; token or collectible to send, but we don't know from which ;; account, so we extract the token data from the picked account. (let [token (utils/get-token-from-account db token-symbol address)] - (assoc token - :networks (network-utils/network-list-with-positive-balance - token - network-details) - :supported-networks (network-utils/network-list - token - network-details) - :total-balance (utils/calculate-total-token-balance token)))) + (utils/token-with-balance token network-details))) bridge-tx? (= tx-type :tx/bridge) flow-id (if bridge-tx? :wallet-bridge-flow