[#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?))]
|
||||||
|
(when-not (= network-status :offline)
|
||||||
(doseq [{:keys [address symbol]} contracts]
|
(doseq [{:keys [address symbol]} contracts]
|
||||||
;;TODO(goranjovic): move `get-token-balance` function to wallet models
|
;;TODO(goranjovic): move `get-token-balance` function to wallet models
|
||||||
(wallet.events/get-token-balance {:web3 web3
|
(wallet.events/get-token-balance {:web3 web3
|
||||||
:contract address
|
:contract address
|
||||||
:account-id (:address account)
|
:account-id (:address account)
|
||||||
|
:on-error #(re-frame/dispatch [:update-token-balance-fail symbol %])
|
||||||
:on-success #(when (> % 0)
|
: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