Skip to content

Commit

Permalink
Merge branch 'develop' into 17023-share-qr-code-variants
Browse files Browse the repository at this point in the history
  • Loading branch information
ulisesmac authored Oct 31, 2023
2 parents ea538bf + ca822ff commit 644544e
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 69 deletions.
1 change: 1 addition & 0 deletions src/status_im2/contexts/profile/login/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
{:db (assoc db
:chats/loading? true
:networks/current-network current-network
:wallet/tokens-loading? true
:networks/networks (merge networks config/default-networks-by-id)
:profile/profile (merge profile settings))}
(notifications/load-preferences)
Expand Down
3 changes: 3 additions & 0 deletions src/status_im2/contexts/wallet/account/style.cljs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
(ns status-im2.contexts.wallet.account.style)

(def container
{:flex 1})

(def tabs
{:padding-left 20
:padding-vertical 12})
Expand Down
21 changes: 12 additions & 9 deletions src/status_im2/contexts/wallet/account/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
(:require
[quo.core :as quo]
[react-native.core :as rn]
[react-native.safe-area :as safe-area]
[reagent.core :as reagent]
[status-im2.contexts.wallet.account.style :as style]
[status-im2.contexts.wallet.account.tabs.view :as tabs]
[status-im2.contexts.wallet.common.temp :as temp]
[status-im2.contexts.wallet.common.utils :as utils]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

Expand Down Expand Up @@ -57,14 +57,13 @@
{:id :about :label (i18n/label :t/about) :accessibility-label :about}])

(defn view
[]
(let [top (safe-area/get-top)
selected-tab (reagent/atom (:id (first tabs-data)))]
[account-address]
(let [selected-tab (reagent/atom (:id (first tabs-data)))]
(fn []
(let [networks (rf/sub [:wallet/network-details])]
[rn/view
{:style {:flex 1
:margin-top top}}
(let [account-address (or account-address (rf/sub [:get-screen-params :wallet-accounts]))
account (rf/sub [:wallet/account account-address])
networks (rf/sub [:wallet/network-details])]
[rn/view {:style style/container}
[quo/page-nav
{:type :wallet-networks
:background :blur
Expand All @@ -79,7 +78,11 @@
:gradient-cover? true
:customization-color :purple}])
:emoji "🍑"}}]
[quo/account-overview temp/account-overview-state]
[quo/account-overview
{:current-value (utils/prettify-balance (:balance account))
:account-name (:name account)
:account :default
:customization-color :blue}]
[quo/wallet-graph {:time-frame :empty}]
[quo/wallet-ctas
{:send-action #(rf/dispatch [:open-modal :wallet-select-address])
Expand Down
15 changes: 15 additions & 0 deletions src/status_im2/contexts/wallet/common/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@
[full-name]
(first (string/split full-name #" ")))

(defn get-balance-by-address
[balances address]
(->> balances
(filter #(= (:address %) address))
first
:balance))

(defn get-account-by-address
[accounts address]
(some #(when (= (:address %) address) %) accounts))

(defn prettify-balance
[balance]
(str "$" (.toFixed (if (number? balance) balance 0) 2)))

(defn get-derivation-path
[number-of-accounts]
(str constants/path-wallet-root "/" number-of-accounts))
20 changes: 20 additions & 0 deletions src/status_im2/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
[utils.re-frame :as rf]
[utils.security.core :as security]))

(rf/defn get-wallet-token
{:events [:wallet/get-wallet-token]}
[{:keys [db]}]
(let [params (map :address (:profile/wallet-accounts db))]
{:json-rpc/call [{:method "wallet_getWalletToken"
:params [params]
:on-success #(rf/dispatch [:wallet/get-wallet-token-success %])
:on-error (fn [error]
(log/info "failed to get wallet token"
{:event :wallet/get-wallet-token
:error error
:params params}))}]}))

(rf/defn get-wallet-token-success
{:events [:wallet/get-wallet-token-success]}
[{:keys [db]} data]
{:db (assoc db
:wallet/tokens data
:wallet/tokens-loading? false)})

(rf/defn scan-address-success
{:events [:wallet/scan-address-success]}
[{:keys [db]} address]
Expand Down
110 changes: 62 additions & 48 deletions src/status_im2/contexts/wallet/home/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[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.temp :as temp]
[status-im2.contexts.wallet.common.token-value.view :as token-value]
[status-im2.contexts.wallet.common.utils :as utils]
[status-im2.contexts.wallet.home.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
Expand All @@ -28,58 +28,72 @@
:on-press #(rf/dispatch [:navigate-to :wallet-address-watch])
:add-divider? true}]]])

(def account-cards
[{:name "Account 1"
:balance "€0.00"
:percentage-value "€0.00"
:customization-color :blue
:type :empty
:emoji "🍑"
:on-press #(rf/dispatch [:navigate-to :wallet-accounts])}
{:customization-color :blue
:on-press #(rf/dispatch
[:show-bottom-sheet {:content new-account}])
:type :add-account}])
(defn- add-account-placeholder
[color]
{:customization-color color
:on-press #(rf/dispatch [:show-bottom-sheet {:content new-account}])
:type :add-account})

(def tabs-data
[{:id :assets :label (i18n/label :t/assets) :accessibility-label :assets-tab}
{:id :collectibles :label (i18n/label :t/collectibles) :accessibility-label :collectibles-tab}
{:id :activity :label (i18n/label :t/activity) :accessibility-label :activity-tab}])

(defn account-cards
[{:keys [accounts loading? balances profile]}]
(let [accounts-with-balances
(mapv
(fn [account]
(assoc account
:type :empty
:customization-color (:customization-color profile)
:on-press #(rf/dispatch [:navigate-to :wallet-accounts (:address account)])
:loading? loading?
:balance (utils/prettify-balance
(utils/get-balance-by-address balances (:address account)))))
accounts)]
(conj accounts-with-balances (add-account-placeholder (:customization-color profile)))))

(defn view
[]
(let [top (safe-area/get-top)
selected-tab (reagent/atom (:id (first tabs-data)))]
(fn []
(let [networks (rf/sub [:wallet/network-details])]
[rn/view
{:style {:margin-top top
:flex 1}}
[common.top-nav/view]
[rn/view {:style style/overview-container}
[quo/wallet-overview (temp/wallet-overview-state networks)]]
[rn/pressable
{:on-long-press #(rf/dispatch [:show-bottom-sheet
{:content temp/wallet-temporary-navigation}])}
[quo/wallet-graph {:time-frame :empty}]]
[rn/view {:style style/accounts-container}
[rn/flat-list
{:style style/accounts-list
:data account-cards
:horizontal true
:separator [rn/view {:style {:width 12}}]
:render-fn quo/account-card}]]
[quo/tabs
{:style style/tabs
:size 32
:default-active @selected-tab
:data tabs-data
:on-change #(reset! selected-tab %)}]
(case @selected-tab
:assets [rn/flat-list
{:render-fn token-value/view
:data temp/tokens
:key :assets-list
:content-container-style {:padding-horizontal 8}}]
:collectibles [collectibles/view]
[activity/view])]))))
(rf/dispatch [:wallet/get-wallet-token])
(fn []
(let [accounts (rf/sub [:profile/wallet-accounts])
top (safe-area/get-top)
selected-tab (reagent/atom (:id (first tabs-data)))
loading? (rf/sub [:wallet/tokens-loading?])
balances (rf/sub [:wallet/balances])
profile (rf/sub [:profile/profile])
networks (rf/sub [:wallet/network-details])]
[rn/view
{:style {:margin-top top
:flex 1}}
[common.top-nav/view]
[rn/view {:style style/overview-container}
[quo/wallet-overview (temp/wallet-overview-state networks)]]
[rn/pressable
{:on-long-press #(rf/dispatch [:show-bottom-sheet {:content temp/wallet-temporary-navigation}])}
[quo/wallet-graph {:time-frame :empty}]]
[rn/flat-list
{:style style/accounts-list
:data (account-cards {:accounts accounts
:loading? loading?
:balances balances
:profile profile})
:horizontal true
:separator [rn/view {:style {:width 12}}]
:render-fn quo/account-card}]
[quo/tabs
{:style style/tabs
:size 32
:default-active @selected-tab
:data tabs-data
:on-change #(reset! selected-tab %)}]
(case @selected-tab
:assets [rn/flat-list
{:render-fn quo/token-value
:data temp/tokens
:key :assets-list
:content-container-style {:padding-horizontal 8}}]
:collectibles [collectibles/view]
[activity/view])])))
1 change: 1 addition & 0 deletions src/status_im2/navigation/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
:component emoji-picker/view}

{:name :wallet-accounts
:options {:insets {:top? true}}
:component wallet-accounts/view}

{:name :wallet-edit-account
Expand Down
7 changes: 6 additions & 1 deletion src/status_im2/subs/root.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
status-im2.subs.pairing
status-im2.subs.profile
status-im2.subs.shell
status-im2.subs.wallet.networks))
status-im2.subs.wallet.networks
status-im2.subs.wallet.wallet))

(defn reg-root-key-sub
[sub-name db-key]
Expand Down Expand Up @@ -142,6 +143,10 @@
(reg-root-key-sub :communities/selected-tab :communities/selected-tab)
(reg-root-key-sub :contract-communities :contract-communities)

;;wallet
(reg-root-key-sub :wallet/tokens :wallet/tokens)
(reg-root-key-sub :wallet/tokens-loading? :wallet/tokens-loading?)

;;activity center
(reg-root-key-sub :activity-center :activity-center)

Expand Down
51 changes: 51 additions & 0 deletions src/status_im2/subs/wallet/wallet.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
(ns status-im2.subs.wallet.wallet
(:require [clojure.string :as string]
[re-frame.core :as re-frame]
[status-im2.contexts.wallet.common.utils :as utils]
[utils.number]))

(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)))
0))

(defn- total-per-token
[item]
(reduce (fn [ac balances]
(+ (calculate-raw-balance (:rawBalance balances)
(:decimals item))
ac))
0
(vals (:balancesPerChain item))))

(defn- calculate-balance
[address tokens]
(let [token (get tokens (keyword (string/lower-case address)))
result (reduce
(fn [acc item]
(let [total-values (* (total-per-token item)
(get-in item [:marketValuesPerCurrency :USD :price]))]
(+ acc total-values)))
0
token)]
result))

(re-frame/reg-sub
:wallet/balances
:<- [:profile/wallet-accounts]
:<- [:wallet/tokens]
(fn [[accounts tokens]]
(for [{:keys [address]} accounts]
{:address address
:balance (calculate-balance address tokens)})))

(re-frame/reg-sub
:wallet/account
:<- [:profile/wallet-accounts]
:<- [:wallet/balances]
(fn [[accounts balances] [_ account-address]]
(assoc
(utils/get-account-by-address accounts account-address)
:balance
(utils/get-balance-by-address balances account-address))))
Loading

0 comments on commit 644544e

Please sign in to comment.