[wallet] Show cached balance before fetching latest

This commit is contained in:
Roman Volosovskyi 2021-05-20 16:36:49 +03:00
parent f5baee5039
commit 58d358125c
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
6 changed files with 47 additions and 12 deletions

View File

@ -15,7 +15,6 @@
:app-state "active"
:wallet wallet.db/default-wallet
:wallet/all-tokens {}
:prices {}
:peers-count 0
:node-info {}
:peers-summary []

View File

@ -159,6 +159,7 @@
"wallet_getTransfersByAddress" {}
"wallet_watchTransaction" {}
"wallet_checkRecentHistory" {}
"wallet_getCachedBalances" {}
"wallet_storePendingTransaction" {}
"wallet_deletePendingTransaction" {}
"wallet_getPendingTransactions" {}

View File

@ -107,7 +107,7 @@
(wallet/set-max-block (get (first accounts) :address) 0)
:else
(wallet/update-balances nil scan-all-tokens?))
(wallet/get-cached-balances scan-all-tokens?))
(when-not (get db :wallet/new-account)
(wallet/restart-wallet-service nil))
(when-not (utils.mobile-sync/syncing-allowed? cofx)

View File

@ -24,12 +24,13 @@
;;NOTE(this check is to allow value conversion for sidechains with native currencies listed on cryptocompare
;; under a symbol different than display symbol. Specific use case xDAI and POA.
(if mainnet?
(into {} (for [[from entries] (:RAW (types/json->clj resp))]
{from (into {} (for [[to entry] entries]
{to {:from (name from)
:to (name to)
:price (:PRICE entry)
:last-day (:OPEN24HOUR entry)}}))}))
(when-let [RAW (:RAW (types/json->clj resp))]
(into {} (for [[from entries] RAW]
{from (into {} (for [[to entry] entries]
{to {:from (name from)
:to (name to)
:price (:PRICE entry)
:last-day (:OPEN24HOUR entry)}}))})))
(into {} (for [[_ entries] (:RAW (types/json->clj resp))]
{:ETH (into {} (for [[to entry] entries]
{to {:from "ETH"

View File

@ -51,6 +51,24 @@
(defn assoc-error-message [db error-type err]
(assoc-in db [:wallet :errors error-type] (or err :unknown-error)))
(re-frame/reg-fx
:wallet/get-cached-balances
(fn [{:keys [addresses on-success on-error]}]
(json-rpc/call
{:method "wallet_getCachedBalances"
:params [addresses]
:on-success on-success
:on-error on-error})))
(fx/defn get-cached-balances
[{:keys [db]} scan-all-tokens?]
(let [addresses (map (comp string/lower-case :address)
(get db :multiaccount/accounts))]
{:wallet/get-cached-balances
{:addresses addresses
:on-success #(re-frame/dispatch [::set-cached-balances addresses % scan-all-tokens?])
:on-error #(re-frame/dispatch [::on-get-cached-balance-fail % scan-all-tokens?])}}))
(fx/defn on-update-balance-fail
{:events [::update-balance-fail]}
[{:keys [db]} err]
@ -60,7 +78,7 @@
(fx/defn on-update-token-balance-fail
{:events [::update-token-balance-fail]}
[{:keys [db]} err]
(log/debug "Unable to get tokens balances: " err)
(log/debug "on-update-token-balance-fail: " err)
{:db (assoc-error-message db :balance-update :error-unable-to-get-token-balance)})
(fx/defn open-transaction-details
@ -257,6 +275,12 @@
#{}))
{}))))))
(fx/defn on-get-cached-balance-fail
{:events [::on-get-cached-balance-fail]}
[{:keys [db] :as cofx} err scan-all-tokens?]
(log/warn "Can't fetch cached balances" err)
(update-balances cofx nil scan-all-tokens?))
(defn- set-checked [tokens-id token-id checked?]
(let [tokens-id (or tokens-id #{})]
(if checked?
@ -270,6 +294,16 @@
[:wallet :accounts (eip55/address->checksum address) :balance :ETH]
(money/bignumber balance))})
(fx/defn set-cached-balances
{:events [::set-cached-balances]}
[cofx addresses balances scan-all-tokens?]
(apply fx/merge
cofx
(update-balances nil scan-all-tokens?)
(map (fn [{:keys [address balance]}]
(update-balance address balance))
balances)))
(defn has-empty-balances? [db]
(some #(nil? (get-in % [:balance :ETH]))
(get-in db [:wallet :accounts])))

View File

@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.79.3",
"commit-sha1": "71f66f68064e9897cd17b6bcecba426a91405034",
"src-sha256": "1npbsy1fs50k6lajhl70yah9dhj7zf2a8x3mqr70lvn2w5qprcy5"
"version": "v0.79.4",
"commit-sha1": "d1dc5f1e272b72d84a8c6bee1fe09de6c7d6fd1e",
"src-sha256": "04nszlhn33p0szqpd115h50gcgw3jm3yjrvqv028ry1zzn4r8k6a"
}