mirror of
https://github.com/status-im/status-react.git
synced 2025-02-17 05:16:46 +00:00
[Feature] Wallet - Display token price (#18438)
This commit adds a feature to display token prices for each token in the Wallet home and Account screens. Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
This commit is contained in:
parent
7b639f2ffe
commit
d1c8f6411d
@ -221,29 +221,43 @@
|
|||||||
"<$0.01"
|
"<$0.01"
|
||||||
(prettify-balance currency-symbol fiat-value)))
|
(prettify-balance currency-symbol fiat-value)))
|
||||||
|
|
||||||
|
(defn prettify-percentage-change
|
||||||
|
"Returns unsigned precentage"
|
||||||
|
[percentage]
|
||||||
|
(-> (if (number? percentage) percentage 0)
|
||||||
|
money/bignumber
|
||||||
|
money/absolute-value
|
||||||
|
(money/to-fixed 2)))
|
||||||
|
|
||||||
(defn calculate-token-value
|
(defn calculate-token-value
|
||||||
"This function returns token values in the props of token-value (quo) component"
|
"This function returns token values in the props of token-value (quo) component"
|
||||||
[{:keys [token color currency currency-symbol]}]
|
[{:keys [token color currency currency-symbol]}]
|
||||||
(let [token-units (total-token-units-in-all-chains token)
|
(let [token-units (total-token-units-in-all-chains token)
|
||||||
fiat-value (total-token-fiat-value currency token)
|
fiat-value (total-token-fiat-value currency token)
|
||||||
market-values (or (get-in token [:market-values-per-currency currency])
|
market-values (or (get-in token [:market-values-per-currency currency])
|
||||||
(get-in token
|
(get-in token
|
||||||
[:market-values-per-currency
|
[:market-values-per-currency
|
||||||
constants/profile-default-currency]))
|
constants/profile-default-currency]))
|
||||||
{:keys [change-pct-24hour]} market-values
|
{:keys [price change-pct-24hour]} market-values
|
||||||
crypto-value (get-standard-crypto-format token token-units)
|
formatted-token-price (prettify-balance currency-symbol price)
|
||||||
fiat-value (get-standard-fiat-format crypto-value currency-symbol fiat-value)]
|
percentage-change (prettify-percentage-change change-pct-24hour)
|
||||||
|
crypto-value (get-standard-crypto-format token token-units)
|
||||||
|
fiat-value (get-standard-fiat-format crypto-value
|
||||||
|
currency-symbol
|
||||||
|
fiat-value)]
|
||||||
{:token (:symbol token)
|
{:token (:symbol token)
|
||||||
:token-name (:name token)
|
:token-name (:name token)
|
||||||
:state :default
|
:state :default
|
||||||
|
:metrics? true
|
||||||
:status (cond
|
:status (cond
|
||||||
(pos? change-pct-24hour) :positive
|
(pos? change-pct-24hour) :positive
|
||||||
(neg? change-pct-24hour) :negative
|
(neg? change-pct-24hour) :negative
|
||||||
:else :empty)
|
:else :empty)
|
||||||
:customization-color color
|
:customization-color color
|
||||||
:values {:crypto-value crypto-value
|
:values {:crypto-value crypto-value
|
||||||
:fiat-value fiat-value}}))
|
:fiat-value fiat-value
|
||||||
|
:fiat-change formatted-token-price
|
||||||
|
:percentage-change percentage-change}}))
|
||||||
|
|
||||||
(defn get-multichain-address
|
(defn get-multichain-address
|
||||||
[networks address]
|
[networks address]
|
||||||
|
@ -106,3 +106,12 @@
|
|||||||
|
|
||||||
(is (= (utils/get-wallet-qr wallet-singlechain)
|
(is (= (utils/get-wallet-qr wallet-singlechain)
|
||||||
"x000")))))
|
"x000")))))
|
||||||
|
|
||||||
|
(deftest test-prettify-percentage-change
|
||||||
|
(testing "prettify-percentage-change function"
|
||||||
|
(is (= (utils/prettify-percentage-change nil) "0.00"))
|
||||||
|
(is (= (utils/prettify-percentage-change "") "0.00"))
|
||||||
|
(is (= (utils/prettify-percentage-change 0.5) "0.50"))
|
||||||
|
(is (= (utils/prettify-percentage-change 1.113454) "1.11"))
|
||||||
|
(is (= (utils/prettify-percentage-change -0.35) "0.35"))
|
||||||
|
(is (= (utils/prettify-percentage-change -0.78234) "0.78"))))
|
||||||
|
@ -229,6 +229,11 @@
|
|||||||
[bn1 bn2]
|
[bn1 bn2]
|
||||||
(.round (.dividedBy ^js bn1 bn2) 0))
|
(.round (.dividedBy ^js bn1 bn2) 0))
|
||||||
|
|
||||||
|
(defn absolute-value
|
||||||
|
[bn]
|
||||||
|
(when bn
|
||||||
|
(.absoluteValue ^js bn)))
|
||||||
|
|
||||||
(defn format-amount
|
(defn format-amount
|
||||||
"Format `amount` to thousands or millions. Return nil if `amount` is not truthy."
|
"Format `amount` to thousands or millions. Return nil if `amount` is not truthy."
|
||||||
[amount]
|
[amount]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user