Skip to content

Commit 0307acd

Browse files
OmarBasemyevh-berdnyk
authored andcommitted
Wallet: account real data (#17821)
* wallet: account real data
1 parent 5dd7053 commit 0307acd

File tree

4 files changed

+58
-25
lines changed

4 files changed

+58
-25
lines changed

src/status_im2/constants.cljs

+2
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@
372372
;; wallet
373373
(def ^:const mainnet-chain-id 1)
374374
(def ^:const optimism-chain-id 10)
375+
(def ^:const optimism-test-chain-id 420)
375376
(def ^:const arbitrum-chain-id 42161)
377+
(def ^:const arbitrum-test-chain-id 421613)
376378
(def ^:const goerli-chain-id 5)
377379

378380
(def ^:const mainnet-short-name "eth")
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
(ns status-im2.contexts.wallet.account.tabs.view
22
(:require
3-
[quo.theme]
43
[react-native.core :as rn]
5-
[status-im2.common.resources :as resources]
64
[status-im2.contexts.wallet.account.tabs.about.view :as about]
75
[status-im2.contexts.wallet.account.tabs.dapps.view :as dapps]
86
[status-im2.contexts.wallet.common.activity-tab.view :as activity]
97
[status-im2.contexts.wallet.common.collectibles-tab.view :as collectibles]
108
[status-im2.contexts.wallet.common.empty-tab.view :as empty-tab]
11-
[status-im2.contexts.wallet.common.temp :as temp]
129
[status-im2.contexts.wallet.common.token-value.view :as token-value]
13-
[utils.i18n :as i18n]))
10+
[utils.i18n :as i18n]
11+
[utils.re-frame :as rf]))
1412

15-
(defn- view-internal
16-
[{:keys [selected-tab theme]}]
17-
(case selected-tab
18-
:assets [rn/flat-list
19-
{:render-fn token-value/view
20-
:data temp/tokens
21-
:content-container-style {:padding-horizontal 8}}]
22-
:collectibles [collectibles/view]
23-
:activity [activity/view]
24-
:permissions [empty-tab/view
25-
{:title (i18n/label :t/no-permissions)
26-
:description (i18n/label :t/no-collectibles-description)
27-
:image (resources/get-image
28-
(quo.theme/theme-value :no-permissions-light
29-
:no-permissions-dark
30-
theme))}]
31-
:dapps [dapps/view]
32-
[about/view]))
33-
34-
(def view (quo.theme/with-theme view-internal))
13+
(defn view
14+
[{:keys [selected-tab]}]
15+
(let [tokens (filter identity (rf/sub [:wallet/account-token-values]))]
16+
(case selected-tab
17+
:assets [rn/flat-list
18+
{:render-fn token-value/view
19+
:data tokens
20+
:content-container-style {:padding-horizontal 8}}]
21+
:collectibles [collectibles/view]
22+
:activity [activity/view]
23+
:permissions [empty-tab/view
24+
{:title (i18n/label :t/no-permissions)
25+
:description (i18n/label :t/no-collectibles-description)
26+
:placeholder? true}]
27+
:dapps [dapps/view]
28+
[about/view])))

src/status_im2/contexts/wallet/common/utils.cljs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns status-im2.contexts.wallet.common.utils
22
(:require [clojure.string :as string]
33
[status-im2.constants :as constants]
4+
[utils.money :as money]
45
[utils.number]))
56

67
(defn get-first-name
@@ -23,7 +24,7 @@
2324
(let [path (get-derivation-path number-of-accounts)]
2425
(format-derivation-path path)))
2526

26-
(defn- calculate-raw-balance
27+
(defn calculate-raw-balance
2728
[raw-balance decimals]
2829
(if-let [n (utils.number/parse-int raw-balance nil)]
2930
(/ n (Math/pow 10 (utils.number/parse-int decimals)))
@@ -36,6 +37,12 @@
3637
(map #(calculate-raw-balance (:raw-balance %) decimals))
3738
(reduce +)))
3839

40+
(defn token-value-in-chain
41+
[{:keys [balances-per-chain decimals]} chain-id]
42+
(let [balance-in-chain (get balances-per-chain chain-id)]
43+
(when balance-in-chain
44+
(calculate-raw-balance (:raw-balance balance-in-chain) decimals))))
45+
3946
(defn calculate-balance
4047
[tokens-in-account]
4148
(->> tokens-in-account
@@ -52,3 +59,7 @@
5259
(= (:related-chain-id %) chain-id))
5360
networks)))
5461
(keys balances-per-chain))))
62+
63+
(defn calculate-fiat-change
64+
[fiat-value change-pct-24hour]
65+
(money/bignumber (* fiat-value (/ change-pct-24hour (+ 100 change-pct-24hour)))))

src/status_im2/subs/wallet/wallet.cljs

+26
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,29 @@
9999
:<- [:wallet/current-viewing-account-address]
100100
(fn [[accounts current-viewing-account-address]]
101101
(remove #(= (:address %) current-viewing-account-address) accounts)))
102+
103+
(defn- calc-token-value
104+
[{:keys [market-values-per-currency] :as item} chain-id]
105+
(let [crypto-value (utils/token-value-in-chain item chain-id)
106+
market-values (:usd market-values-per-currency)
107+
{:keys [price change-pct-24hour]} market-values
108+
fiat-change (utils/calculate-fiat-change crypto-value change-pct-24hour)]
109+
(when crypto-value
110+
{:token (keyword (string/lower-case (:symbol item)))
111+
:state :default
112+
:status (cond
113+
(pos? change-pct-24hour) :positive
114+
(neg? change-pct-24hour) :negative
115+
:else :empty)
116+
:customization-color :blue
117+
:values {:crypto-value crypto-value
118+
:fiat-value (utils/prettify-balance (* crypto-value price))
119+
:percentage-change (.toFixed change-pct-24hour 2)
120+
:fiat-change (utils/prettify-balance fiat-change)}})))
121+
122+
(rf/reg-sub
123+
:wallet/account-token-values
124+
:<- [:wallet/current-viewing-account]
125+
:<- [:chain-id]
126+
(fn [[current-account chain-id]]
127+
(mapv #(calc-token-value % chain-id) (:tokens current-account))))

0 commit comments

Comments
 (0)