[#9280] Add retries on error when fetching balances
This commit is contained in:
parent
5a64745fce
commit
ea02f8e3cf
|
@ -27,22 +27,29 @@
|
||||||
[status-im.ethereum.stateofus :as stateofus]
|
[status-im.ethereum.stateofus :as stateofus]
|
||||||
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]))
|
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(defn get-balance
|
||||||
:wallet/get-balance
|
[{:keys [address on-success on-error number-of-retries]
|
||||||
(fn [{:keys [account-address on-success on-error]}]
|
:as params
|
||||||
|
:or {number-of-retries 4}}]
|
||||||
|
(log/debug "[wallet] get-balance"
|
||||||
|
"address" address
|
||||||
|
"number-of-retries" number-of-retries)
|
||||||
(json-rpc/call
|
(json-rpc/call
|
||||||
{:method "eth_getBalance"
|
{:method "eth_getBalance"
|
||||||
:params [account-address "latest"]
|
:params [address "latest"]
|
||||||
:on-success on-success
|
:on-success on-success
|
||||||
:on-error on-error})))
|
:on-error (fn [error]
|
||||||
|
(if (zero? number-of-retries)
|
||||||
|
(on-error error)
|
||||||
|
(get-balance
|
||||||
|
(update params :number-of-retries dec))))}))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:wallet/get-balances
|
:wallet/get-balances
|
||||||
(fn [addresses]
|
(fn [addresses]
|
||||||
(doseq [address addresses]
|
(doseq [address addresses]
|
||||||
(json-rpc/call
|
(get-balance
|
||||||
{:method "eth_getBalance"
|
{:address address
|
||||||
:params [address "latest"]
|
|
||||||
:on-success #(re-frame/dispatch [::update-balance-success address %])
|
:on-success #(re-frame/dispatch [::update-balance-success address %])
|
||||||
:on-error #(re-frame/dispatch [::update-balance-fail %])}))))
|
:on-error #(re-frame/dispatch [::update-balance-fail %])}))))
|
||||||
|
|
||||||
|
@ -175,9 +182,13 @@
|
||||||
(when (not-empty balances)
|
(when (not-empty balances)
|
||||||
balances)))
|
balances)))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(defn get-token-balances
|
||||||
:wallet/get-tokens-balances
|
[{:keys [addresses tokens init? assets number-of-retries]
|
||||||
(fn [{:keys [addresses tokens init? assets]}]
|
:as params
|
||||||
|
:or {number-of-retries 4}}]
|
||||||
|
(log/debug "[wallet] get-token-balances"
|
||||||
|
"addresses" addresses
|
||||||
|
"number-of-retries" number-of-retries)
|
||||||
(json-rpc/call
|
(json-rpc/call
|
||||||
{:method "wallet_getTokensBalances"
|
{:method "wallet_getTokensBalances"
|
||||||
:params [addresses (keys tokens)]
|
:params [addresses (keys tokens)]
|
||||||
|
@ -189,7 +200,15 @@
|
||||||
;; assets we make an initialization round
|
;; assets we make an initialization round
|
||||||
[::tokens-found balances]
|
[::tokens-found balances]
|
||||||
[::update-tokens-balances-success balances]))))
|
[::update-tokens-balances-success balances]))))
|
||||||
:on-error #(re-frame/dispatch [::update-token-balance-fail %])})))
|
:on-error
|
||||||
|
(fn [error]
|
||||||
|
(if (zero? number-of-retries)
|
||||||
|
(re-frame/dispatch [::update-token-balance-fail error])
|
||||||
|
(get-token-balances (update params :number-of-retries dec))))}))
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
:wallet/get-tokens-balances
|
||||||
|
get-token-balances)
|
||||||
|
|
||||||
(defn clear-error-message [db error-type]
|
(defn clear-error-message [db error-type]
|
||||||
(update-in db [:wallet :errors] dissoc error-type))
|
(update-in db [:wallet :errors] dissoc error-type))
|
||||||
|
|
Loading…
Reference in New Issue