[fix 3821] fix update-price to only update visible tokens
This commit is contained in:
parent
dd65c44389
commit
d2811d6c45
|
@ -10,7 +10,6 @@
|
||||||
status-im.ui.screens.wallet.subs
|
status-im.ui.screens.wallet.subs
|
||||||
status-im.ui.screens.wallet.request.subs
|
status-im.ui.screens.wallet.request.subs
|
||||||
status-im.ui.screens.wallet.send.subs
|
status-im.ui.screens.wallet.send.subs
|
||||||
status-im.ui.screens.wallet.settings.subs
|
|
||||||
status-im.ui.screens.wallet.transactions.subs
|
status-im.ui.screens.wallet.transactions.subs
|
||||||
status-im.ui.screens.network-settings.subs
|
status-im.ui.screens.network-settings.subs
|
||||||
status-im.ui.screens.offline-messaging-settings.subs
|
status-im.ui.screens.offline-messaging-settings.subs
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
:request :wallet.request/set-symbol
|
:request :wallet.request/set-symbol
|
||||||
(throw (str "Unknown type: " k))))
|
(throw (str "Unknown type: " k))))
|
||||||
|
|
||||||
(defn- render-token [{:keys [symbol name icon decimals]} balance type]
|
(defn- render-token [{:keys [symbol name icon decimals amount]} type]
|
||||||
[list/touchable-item #(do (re-frame/dispatch [(type->handler type) symbol])
|
[list/touchable-item #(do (re-frame/dispatch [(type->handler type) symbol])
|
||||||
(re-frame/dispatch [:navigate-back]))
|
(re-frame/dispatch [:navigate-back]))
|
||||||
[react/view
|
[react/view
|
||||||
|
@ -49,19 +49,17 @@
|
||||||
name]
|
name]
|
||||||
[react/text {:force-uppercase? true}
|
[react/text {:force-uppercase? true}
|
||||||
(clojure.core/name symbol)]]
|
(clojure.core/name symbol)]]
|
||||||
[list/item-secondary (wallet.utils/format-amount (symbol balance) decimals)]]]]])
|
[list/item-secondary (wallet.utils/format-amount amount decimals)]]]]])
|
||||||
|
|
||||||
(views/defview assets [type]
|
(views/defview assets [type]
|
||||||
(views/letsubs [network [:network]
|
(views/letsubs [assets [:wallet/visible-assets-with-amount]]
|
||||||
visible-tokens [:wallet.settings/visible-tokens]
|
|
||||||
balance [:balance]]
|
|
||||||
[components/simple-screen
|
[components/simple-screen
|
||||||
[components/toolbar (i18n/label :t/wallet-assets)]
|
[components/toolbar (i18n/label :t/wallet-assets)]
|
||||||
[react/view {:style (assoc components.styles/flex :background-color :white)}
|
[react/view {:style (assoc components.styles/flex :background-color :white)}
|
||||||
[list/flat-list {:default-separator? true
|
[list/flat-list {:default-separator? true
|
||||||
:data (concat [tokens/ethereum] (wallet/current-tokens visible-tokens network))
|
:data assets
|
||||||
:key-fn (comp str :symbol)
|
:key-fn (comp str :symbol)
|
||||||
:render-fn #(render-token % balance type)}]]]))
|
:render-fn #(render-token % type)}]]]))
|
||||||
|
|
||||||
(defn send-assets []
|
(defn send-assets []
|
||||||
[assets :send])
|
[assets :send])
|
||||||
|
|
|
@ -91,10 +91,11 @@
|
||||||
(ethereum/estimate-gas-web3 web3 (clj->js obj) #(re-frame/dispatch [success-event %2]))))
|
(ethereum/estimate-gas-web3 web3 (clj->js obj) #(re-frame/dispatch [success-event %2]))))
|
||||||
|
|
||||||
;; Handlers
|
;; Handlers
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:update-wallet
|
:update-wallet
|
||||||
(fn [{{:keys [web3 accounts/current-account-id network network-status] :as db} :db} [_ symbols]]
|
(fn [{{:keys [web3 accounts/current-account-id network network-status] :as db} :db} _]
|
||||||
|
(let [chain (ethereum/network->chain-keyword network)
|
||||||
|
symbols (get-in db [:accounts/accounts current-account-id :settings :wallet :visible-tokens chain])]
|
||||||
(when (not= network-status :offline)
|
(when (not= network-status :offline)
|
||||||
{:get-balance {:web3 web3
|
{:get-balance {:web3 web3
|
||||||
:account-id current-account-id
|
:account-id current-account-id
|
||||||
|
@ -103,7 +104,7 @@
|
||||||
:get-tokens-balance {:web3 web3
|
:get-tokens-balance {:web3 web3
|
||||||
:account-id current-account-id
|
:account-id current-account-id
|
||||||
:symbols symbols
|
:symbols symbols
|
||||||
:chain (ethereum/network->chain-keyword network)
|
:chain chain
|
||||||
:success-event :update-token-balance-success
|
:success-event :update-token-balance-success
|
||||||
:error-event :update-token-balance-fail}
|
:error-event :update-token-balance-fail}
|
||||||
:get-prices {:from "ETH"
|
:get-prices {:from "ETH"
|
||||||
|
@ -114,7 +115,7 @@
|
||||||
(clear-error-message :prices-update)
|
(clear-error-message :prices-update)
|
||||||
(clear-error-message :balance-update)
|
(clear-error-message :balance-update)
|
||||||
(assoc-in [:wallet :balance-loading?] true)
|
(assoc-in [:wallet :balance-loading?] true)
|
||||||
(assoc :prices-loading? true))})))
|
(assoc :prices-loading? true))}))))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:update-transactions
|
:update-transactions
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
(defmethod navigation/preload-data! :wallet
|
(defmethod navigation/preload-data! :wallet
|
||||||
[db _]
|
[db _]
|
||||||
(re-frame/dispatch [:update-wallet (map :symbol (tokens/tokens-for (ethereum/network->chain-keyword (:network db))))])
|
(re-frame/dispatch [:update-wallet])
|
||||||
(assoc-in db [:wallet :current-tab] 0))
|
(assoc-in db [:wallet :current-tab] 0))
|
||||||
|
|
||||||
(defmethod navigation/preload-data! :transactions-history
|
(defmethod navigation/preload-data! :transactions-history
|
||||||
|
|
|
@ -124,7 +124,7 @@
|
||||||
(if sending-from-bot-or-dapp?
|
(if sending-from-bot-or-dapp?
|
||||||
;;SENDING FROM BOT (CHAT) OR DAPP
|
;;SENDING FROM BOT (CHAT) OR DAPP
|
||||||
{:db (assoc-in new-db [:wallet :send-transaction] sending-db) ; we need to completely reset sending state here
|
{:db (assoc-in new-db [:wallet :send-transaction] sending-db) ; we need to completely reset sending state here
|
||||||
:dispatch-n [[:update-wallet (map :symbol (tokens/tokens-for (ethereum/network->chain-keyword (:network db))))]
|
:dispatch-n [[:update-wallet]
|
||||||
[:navigate-to-modal :wallet-send-transaction-modal]
|
[:navigate-to-modal :wallet-send-transaction-modal]
|
||||||
(when-not (seq gas)
|
(when-not (seq gas)
|
||||||
[:wallet/update-estimated-gas transaction])
|
[:wallet/update-estimated-gas transaction])
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
(ns status-im.ui.screens.wallet.settings.subs
|
|
||||||
(:require [re-frame.core :as re-frame]
|
|
||||||
[status-im.utils.ethereum.core :as ethereum]))
|
|
||||||
|
|
||||||
;; A set of visible-tokens for current network
|
|
||||||
(re-frame/reg-sub :wallet.settings/visible-tokens
|
|
||||||
:<- [:network]
|
|
||||||
:<- [:get-current-account]
|
|
||||||
(fn [[network current-account]]
|
|
||||||
(let [chain (ethereum/network->chain-keyword network)]
|
|
||||||
(get-in current-account [:settings :wallet :visible-tokens chain]))))
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
(defview manage-assets []
|
(defview manage-assets []
|
||||||
(letsubs [network [:network]
|
(letsubs [network [:network]
|
||||||
visible-tokens [:wallet.settings/visible-tokens]]
|
visible-tokens [:wallet/visible-tokens-symbols]]
|
||||||
[react/view (merge components.styles/flex {:background-color :white})
|
[react/view (merge components.styles/flex {:background-color :white})
|
||||||
[status-bar/status-bar {:type :modal-wallet}]
|
[status-bar/status-bar {:type :modal-wallet}]
|
||||||
[toolbar/toolbar #_{} {:style wallet.styles/toolbar}
|
[toolbar/toolbar #_{} {:style wallet.styles/toolbar}
|
||||||
|
|
|
@ -1,25 +1,27 @@
|
||||||
(ns status-im.ui.screens.wallet.subs
|
(ns status-im.ui.screens.wallet.subs
|
||||||
(:require [re-frame.core :refer [reg-sub subscribe]]
|
(:require [re-frame.core :as re-frame]
|
||||||
[status-im.utils.money :as money]))
|
[status-im.utils.money :as money]
|
||||||
|
[status-im.utils.ethereum.core :as ethereum]
|
||||||
|
[status-im.utils.ethereum.tokens :as tokens]))
|
||||||
|
|
||||||
(reg-sub :wallet
|
(re-frame/reg-sub :wallet
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(:wallet db)))
|
(:wallet db)))
|
||||||
|
|
||||||
(reg-sub :balance
|
(re-frame/reg-sub :balance
|
||||||
:<- [:wallet]
|
:<- [:wallet]
|
||||||
(fn [wallet]
|
(fn [wallet]
|
||||||
(:balance wallet)))
|
(:balance wallet)))
|
||||||
|
|
||||||
(reg-sub :price
|
(re-frame/reg-sub :price
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(get-in db [:prices :price])))
|
(get-in db [:prices :price])))
|
||||||
|
|
||||||
(reg-sub :last-day
|
(re-frame/reg-sub :last-day
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(get-in db [:prices :last-day])))
|
(get-in db [:prices :last-day])))
|
||||||
|
|
||||||
(reg-sub :portfolio-value
|
(re-frame/reg-sub :portfolio-value
|
||||||
:<- [:balance]
|
:<- [:balance]
|
||||||
:<- [:price]
|
:<- [:price]
|
||||||
(fn [[balance price]]
|
(fn [[balance price]]
|
||||||
|
@ -30,21 +32,42 @@
|
||||||
str)
|
str)
|
||||||
"...")))
|
"...")))
|
||||||
|
|
||||||
(reg-sub :prices-loading?
|
(re-frame/reg-sub :prices-loading?
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(:prices-loading? db)))
|
(:prices-loading? db)))
|
||||||
|
|
||||||
(reg-sub :wallet/balance-loading?
|
(re-frame/reg-sub :wallet/balance-loading?
|
||||||
:<- [:wallet]
|
:<- [:wallet]
|
||||||
(fn [wallet]
|
(fn [wallet]
|
||||||
(:balance-loading? wallet)))
|
(:balance-loading? wallet)))
|
||||||
|
|
||||||
(reg-sub :wallet/error-message?
|
(re-frame/reg-sub :wallet/error-message?
|
||||||
:<- [:wallet]
|
:<- [:wallet]
|
||||||
(fn [wallet]
|
(fn [wallet]
|
||||||
(or (get-in wallet [:errors :balance-update])
|
(or (get-in wallet [:errors :balance-update])
|
||||||
(get-in wallet [:errors :prices-update]))))
|
(get-in wallet [:errors :prices-update]))))
|
||||||
|
|
||||||
(reg-sub :get-wallet-unread-messages-number
|
(re-frame/reg-sub :get-wallet-unread-messages-number
|
||||||
(fn [db]
|
(fn [db]
|
||||||
0))
|
0))
|
||||||
|
|
||||||
|
(re-frame/reg-sub :wallet/visible-tokens-symbols
|
||||||
|
:<- [:network]
|
||||||
|
:<- [:get-current-account]
|
||||||
|
(fn [[network current-account]]
|
||||||
|
(let [chain (ethereum/network->chain-keyword network)]
|
||||||
|
(get-in current-account [:settings :wallet :visible-tokens chain]))))
|
||||||
|
|
||||||
|
(re-frame/reg-sub :wallet/visible-assets
|
||||||
|
:<- [:network]
|
||||||
|
:<- [:wallet/visible-tokens-symbols]
|
||||||
|
(fn [[network visible-tokens-symbols]]
|
||||||
|
(conj (filter #(contains? visible-tokens-symbols (:symbol %))
|
||||||
|
(tokens/tokens-for (ethereum/network->chain-keyword network)))
|
||||||
|
tokens/ethereum)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub :wallet/visible-assets-with-amount
|
||||||
|
:<- [:balance]
|
||||||
|
:<- [:wallet/visible-assets]
|
||||||
|
(fn [[balance visible-assets]]
|
||||||
|
(map #(assoc % :amount (get balance (:symbol %))) visible-assets)))
|
||||||
|
|
|
@ -63,12 +63,9 @@
|
||||||
:number-of-lines 1}
|
:number-of-lines 1}
|
||||||
(clojure.core/name symbol)]]]])
|
(clojure.core/name symbol)]]]])
|
||||||
|
|
||||||
(defn current-tokens [visible-tokens network]
|
|
||||||
(filter #(contains? visible-tokens (:symbol %)) (tokens/tokens-for (ethereum/network->chain-keyword network))))
|
|
||||||
|
|
||||||
(defn- asset-section [network balance visible-tokens]
|
|
||||||
(let [tokens (current-tokens visible-tokens network)
|
(defn- asset-section [assets]
|
||||||
assets (map #(assoc % :amount (get balance (:symbol %))) (concat [tokens/ethereum] tokens))]
|
|
||||||
[react/view styles/asset-section
|
[react/view styles/asset-section
|
||||||
[react/text {:style styles/asset-section-title} (i18n/label :t/wallet-assets)]
|
[react/text {:style styles/asset-section-title} (i18n/label :t/wallet-assets)]
|
||||||
[list/flat-list
|
[list/flat-list
|
||||||
|
@ -76,24 +73,21 @@
|
||||||
:scroll-enabled false
|
:scroll-enabled false
|
||||||
:key-fn (comp str :symbol)
|
:key-fn (comp str :symbol)
|
||||||
:data assets
|
:data assets
|
||||||
:render-fn render-asset}]]))
|
:render-fn render-asset}]])
|
||||||
|
|
||||||
(views/defview wallet []
|
(views/defview wallet []
|
||||||
(views/letsubs [network [:network]
|
(views/letsubs [assets [:wallet/visible-assets-with-amount]
|
||||||
balance [:balance]
|
|
||||||
visible-tokens [:wallet.settings/visible-tokens]
|
|
||||||
portfolio-value [:portfolio-value]]
|
portfolio-value [:portfolio-value]]
|
||||||
(let [symbols (map :symbol (current-tokens visible-tokens network))]
|
|
||||||
[react/view styles/main-section
|
[react/view styles/main-section
|
||||||
[toolbar-view]
|
[toolbar-view]
|
||||||
[react/scroll-view {:content-container-style styles/scrollable-section
|
[react/scroll-view {:content-container-style styles/scrollable-section
|
||||||
:refresh-control
|
:refresh-control
|
||||||
(reagent/as-element
|
(reagent/as-element
|
||||||
[react/refresh-control {:on-refresh #(re-frame/dispatch [:update-wallet symbols])
|
[react/refresh-control {:on-refresh #(re-frame/dispatch [:update-wallet])
|
||||||
:tint-color :white
|
:tint-color :white
|
||||||
:refreshing false}])}
|
:refreshing false}])}
|
||||||
[react/view {:style styles/scroll-top}] ;; Hack to allow different colors for top / bottom scroll view]
|
[react/view {:style styles/scroll-top}] ;; Hack to allow different colors for top / bottom scroll view]
|
||||||
[total-section portfolio-value]
|
[total-section portfolio-value]
|
||||||
[list/action-list actions
|
[list/action-list actions
|
||||||
{:container-style styles/action-section}]
|
{:container-style styles/action-section}]
|
||||||
[asset-section network balance visible-tokens]]])))
|
[asset-section assets]]]))
|
||||||
|
|
Loading…
Reference in New Issue