[#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:
Dmitry Novotochinov 2018-09-11 19:44:47 +03:00 committed by Pedro Pombeiro
parent 4a21b5192c
commit ed63cd4994
No known key found for this signature in database
GPG Key ID: A65DEB11E4BBC647
3 changed files with 16 additions and 9 deletions

View File

@ -176,7 +176,7 @@
[transactions.views/history-list true]]
[react/scroll-view {:refresh-control
(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
:refreshing false}])}
(if error-message

View File

@ -12,3 +12,8 @@
:configure-token-balance-and-visibility
(fn [cofx [_ symbol balance]]
(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)))

View File

@ -24,15 +24,17 @@
(wallet.events/update-token-balance-success symbol balance)))
(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))
chain (ethereum/network->chain-keyword network)
contracts (->> (tokens/tokens-for chain)
(remove :hidden?))]
(doseq [{:keys [address symbol]} contracts]
;;TODO(goranjovic): move `get-token-balance` function to wallet models
(wallet.events/get-token-balance {:web3 web3
:contract address
:account-id (:address account)
:on-success #(when (> % 0)
(re-frame/dispatch [:configure-token-balance-and-visibility symbol %]))}))))
(when-not (= network-status :offline)
(doseq [{:keys [address symbol]} contracts]
;;TODO(goranjovic): move `get-token-balance` function to wallet models
(wallet.events/get-token-balance {:web3 web3
:contract address
:account-id (:address account)
:on-error #(re-frame/dispatch [:update-token-balance-fail symbol %])
:on-success #(when (> % 0)
(re-frame/dispatch [:configure-token-balance-and-visibility symbol %]))})))))