Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Wallet - Network based assets and fiat balance calculation #19150

Merged
merged 5 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
4 changes: 3 additions & 1 deletion src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,9 @@
(def ^:const optimism-network-name :optimism)
(def ^:const arbitrum-network-name :arbitrum)

(def ^:const default-network-names #{mainnet-network-name optimism-network-name arbitrum-network-name})
(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 ":")

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
2 changes: 1 addition & 1 deletion src/status_im/contexts/shell/share/profile/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
:on-text-long-press #(rf/dispatch [:share/copy-text-and-show-toast
{:text-to-copy universal-profile-url
:post-copy-message (i18n/label :t/link-to-profile-copied)}])
:profile-picture (:uri (profile.utils/photo profile))
:profile-picture (profile.utils/photo profile)
:full-name (profile.utils/displayed-name profile)
:customization-color customization-color}]]

Expand Down
34 changes: 19 additions & 15 deletions src/status_im/contexts/shell/share/wallet/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[react-native.platform :as platform]
[react-native.share :as share]
[reagent.core :as reagent]
[status-im.constants :as constants]
[status-im.contexts.shell.share.style :as style]
[status-im.contexts.shell.share.wallet.style :as wallet-style]
[status-im.contexts.wallet.common.utils :as utils]
Expand Down Expand Up @@ -33,25 +34,28 @@
:isNewTask true})))

(defn- open-preferences
[selected-networks]
(rf/dispatch [:show-bottom-sheet
{:theme :dark
:shell? true
:content
(fn []
[network-preferences/view
{:blur? true
:selected-networks (set @selected-networks)
:on-save (fn [chain-ids]
(rf/dispatch [:hide-bottom-sheet])
(reset! selected-networks (map #(get utils/id->network %)
chain-ids)))}])}]))
[selected-networks account]
(rf/dispatch
[:show-bottom-sheet
{:theme :dark
:shell? true
:content (fn []
[network-preferences/view
{:blur? true
:selected-networks (set @selected-networks)
:account account
:button-label (i18n/label :t/display)
:on-save (fn [chain-ids]
(rf/dispatch [:hide-bottom-sheet])
(reset! selected-networks (map #(get utils/id->network %)
chain-ids)))}])}]))

(defn- wallet-qr-code-item
[{:keys [account index]}]
(let [{window-width :width} (rn/get-window)
selected-networks (reagent/atom [:ethereum :optimism :arbitrum])
selected-networks (reagent/atom constants/default-network-names)
wallet-type (reagent/atom :legacy)
on-settings-press #(open-preferences selected-networks)
on-settings-press #(open-preferences selected-networks account)
on-legacy-press #(reset! wallet-type :legacy)
on-multichain-press #(reset! wallet-type :multichain)]
(fn []
Expand Down
9 changes: 5 additions & 4 deletions src/status_im/contexts/wallet/account/share_address/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[react-native.safe-area :as safe-area]
[react-native.share :as share]
[reagent.core :as reagent]
[status-im.constants :as constants]
[status-im.contexts.wallet.account.share-address.style :as style]
[status-im.contexts.wallet.common.utils :as utils]
[status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences]
Expand Down Expand Up @@ -34,13 +35,13 @@
[selected-networks]
(let [on-save (fn [chain-ids]
(rf/dispatch [:hide-bottom-sheet])
(reset! selected-networks (map #(if (= % 1) :mainnet (utils/id->network %))
chain-ids)))
(reset! selected-networks (map utils/id->network chain-ids)))
sheet-content (fn []
[network-preferences/view
{:blur? true
:selected-networks (set @selected-networks)
:on-save on-save}])]
:on-save on-save
:button-label (i18n/label :t/display)}])]
(rf/dispatch [:show-bottom-sheet
{:theme :dark
:shell? true
Expand All @@ -53,7 +54,7 @@
wallet-type (reagent/atom :legacy)
;; Design team is yet to confirm the default selected networks here. Should be the current
;; selected for the account or all the networks always
selected-networks (reagent/atom [:mainnet :optimism :arbitrum])
selected-networks (reagent/atom constants/default-network-names)
on-settings-press #(open-preferences selected-networks)
on-legacy-press #(reset! wallet-type :legacy)
on-multichain-press #(reset! wallet-type :multichain)]
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
22 changes: 11 additions & 11 deletions src/status_im/contexts/wallet/bridge/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
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 @@ -41,13 +41,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