Wallet - Add token filter and prices fallback for fiat amount calculation (#18398)

This commit:

- Adds a filter to remove tokens with no name or symbol to prevent displaying tokens with no data
- Adds a fallback value (zero) for token fiat value calculation and to prevent crash on token price calculation

---------

Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
Mohamed Javid 2024-01-18 15:16:00 +05:30 committed by GitHub
parent 8a4302c85a
commit ed3cb42572
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 4 deletions

View File

@ -90,10 +90,13 @@
(defn total-token-fiat-value (defn total-token-fiat-value
"Returns the total token fiat value taking into account all token's chains." "Returns the total token fiat value taking into account all token's chains."
[currency {:keys [market-values-per-currency] :as token}] [currency {:keys [market-values-per-currency] :as token}]
(let [price (get-in market-values-per-currency (let [price (or (get-in market-values-per-currency
[currency :price] [currency :price])
(get-in market-values-per-currency (get-in market-values-per-currency
[constants/profile-default-currency :price])) [constants/profile-default-currency :price])
;; NOTE: adding fallback value (zero) in case prices are
;; unavailable and to prevent crash on calculating fiat value
0)
total-units-in-all-chains (total-token-units-in-all-chains token)] total-units-in-all-chains (total-token-units-in-all-chains token)]
(money/crypto->fiat total-units-in-all-chains price))) (money/crypto->fiat total-units-in-all-chains price)))

View File

@ -57,11 +57,18 @@
(update :balances-per-chain update-vals #(update % :raw-balance money/bignumber)) (update :balances-per-chain update-vals #(update % :raw-balance money/bignumber))
(update :balances-per-chain update-keys (comp utils.number/parse-int name)))) (update :balances-per-chain update-keys (comp utils.number/parse-int name))))
(defn- remove-tokens-with-empty-values
[tokens]
(remove
#(or (string/blank? (:symbol %)) (string/blank? (:name %)))
tokens))
(defn rpc->tokens (defn rpc->tokens
[tokens] [tokens]
(-> tokens (-> tokens
(update-keys name) (update-keys name)
(update-vals #(cske/transform-keys csk/->kebab-case %)) (update-vals #(cske/transform-keys csk/->kebab-case %))
(update-vals remove-tokens-with-empty-values)
(update-vals #(mapv rpc->balances-per-chain %)))) (update-vals #(mapv rpc->balances-per-chain %))))
(defn rpc->network (defn rpc->network