[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.request.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.network-settings.subs
|
||||
status-im.ui.screens.offline-messaging-settings.subs
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
:request :wallet.request/set-symbol
|
||||
(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])
|
||||
(re-frame/dispatch [:navigate-back]))
|
||||
[react/view
|
||||
|
@ -49,19 +49,17 @@
|
|||
name]
|
||||
[react/text {:force-uppercase? true}
|
||||
(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/letsubs [network [:network]
|
||||
visible-tokens [:wallet.settings/visible-tokens]
|
||||
balance [:balance]]
|
||||
(views/letsubs [assets [:wallet/visible-assets-with-amount]]
|
||||
[components/simple-screen
|
||||
[components/toolbar (i18n/label :t/wallet-assets)]
|
||||
[react/view {:style (assoc components.styles/flex :background-color :white)}
|
||||
[list/flat-list {:default-separator? true
|
||||
:data (concat [tokens/ethereum] (wallet/current-tokens visible-tokens network))
|
||||
:data assets
|
||||
:key-fn (comp str :symbol)
|
||||
:render-fn #(render-token % balance type)}]]]))
|
||||
:render-fn #(render-token % type)}]]]))
|
||||
|
||||
(defn send-assets []
|
||||
[assets :send])
|
||||
|
|
|
@ -91,30 +91,31 @@
|
|||
(ethereum/estimate-gas-web3 web3 (clj->js obj) #(re-frame/dispatch [success-event %2]))))
|
||||
|
||||
;; Handlers
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:update-wallet
|
||||
(fn [{{:keys [web3 accounts/current-account-id network network-status] :as db} :db} [_ symbols]]
|
||||
(when (not= network-status :offline)
|
||||
{:get-balance {:web3 web3
|
||||
:account-id current-account-id
|
||||
:success-event :update-balance-success
|
||||
:error-event :update-balance-fail}
|
||||
:get-tokens-balance {:web3 web3
|
||||
:account-id current-account-id
|
||||
:symbols symbols
|
||||
:chain (ethereum/network->chain-keyword network)
|
||||
:success-event :update-token-balance-success
|
||||
:error-event :update-token-balance-fail}
|
||||
:get-prices {:from "ETH"
|
||||
:to "USD"
|
||||
:success-event :update-prices-success
|
||||
:error-event :update-prices-fail}
|
||||
:db (-> db
|
||||
(clear-error-message :prices-update)
|
||||
(clear-error-message :balance-update)
|
||||
(assoc-in [:wallet :balance-loading?] true)
|
||||
(assoc :prices-loading? true))})))
|
||||
(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)
|
||||
{:get-balance {:web3 web3
|
||||
:account-id current-account-id
|
||||
:success-event :update-balance-success
|
||||
:error-event :update-balance-fail}
|
||||
:get-tokens-balance {:web3 web3
|
||||
:account-id current-account-id
|
||||
:symbols symbols
|
||||
:chain chain
|
||||
:success-event :update-token-balance-success
|
||||
:error-event :update-token-balance-fail}
|
||||
:get-prices {:from "ETH"
|
||||
:to "USD"
|
||||
:success-event :update-prices-success
|
||||
:error-event :update-prices-fail}
|
||||
:db (-> db
|
||||
(clear-error-message :prices-update)
|
||||
(clear-error-message :balance-update)
|
||||
(assoc-in [:wallet :balance-loading?] true)
|
||||
(assoc :prices-loading? true))}))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:update-transactions
|
||||
|
@ -241,4 +242,4 @@
|
|||
(handlers/register-handler-fx
|
||||
:wallet/show-error
|
||||
(fn []
|
||||
{:show-error (i18n/label :t/wallet-error)}))
|
||||
{:show-error (i18n/label :t/wallet-error)}))
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
(defmethod navigation/preload-data! :wallet
|
||||
[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))
|
||||
|
||||
(defmethod navigation/preload-data! :transactions-history
|
||||
|
|
|
@ -124,7 +124,7 @@
|
|||
(if sending-from-bot-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
|
||||
: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]
|
||||
(when-not (seq gas)
|
||||
[: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 []
|
||||
(letsubs [network [:network]
|
||||
visible-tokens [:wallet.settings/visible-tokens]]
|
||||
visible-tokens [:wallet/visible-tokens-symbols]]
|
||||
[react/view (merge components.styles/flex {:background-color :white})
|
||||
[status-bar/status-bar {:type :modal-wallet}]
|
||||
[toolbar/toolbar #_{} {:style wallet.styles/toolbar}
|
||||
|
|
|
@ -1,25 +1,27 @@
|
|||
(ns status-im.ui.screens.wallet.subs
|
||||
(:require [re-frame.core :refer [reg-sub subscribe]]
|
||||
[status-im.utils.money :as money]))
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[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]
|
||||
(:wallet db)))
|
||||
|
||||
(reg-sub :balance
|
||||
(re-frame/reg-sub :balance
|
||||
:<- [:wallet]
|
||||
(fn [wallet]
|
||||
(:balance wallet)))
|
||||
|
||||
(reg-sub :price
|
||||
(re-frame/reg-sub :price
|
||||
(fn [db]
|
||||
(get-in db [:prices :price])))
|
||||
|
||||
(reg-sub :last-day
|
||||
(re-frame/reg-sub :last-day
|
||||
(fn [db]
|
||||
(get-in db [:prices :last-day])))
|
||||
|
||||
(reg-sub :portfolio-value
|
||||
(re-frame/reg-sub :portfolio-value
|
||||
:<- [:balance]
|
||||
:<- [:price]
|
||||
(fn [[balance price]]
|
||||
|
@ -30,21 +32,42 @@
|
|||
str)
|
||||
"...")))
|
||||
|
||||
(reg-sub :prices-loading?
|
||||
(re-frame/reg-sub :prices-loading?
|
||||
(fn [db]
|
||||
(:prices-loading? db)))
|
||||
|
||||
(reg-sub :wallet/balance-loading?
|
||||
(re-frame/reg-sub :wallet/balance-loading?
|
||||
:<- [:wallet]
|
||||
(fn [wallet]
|
||||
(:balance-loading? wallet)))
|
||||
|
||||
(reg-sub :wallet/error-message?
|
||||
(re-frame/reg-sub :wallet/error-message?
|
||||
:<- [:wallet]
|
||||
(fn [wallet]
|
||||
(or (get-in wallet [:errors :balance-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]
|
||||
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}
|
||||
(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)
|
||||
assets (map #(assoc % :amount (get balance (:symbol %))) (concat [tokens/ethereum] tokens))]
|
||||
[react/view styles/asset-section
|
||||
[react/text {:style styles/asset-section-title} (i18n/label :t/wallet-assets)]
|
||||
[list/flat-list
|
||||
{:default-separator? true
|
||||
:scroll-enabled false
|
||||
:key-fn (comp str :symbol)
|
||||
:data assets
|
||||
:render-fn render-asset}]]))
|
||||
|
||||
(defn- asset-section [assets]
|
||||
[react/view styles/asset-section
|
||||
[react/text {:style styles/asset-section-title} (i18n/label :t/wallet-assets)]
|
||||
[list/flat-list
|
||||
{:default-separator? true
|
||||
:scroll-enabled false
|
||||
:key-fn (comp str :symbol)
|
||||
:data assets
|
||||
:render-fn render-asset}]])
|
||||
|
||||
(views/defview wallet []
|
||||
(views/letsubs [network [:network]
|
||||
balance [:balance]
|
||||
visible-tokens [:wallet.settings/visible-tokens]
|
||||
(views/letsubs [assets [:wallet/visible-assets-with-amount]
|
||||
portfolio-value [:portfolio-value]]
|
||||
(let [symbols (map :symbol (current-tokens visible-tokens network))]
|
||||
[react/view styles/main-section
|
||||
[toolbar-view]
|
||||
[react/scroll-view {:content-container-style styles/scrollable-section
|
||||
:refresh-control
|
||||
(reagent/as-element
|
||||
[react/refresh-control {:on-refresh #(re-frame/dispatch [:update-wallet symbols])
|
||||
:tint-color :white
|
||||
:refreshing false}])}
|
||||
[react/view {:style styles/scroll-top}] ;; Hack to allow different colors for top / bottom scroll view]
|
||||
[total-section portfolio-value]
|
||||
[list/action-list actions
|
||||
{:container-style styles/action-section}]
|
||||
[asset-section network balance visible-tokens]]])))
|
||||
[react/view styles/main-section
|
||||
[toolbar-view]
|
||||
[react/scroll-view {:content-container-style styles/scrollable-section
|
||||
:refresh-control
|
||||
(reagent/as-element
|
||||
[react/refresh-control {:on-refresh #(re-frame/dispatch [:update-wallet])
|
||||
:tint-color :white
|
||||
:refreshing false}])}
|
||||
[react/view {:style styles/scroll-top}] ;; Hack to allow different colors for top / bottom scroll view]
|
||||
[total-section portfolio-value]
|
||||
[list/action-list actions
|
||||
{:container-style styles/action-section}]
|
||||
[asset-section assets]]]))
|
||||
|
|
Loading…
Reference in New Issue