mirror of
https://github.com/status-im/status-react.git
synced 2025-02-25 17:16:03 +00:00
parent
64de325678
commit
5c30fd847a
@ -372,7 +372,9 @@
|
||||
;; wallet
|
||||
(def ^:const mainnet-chain-id 1)
|
||||
(def ^:const optimism-chain-id 10)
|
||||
(def ^:const optimism-test-chain-id 420)
|
||||
(def ^:const arbitrum-chain-id 42161)
|
||||
(def ^:const arbitrum-test-chain-id 421613)
|
||||
(def ^:const goerli-chain-id 5)
|
||||
|
||||
(def ^:const mainnet-short-name "eth")
|
||||
|
@ -1,34 +1,28 @@
|
||||
(ns status-im2.contexts.wallet.account.tabs.view
|
||||
(:require
|
||||
[quo.theme]
|
||||
[react-native.core :as rn]
|
||||
[status-im2.common.resources :as resources]
|
||||
[status-im2.contexts.wallet.account.tabs.about.view :as about]
|
||||
[status-im2.contexts.wallet.account.tabs.dapps.view :as dapps]
|
||||
[status-im2.contexts.wallet.common.activity-tab.view :as activity]
|
||||
[status-im2.contexts.wallet.common.collectibles-tab.view :as collectibles]
|
||||
[status-im2.contexts.wallet.common.empty-tab.view :as empty-tab]
|
||||
[status-im2.contexts.wallet.common.temp :as temp]
|
||||
[status-im2.contexts.wallet.common.token-value.view :as token-value]
|
||||
[utils.i18n :as i18n]))
|
||||
[utils.i18n :as i18n]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
(defn- view-internal
|
||||
[{:keys [selected-tab theme]}]
|
||||
(case selected-tab
|
||||
:assets [rn/flat-list
|
||||
{:render-fn token-value/view
|
||||
:data temp/tokens
|
||||
:content-container-style {:padding-horizontal 8}}]
|
||||
:collectibles [collectibles/view]
|
||||
:activity [activity/view]
|
||||
:permissions [empty-tab/view
|
||||
{:title (i18n/label :t/no-permissions)
|
||||
:description (i18n/label :t/no-collectibles-description)
|
||||
:image (resources/get-image
|
||||
(quo.theme/theme-value :no-permissions-light
|
||||
:no-permissions-dark
|
||||
theme))}]
|
||||
:dapps [dapps/view]
|
||||
[about/view]))
|
||||
|
||||
(def view (quo.theme/with-theme view-internal))
|
||||
(defn view
|
||||
[{:keys [selected-tab]}]
|
||||
(let [tokens (filter identity (rf/sub [:wallet/account-token-values]))]
|
||||
(case selected-tab
|
||||
:assets [rn/flat-list
|
||||
{:render-fn token-value/view
|
||||
:data tokens
|
||||
:content-container-style {:padding-horizontal 8}}]
|
||||
:collectibles [collectibles/view]
|
||||
:activity [activity/view]
|
||||
:permissions [empty-tab/view
|
||||
{:title (i18n/label :t/no-permissions)
|
||||
:description (i18n/label :t/no-collectibles-description)
|
||||
:placeholder? true}]
|
||||
:dapps [dapps/view]
|
||||
[about/view])))
|
||||
|
@ -1,6 +1,7 @@
|
||||
(ns status-im2.contexts.wallet.common.utils
|
||||
(:require [clojure.string :as string]
|
||||
[status-im2.constants :as constants]
|
||||
[utils.money :as money]
|
||||
[utils.number]))
|
||||
|
||||
(defn get-first-name
|
||||
@ -23,7 +24,7 @@
|
||||
(let [path (get-derivation-path number-of-accounts)]
|
||||
(format-derivation-path path)))
|
||||
|
||||
(defn- calculate-raw-balance
|
||||
(defn calculate-raw-balance
|
||||
[raw-balance decimals]
|
||||
(if-let [n (utils.number/parse-int raw-balance nil)]
|
||||
(/ n (Math/pow 10 (utils.number/parse-int decimals)))
|
||||
@ -36,6 +37,12 @@
|
||||
(map #(calculate-raw-balance (:raw-balance %) decimals))
|
||||
(reduce +)))
|
||||
|
||||
(defn token-value-in-chain
|
||||
[{:keys [balances-per-chain decimals]} chain-id]
|
||||
(let [balance-in-chain (get balances-per-chain chain-id)]
|
||||
(when balance-in-chain
|
||||
(calculate-raw-balance (:raw-balance balance-in-chain) decimals))))
|
||||
|
||||
(defn calculate-balance
|
||||
[tokens-in-account]
|
||||
(->> tokens-in-account
|
||||
@ -52,3 +59,7 @@
|
||||
(= (:related-chain-id %) chain-id))
|
||||
networks)))
|
||||
(keys balances-per-chain))))
|
||||
|
||||
(defn calculate-fiat-change
|
||||
[fiat-value change-pct-24hour]
|
||||
(money/bignumber (* fiat-value (/ change-pct-24hour (+ 100 change-pct-24hour)))))
|
||||
|
@ -99,3 +99,29 @@
|
||||
:<- [:wallet/current-viewing-account-address]
|
||||
(fn [[accounts current-viewing-account-address]]
|
||||
(remove #(= (:address %) current-viewing-account-address) accounts)))
|
||||
|
||||
(defn- calc-token-value
|
||||
[{:keys [market-values-per-currency] :as item} chain-id]
|
||||
(let [crypto-value (utils/token-value-in-chain item chain-id)
|
||||
market-values (:usd market-values-per-currency)
|
||||
{:keys [price change-pct-24hour]} market-values
|
||||
fiat-change (utils/calculate-fiat-change crypto-value change-pct-24hour)]
|
||||
(when crypto-value
|
||||
{:token (keyword (string/lower-case (:symbol item)))
|
||||
:state :default
|
||||
:status (cond
|
||||
(pos? change-pct-24hour) :positive
|
||||
(neg? change-pct-24hour) :negative
|
||||
:else :empty)
|
||||
:customization-color :blue
|
||||
:values {:crypto-value crypto-value
|
||||
:fiat-value (utils/prettify-balance (* crypto-value price))
|
||||
:percentage-change (.toFixed change-pct-24hour 2)
|
||||
:fiat-change (utils/prettify-balance fiat-change)}})))
|
||||
|
||||
(rf/reg-sub
|
||||
:wallet/account-token-values
|
||||
:<- [:wallet/current-viewing-account]
|
||||
:<- [:chain-id]
|
||||
(fn [[current-account chain-id]]
|
||||
(mapv #(calc-token-value % chain-id) (:tokens current-account))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user