[#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]]
|
||||
[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
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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?))]
|
||||
(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 %]))}))))
|
||||
(re-frame/dispatch [:configure-token-balance-and-visibility symbol %]))})))))
|
||||
|
|
Loading…
Reference in New Issue