Skip to content

Commit

Permalink
[Feature] Wallet - Network based assets and fiat balance calculation
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Javid <19339952+smohamedjavid@users.noreply.github.com>
  • Loading branch information
smohamedjavid committed Mar 13, 2024
1 parent eb37979 commit 06e697e
Show file tree
Hide file tree
Showing 33 changed files with 611 additions and 299 deletions.
Binary file added resources/images/tokens/mainnet/STT.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/tokens/mainnet/STT@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/tokens/mainnet/STT@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/quo/foundations/colors.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@
;;;; Networks
(def ^:private networks
{:ethereum "#758EEB"
:mainnet "#758EEB"
:optimism "#E76E6E"
:arbitrum "#6BD5F0"
:zkSync "#9FA0FE"
Expand Down
2 changes: 2 additions & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@

(def ^:const default-network-names #{mainnet-network-name optimism-network-name arbitrum-network-name})

(def ^:const default-network-count (count default-network-names))

(def ^:const chain-id-separator ":")

(def ^:const account-default-customization-color :blue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
(assoc :test-ID stack-id
:icon icon
:icon-color-anim icon-color
:on-press #(animation/bottom-tab-on-press stack-id true)
:on-press (fn []
(when-not (= stack-id :wallet-stack)
(rf/dispatch [:wallet/reset-selected-networks]))
(animation/bottom-tab-on-press stack-id true))
:accessibility-label (str (name stack-id) "-tab")
:customization-color customization-color))]))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[status-im.contexts.shell.jump-to.constants :as shell.constants]
[status-im.contexts.shell.jump-to.state :as state]
[status-im.contexts.shell.jump-to.utils :as utils]
[status-im.contexts.wallet.home.view :as wallet-new]
[status-im.contexts.wallet.home.view :as wallet]
[utils.re-frame :as rf]))

(defn load-stack?
Expand All @@ -32,7 +32,7 @@
(case stack-id
:communities-stack [:f> communities/view]
:chats-stack [:f> chat/view]
:wallet-stack [wallet-new/view]
:wallet-stack [wallet/view]
:browser-stack [browser.stack/browser-stack]
[:<>])])

Expand Down
22 changes: 11 additions & 11 deletions src/status_im/contexts/wallet/account/bridge_to/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
(defn- bridge-token-component
[]
(fn [{:keys [chain-id network-name]} token]
(let [network (rf/sub [:wallet/network-details-by-chain-id chain-id])
currency (rf/sub [:profile/currency])
currency-symbol (rf/sub [:profile/currency-symbol])
all-balances (:balances-per-chain token)
balance-for-chain (utils/get-balance-for-chain all-balances chain-id)
crypto-formatted (or (:balance balance-for-chain) "0.00")
fiat-value (utils/token-fiat-value currency
(or (:balance balance-for-chain) 0)
token)
fiat-formatted (utils/get-standard-fiat-format crypto-formatted currency-symbol fiat-value)]
(let [network (rf/sub [:wallet/network-details-by-chain-id chain-id])
currency (rf/sub [:profile/currency])
currency-symbol (rf/sub [:profile/currency-symbol])
balance (utils/calculate-total-token-balance token [chain-id])
crypto-value (utils/get-standard-crypto-format token balance)
fiat-value (utils/calculate-token-fiat-value
{:currency currency
:balance balance
:token token})
fiat-formatted (utils/get-standard-fiat-format crypto-value currency-symbol fiat-value)]
[quo/network-list
{:label (name network-name)
:network-image (quo.resources/get-network (:network-name network))
:token-value (str crypto-formatted " " (:symbol token))
:token-value (str crypto-value " " (:symbol token))
:fiat-value fiat-formatted
:on-press #(rf/dispatch [:wallet/select-bridge-network
{:network-chain-id chain-id
Expand Down
6 changes: 4 additions & 2 deletions src/status_im/contexts/wallet/account/tabs/assets/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

(defn view
[]
(let [tokens-loading? (rf/sub [:wallet/tokens-loading?])
tokens (rf/sub [:wallet/account-token-values])]
(let [tokens-loading? (rf/sub [:wallet/tokens-loading?])
tokens (rf/sub [:wallet/current-viewing-account-token-values])
{:keys [watch-only?]} (rf/sub [:wallet/current-viewing-account])]
(if tokens-loading?
[quo/skeleton-list
{:content :assets
Expand All @@ -18,4 +19,5 @@
{:render-fn token-value/view
:style {:flex 1}
:data tokens
:render-data {:watch-only? watch-only?}
:content-container-style {:padding-horizontal 8}}])))
2 changes: 1 addition & 1 deletion src/status_im/contexts/wallet/account/tabs/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

(defn view
[{:keys [selected-tab]}]
(let [collectible-list (rf/sub [:wallet/current-viewing-account-collectibles])]
(let [collectible-list (rf/sub [:wallet/current-viewing-account-collectibles-in-selected-networks])]
[rn/view {:style {:flex 1}}
(case selected-tab
:assets [assets/view]
Expand Down
19 changes: 8 additions & 11 deletions src/status_im/contexts/wallet/common/account_switcher/view.cljs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
(ns status-im.contexts.wallet.common.account-switcher.view
(:require [quo.core :as quo]
[status-im.contexts.wallet.sheets.account-options.view :as account-options]
[status-im.contexts.wallet.sheets.network-filter.view :as network-filter]
[status-im.contexts.wallet.sheets.select-account.view :as select-account]
[status-im.feature-flags :as ff]
[utils.re-frame :as rf]))
(:require
[quo.core :as quo]
[status-im.contexts.wallet.sheets.account-options.view :as account-options]
[status-im.contexts.wallet.sheets.network-filter.view :as network-filter]
[status-im.contexts.wallet.sheets.select-account.view :as select-account]
[utils.re-frame :as rf]))

(defn get-bottom-sheet-args
[switcher-type]
Expand All @@ -20,7 +20,7 @@
accessibility-label :top-bar
switcher-type :account-options}}]
(let [{:keys [color emoji watch-only?]} (rf/sub [:wallet/current-viewing-account])
networks (rf/sub [:wallet/network-details])]
networks (rf/sub [:wallet/selected-network-details])]
[quo/page-nav
{:type (or type :no-title)
:icon-name icon-name
Expand All @@ -29,10 +29,7 @@
:on-press on-press
:accessibility-label accessibility-label
:networks networks
:networks-on-press #(ff/alert ::ff/wallet.network-filter
(fn []
(rf/dispatch [:show-bottom-sheet
{:content network-filter/view}])))
:networks-on-press #(rf/dispatch [:show-bottom-sheet {:content network-filter/view}])
:right-side :account-switcher
:account-switcher {:customization-color color
:on-press #(rf/dispatch [:show-bottom-sheet
Expand Down
12 changes: 7 additions & 5 deletions src/status_im/contexts/wallet/common/asset_list/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
[utils.re-frame :as rf]))

(defn- asset-component
[token _ _ {:keys [currency currency-symbol on-token-press]}]
(let [token-units (utils/total-token-units-in-all-chains token)
crypto-formatted (utils/get-standard-crypto-format token token-units)
fiat-value (utils/total-token-fiat-value currency token)
[{:keys [total-balance] :as token} _ _ {:keys [currency currency-symbol on-token-press]}]
(let [fiat-value (utils/calculate-token-fiat-value
{:currency currency
:balance total-balance
:token token})
crypto-formatted (utils/get-standard-crypto-format token total-balance)
fiat-formatted (utils/get-standard-fiat-format crypto-formatted currency-symbol fiat-value)]
[quo/token-network
{:token (:symbol token)
Expand All @@ -21,7 +23,7 @@

(defn view
[{:keys [search-text on-token-press]}]
(let [filtered-tokens (rf/sub [:wallet/tokens-filtered search-text])
(let [filtered-tokens (rf/sub [:wallet/current-viewing-account-tokens-filtered search-text])
currency (rf/sub [:profile/currency])
currency-symbol (rf/sub [:profile/currency-symbol])]
[rn/flat-list
Expand Down
34 changes: 0 additions & 34 deletions src/status_im/contexts/wallet/common/temp.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,3 @@
:image :icon-avatar
:image-props {:icon (status.resources/get-service-image :latamex)}
:on-press #(rn/open-url "https://latamex.com")}])

(defn bridge-token-list
[networks-list]
[{:token :snt
:name "Status"
:token-value "0.00 SNT"
:fiat-value "€0.00"
:networks networks-list
:state :default
:symbol "STT"
:customization-color :blue}
{:token :eth
:name "Ethereum"
:token-value "0.00 ETH"
:fiat-value "€0.00"
:networks networks-list
:state :default
:symbol "ETH"
:customization-color :blue}
{:token :dai
:name "Dai"
:token-value "0.00 DAI"
:fiat-value "€0.00"
:networks networks-list
:state :default
:symbol "DAI"
:customization-color :blue}])

(def secret-phrase
["witch" "collapse" "practice" "feed" "shame" "open" "lion"
"collapse" "umbrella" "fabric" "sadness" "obligue"])
(def random-words
["cousin" "roof" "minute" "swallow" "wing" "motion" "stomach"
"abuse" "banner" "noble" "poet" "wrist"])
21 changes: 10 additions & 11 deletions src/status_im/contexts/wallet/common/token_value/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

(defn token-value-drawer
[token]
(let [token-data (first (rf/sub [:wallet/tokens-filtered (:token token)]))]
(let [token-data (first (rf/sub [:wallet/current-viewing-account-tokens-filtered (:token token)]))]
[:<>
[quo/action-drawer
[[{:icon :i/buy
Expand Down Expand Up @@ -40,13 +40,12 @@
:on-press #(js/alert "to be implemented")}]]]]))

(defn view
[item]
(let [{:keys [watch-only?]} (rf/sub [:wallet/current-viewing-account])]
[quo/token-value
(cond-> item
(not watch-only?)
(assoc :on-long-press
#(rf/dispatch
[:show-bottom-sheet
{:content (fn [] [token-value-drawer item])
:selected-item (fn [] [quo/token-value item])}])))]))
[item _ _ {:keys [watch-only?]}]
[quo/token-value
(cond-> item
(not watch-only?)
(assoc :on-long-press
#(rf/dispatch
[:show-bottom-sheet
{:content (fn [] [token-value-drawer item])
:selected-item (fn [] [quo/token-value item])}])))])
Loading

0 comments on commit 06e697e

Please sign in to comment.