mirror of
https://github.com/status-im/status-react.git
synced 2025-03-01 11:00:51 +00:00
[#5474] Handle offline wallet onboarding
* Add :on-error callback to get-token-balance * Check if online before doing token balance update * Pull to refresh makes full wallet update, i.e. for all known tokens, to properly update balances for new tokens that might appear in user wallet with time and for tokens that were missed during offline Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
parent
4a21b5192c
commit
ed63cd4994
@ -176,7 +176,7 @@
|
|||||||
[transactions.views/history-list true]]
|
[transactions.views/history-list true]]
|
||||||
[react/scroll-view {:refresh-control
|
[react/scroll-view {: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 [:wallet.ui/pull-to-refresh])
|
||||||
:tint-color :white
|
:tint-color :white
|
||||||
:refreshing false}])}
|
:refreshing false}])}
|
||||||
(if error-message
|
(if error-message
|
||||||
|
@ -12,3 +12,8 @@
|
|||||||
:configure-token-balance-and-visibility
|
:configure-token-balance-and-visibility
|
||||||
(fn [cofx [_ symbol balance]]
|
(fn [cofx [_ symbol balance]]
|
||||||
(models/configure-token-balance-and-visibility symbol balance accounts.update/update-settings cofx)))
|
(models/configure-token-balance-and-visibility symbol balance accounts.update/update-settings cofx)))
|
||||||
|
|
||||||
|
(handlers/register-handler-fx
|
||||||
|
:wallet.ui/pull-to-refresh
|
||||||
|
(fn [cofx _]
|
||||||
|
(models/wallet-autoconfig-tokens cofx)))
|
||||||
|
@ -24,15 +24,17 @@
|
|||||||
(wallet.events/update-token-balance-success symbol balance)))
|
(wallet.events/update-token-balance-success symbol balance)))
|
||||||
|
|
||||||
(defn wallet-autoconfig-tokens [{:keys [db]}]
|
(defn wallet-autoconfig-tokens [{:keys [db]}]
|
||||||
(let [{:keys [account/account web3]} db
|
(let [{:keys [account/account web3 network-status]} db
|
||||||
network (get (:networks account) (:network account))
|
network (get (:networks account) (:network account))
|
||||||
chain (ethereum/network->chain-keyword network)
|
chain (ethereum/network->chain-keyword network)
|
||||||
contracts (->> (tokens/tokens-for chain)
|
contracts (->> (tokens/tokens-for chain)
|
||||||
(remove :hidden?))]
|
(remove :hidden?))]
|
||||||
(doseq [{:keys [address symbol]} contracts]
|
(when-not (= network-status :offline)
|
||||||
;;TODO(goranjovic): move `get-token-balance` function to wallet models
|
(doseq [{:keys [address symbol]} contracts]
|
||||||
(wallet.events/get-token-balance {:web3 web3
|
;;TODO(goranjovic): move `get-token-balance` function to wallet models
|
||||||
:contract address
|
(wallet.events/get-token-balance {:web3 web3
|
||||||
:account-id (:address account)
|
:contract address
|
||||||
:on-success #(when (> % 0)
|
:account-id (:address account)
|
||||||
(re-frame/dispatch [:configure-token-balance-and-visibility symbol %]))}))))
|
:on-error #(re-frame/dispatch [:update-token-balance-fail symbol %])
|
||||||
|
:on-success #(when (> % 0)
|
||||||
|
(re-frame/dispatch [:configure-token-balance-and-visibility symbol %]))})))))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user