[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,30 +91,31 @@
|
||||||
(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} _]
|
||||||
(when (not= network-status :offline)
|
(let [chain (ethereum/network->chain-keyword network)
|
||||||
{:get-balance {:web3 web3
|
symbols (get-in db [:accounts/accounts current-account-id :settings :wallet :visible-tokens chain])]
|
||||||
:account-id current-account-id
|
(when (not= network-status :offline)
|
||||||
:success-event :update-balance-success
|
{:get-balance {:web3 web3
|
||||||
:error-event :update-balance-fail}
|
:account-id current-account-id
|
||||||
:get-tokens-balance {:web3 web3
|
:success-event :update-balance-success
|
||||||
:account-id current-account-id
|
:error-event :update-balance-fail}
|
||||||
:symbols symbols
|
:get-tokens-balance {:web3 web3
|
||||||
:chain (ethereum/network->chain-keyword network)
|
:account-id current-account-id
|
||||||
:success-event :update-token-balance-success
|
:symbols symbols
|
||||||
:error-event :update-token-balance-fail}
|
:chain chain
|
||||||
:get-prices {:from "ETH"
|
:success-event :update-token-balance-success
|
||||||
:to "USD"
|
:error-event :update-token-balance-fail}
|
||||||
:success-event :update-prices-success
|
:get-prices {:from "ETH"
|
||||||
:error-event :update-prices-fail}
|
:to "USD"
|
||||||
:db (-> db
|
:success-event :update-prices-success
|
||||||
(clear-error-message :prices-update)
|
:error-event :update-prices-fail}
|
||||||
(clear-error-message :balance-update)
|
:db (-> db
|
||||||
(assoc-in [:wallet :balance-loading?] true)
|
(clear-error-message :prices-update)
|
||||||
(assoc :prices-loading? true))})))
|
(clear-error-message :balance-update)
|
||||||
|
(assoc-in [:wallet :balance-loading?] true)
|
||||||
|
(assoc :prices-loading? true))}))))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:update-transactions
|
:update-transactions
|
||||||
|
@ -241,4 +242,4 @@
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:wallet/show-error
|
:wallet/show-error
|
||||||
(fn []
|
(fn []
|
||||||
{:show-error (i18n/label :t/wallet-error)}))
|
{:show-error (i18n/label :t/wallet-error)}))
|
||||||
|
|
|
@ -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,37 +63,31 @@
|
||||||
: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
|
{:default-separator? true
|
||||||
{:default-separator? true
|
: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])
|
||||||
[react/refresh-control {:on-refresh #(re-frame/dispatch [:update-wallet symbols])
|
: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 assets]]]))
|
||||||
[asset-section network balance visible-tokens]]])))
|
|
||||||
|
|
Loading…
Reference in New Issue