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
|
;; wallet
|
||||||
(def ^:const mainnet-chain-id 1)
|
(def ^:const mainnet-chain-id 1)
|
||||||
(def ^:const optimism-chain-id 10)
|
(def ^:const optimism-chain-id 10)
|
||||||
|
(def ^:const optimism-test-chain-id 420)
|
||||||
(def ^:const arbitrum-chain-id 42161)
|
(def ^:const arbitrum-chain-id 42161)
|
||||||
|
(def ^:const arbitrum-test-chain-id 421613)
|
||||||
(def ^:const goerli-chain-id 5)
|
(def ^:const goerli-chain-id 5)
|
||||||
|
|
||||||
(def ^:const mainnet-short-name "eth")
|
(def ^:const mainnet-short-name "eth")
|
||||||
|
@ -1,34 +1,28 @@
|
|||||||
(ns status-im2.contexts.wallet.account.tabs.view
|
(ns status-im2.contexts.wallet.account.tabs.view
|
||||||
(:require
|
(:require
|
||||||
[quo.theme]
|
|
||||||
[react-native.core :as rn]
|
[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.about.view :as about]
|
||||||
[status-im2.contexts.wallet.account.tabs.dapps.view :as dapps]
|
[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.activity-tab.view :as activity]
|
||||||
[status-im2.contexts.wallet.common.collectibles-tab.view :as collectibles]
|
[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.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]
|
[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
|
(defn view
|
||||||
[{:keys [selected-tab theme]}]
|
[{:keys [selected-tab]}]
|
||||||
(case selected-tab
|
(let [tokens (filter identity (rf/sub [:wallet/account-token-values]))]
|
||||||
:assets [rn/flat-list
|
(case selected-tab
|
||||||
{:render-fn token-value/view
|
:assets [rn/flat-list
|
||||||
:data temp/tokens
|
{:render-fn token-value/view
|
||||||
:content-container-style {:padding-horizontal 8}}]
|
:data tokens
|
||||||
:collectibles [collectibles/view]
|
:content-container-style {:padding-horizontal 8}}]
|
||||||
:activity [activity/view]
|
:collectibles [collectibles/view]
|
||||||
:permissions [empty-tab/view
|
:activity [activity/view]
|
||||||
{:title (i18n/label :t/no-permissions)
|
:permissions [empty-tab/view
|
||||||
:description (i18n/label :t/no-collectibles-description)
|
{:title (i18n/label :t/no-permissions)
|
||||||
:image (resources/get-image
|
:description (i18n/label :t/no-collectibles-description)
|
||||||
(quo.theme/theme-value :no-permissions-light
|
:placeholder? true}]
|
||||||
:no-permissions-dark
|
:dapps [dapps/view]
|
||||||
theme))}]
|
[about/view])))
|
||||||
:dapps [dapps/view]
|
|
||||||
[about/view]))
|
|
||||||
|
|
||||||
(def view (quo.theme/with-theme view-internal))
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
(ns status-im2.contexts.wallet.common.utils
|
(ns status-im2.contexts.wallet.common.utils
|
||||||
(:require [clojure.string :as string]
|
(:require [clojure.string :as string]
|
||||||
[status-im2.constants :as constants]
|
[status-im2.constants :as constants]
|
||||||
|
[utils.money :as money]
|
||||||
[utils.number]))
|
[utils.number]))
|
||||||
|
|
||||||
(defn get-first-name
|
(defn get-first-name
|
||||||
@ -23,7 +24,7 @@
|
|||||||
(let [path (get-derivation-path number-of-accounts)]
|
(let [path (get-derivation-path number-of-accounts)]
|
||||||
(format-derivation-path path)))
|
(format-derivation-path path)))
|
||||||
|
|
||||||
(defn- calculate-raw-balance
|
(defn calculate-raw-balance
|
||||||
[raw-balance decimals]
|
[raw-balance decimals]
|
||||||
(if-let [n (utils.number/parse-int raw-balance nil)]
|
(if-let [n (utils.number/parse-int raw-balance nil)]
|
||||||
(/ n (Math/pow 10 (utils.number/parse-int decimals)))
|
(/ n (Math/pow 10 (utils.number/parse-int decimals)))
|
||||||
@ -36,6 +37,12 @@
|
|||||||
(map #(calculate-raw-balance (:raw-balance %) decimals))
|
(map #(calculate-raw-balance (:raw-balance %) decimals))
|
||||||
(reduce +)))
|
(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
|
(defn calculate-balance
|
||||||
[tokens-in-account]
|
[tokens-in-account]
|
||||||
(->> tokens-in-account
|
(->> tokens-in-account
|
||||||
@ -52,3 +59,7 @@
|
|||||||
(= (:related-chain-id %) chain-id))
|
(= (:related-chain-id %) chain-id))
|
||||||
networks)))
|
networks)))
|
||||||
(keys balances-per-chain))))
|
(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]
|
:<- [:wallet/current-viewing-account-address]
|
||||||
(fn [[accounts current-viewing-account-address]]
|
(fn [[accounts current-viewing-account-address]]
|
||||||
(remove #(= (:address %) current-viewing-account-address) accounts)))
|
(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