[wallet] RPC calls optimzations for new accounts
This commit is contained in:
parent
4cc99c6bb8
commit
580ecfedc1
|
@ -135,6 +135,7 @@
|
|||
"localnotifications_notificationPreferences" {}
|
||||
"wallet_getTransfers" {}
|
||||
"wallet_getTokensBalances" {}
|
||||
"wallet_setInitialBlocksRange" {}
|
||||
"wallet_getBlocksByAddress" {}
|
||||
"wallet_getTransfersFromBlock" {}
|
||||
"wallet_getTransfersByAddress" {}
|
||||
|
|
|
@ -185,17 +185,6 @@
|
|||
:min-block min-block
|
||||
:min-block-transfers-count min-block-transfers-count)}))
|
||||
|
||||
(fx/defn set-max-block-with-transfers
|
||||
[{:keys [db]} address transfers]
|
||||
(let [max-block (reduce
|
||||
(fn [max-block {:keys [block]}]
|
||||
(if (> block max-block)
|
||||
block
|
||||
max-block))
|
||||
(get-in db [:wallet :accounts address :max-block] 0)
|
||||
transfers)]
|
||||
{:db (assoc-in db [:wallet :accounts address :max-block] max-block)}))
|
||||
|
||||
(defn update-fetching-status
|
||||
[db addresses fetching-type state]
|
||||
(update-in
|
||||
|
@ -231,7 +220,7 @@
|
|||
max-known-block (get-max-block-with-transfers db address)
|
||||
effects (cond-> [(when (seq transfers)
|
||||
(set-lowest-fetched-block checksum transfers))
|
||||
(set-max-block-with-transfers checksum transfers)]
|
||||
(wallet/set-max-block-with-transfers checksum transfers)]
|
||||
|
||||
(seq transfers)
|
||||
(concat (mapv add-transfer transfers))
|
||||
|
@ -250,7 +239,7 @@
|
|||
acc))
|
||||
#{}
|
||||
transfers))
|
||||
nil))
|
||||
(zero? max-known-block)))
|
||||
|
||||
(< (count transfers) limit)
|
||||
(conj (tx-history-end-reached checksum)))]
|
||||
|
@ -286,6 +275,7 @@
|
|||
[cofx transfers params]
|
||||
(fx/merge cofx
|
||||
(handle-new-transfer transfers params)
|
||||
(wallet/stop-fetching-on-empty-tx-history transfers)
|
||||
(check-ens-transactions transfers)))
|
||||
|
||||
(fx/defn tx-fetching-failed
|
||||
|
|
|
@ -18,11 +18,13 @@
|
|||
|
||||
(fx/defn on-network-status-change
|
||||
[{:keys [db] :as cofx}]
|
||||
(let [logged-in? (multiaccounts.model/logged-in? cofx)
|
||||
(let [initialized? (get db :network-status/initialized?)
|
||||
logged-in? (multiaccounts.model/logged-in? cofx)
|
||||
{:keys [remember-syncing-choice?]} (:multiaccount db)]
|
||||
(apply
|
||||
fx/merge
|
||||
cofx
|
||||
{:db (assoc db :network-status/initialized? true)}
|
||||
(cond
|
||||
(and logged-in?
|
||||
(utils/cellular? (:network/type db))
|
||||
|
@ -35,8 +37,13 @@
|
|||
|
||||
logged-in?
|
||||
[(mailserver/process-next-messages-request)
|
||||
(bottom-sheet/hide-bottom-sheet)
|
||||
(wallet/restart-wallet-service-default)]))))
|
||||
(bottom-sheet/hide-bottom-sheet)]
|
||||
|
||||
;; NOTE(rasom): When we log into account on-network-status-change is
|
||||
;; dispatched, but that doesn't mean there was a status change, thus
|
||||
;; no reason to restart wallet.
|
||||
(and logged-in? initialized?)
|
||||
[(wallet/restart-wallet-service-default)]))))
|
||||
|
||||
(defn apply-settings
|
||||
([sync?] (apply-settings sync? :default))
|
||||
|
|
|
@ -131,9 +131,14 @@
|
|||
|
||||
(fx/defn exit-wizard
|
||||
[{:keys [db] :as cofx}]
|
||||
(fx/merge cofx
|
||||
{:db (dissoc db :intro-wizard)}
|
||||
(navigation/navigate-to-cofx :notifications-onboarding nil)))
|
||||
(let [recovered-account? (get-in db [:intro-wizard :recovering?])]
|
||||
(log/info "exit-wizard" "recovered-account?" recovered-account?)
|
||||
(fx/merge
|
||||
cofx
|
||||
{:db (-> db
|
||||
(dissoc :intro-wizard)
|
||||
(assoc :recovered-account? recovered-account?))}
|
||||
(navigation/navigate-to-cofx :notifications-onboarding nil))))
|
||||
|
||||
(fx/defn init-key-generation
|
||||
[{:keys [db] :as cofx}]
|
||||
|
|
|
@ -30,7 +30,8 @@
|
|||
[status-im.acquisition.core :as acquisition]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.data-store.invitations :as data-store.invitations]
|
||||
[status-im.chat.models.link-preview :as link-preview]))
|
||||
[status-im.chat.models.link-preview :as link-preview]
|
||||
[status-im.utils.mobile-sync :as utils.mobile-sync]))
|
||||
|
||||
(re-frame/reg-fx
|
||||
::login
|
||||
|
@ -71,7 +72,8 @@
|
|||
|
||||
(fx/defn initialize-wallet
|
||||
{:events [::initialize-wallet]}
|
||||
[{:keys [db] :as cofx} accounts custom-tokens favourites new-account?]
|
||||
[{:keys [db] :as cofx} accounts custom-tokens
|
||||
favourites scan-all-tokens? new-account?]
|
||||
(fx/merge
|
||||
cofx
|
||||
{:db (assoc db :multiaccount/accounts
|
||||
|
@ -80,7 +82,16 @@
|
|||
::enable-local-notifications nil}
|
||||
(wallet/initialize-tokens custom-tokens)
|
||||
(wallet/initialize-favourites favourites)
|
||||
(wallet/update-balances nil new-account?)
|
||||
(cond (and new-account?
|
||||
(not scan-all-tokens?))
|
||||
(wallet/set-zero-balances (first accounts))
|
||||
|
||||
(and new-account? scan-all-tokens?
|
||||
(not (utils.mobile-sync/cellular? (:network/type db))))
|
||||
(wallet/set-max-block (get (first accounts) :address) 0)
|
||||
|
||||
:else
|
||||
(wallet/update-balances nil scan-all-tokens?))
|
||||
(prices/update-prices)))
|
||||
|
||||
(fx/defn login
|
||||
|
@ -301,7 +312,7 @@
|
|||
{:db (-> db
|
||||
(dissoc :multiaccounts/login)
|
||||
(assoc-in [:multiaccount :multiaccounts/first-account] first-account?))
|
||||
:dispatch-later [{:ms 2000 :dispatch [::initialize-wallet accounts nil nil (:recovered multiaccount)]}]}
|
||||
:dispatch-later [{:ms 2000 :dispatch [::initialize-wallet accounts nil nil (:recovered multiaccount) true]}]}
|
||||
(finish-keycard-setup)
|
||||
(transport/start-messenger)
|
||||
(communities/fetch)
|
||||
|
@ -314,16 +325,18 @@
|
|||
|
||||
(fx/defn multiaccount-login-success
|
||||
[{:keys [db now] :as cofx}]
|
||||
(let [{:keys [key-uid password save-password? creating?]} (:multiaccounts/login db)
|
||||
multiaccounts (:multiaccounts/multiaccounts db)
|
||||
recovering? (get-in db [:intro-wizard :recovering?])
|
||||
login-only? (not (or creating?
|
||||
recovering?
|
||||
(keycard-setup? cofx)))
|
||||
nodes nil]
|
||||
(let [{:keys [key-uid password save-password? creating?]}
|
||||
(:multiaccounts/login db)
|
||||
|
||||
multiaccounts (:multiaccounts/multiaccounts db)
|
||||
recovered-account? (get db :recovered-account?)
|
||||
login-only? (not (or creating?
|
||||
recovered-account?
|
||||
(keycard-setup? cofx)))
|
||||
nodes nil]
|
||||
(log/debug "[multiaccount] multiaccount-login-success"
|
||||
"login-only?" login-only?
|
||||
"recovering?" recovering?)
|
||||
"recovered-account?" recovered-account?)
|
||||
(fx/merge cofx
|
||||
{:db (-> db
|
||||
(dissoc :connectivity/ui-status-properties)
|
||||
|
@ -340,13 +353,13 @@
|
|||
;;FIXME
|
||||
(when nodes
|
||||
(fleet/set-nodes :eth.contract nodes))
|
||||
(wallet/restart-wallet-service {:force-start? true})
|
||||
(if (and (not login-only?)
|
||||
(not recovered-account?))
|
||||
(wallet/set-initial-blocks-range)
|
||||
(wallet/restart-wallet-service {:force-start? true}))
|
||||
(if login-only?
|
||||
(login-only-events key-uid password save-password?)
|
||||
(create-only-events))
|
||||
(when recovering?
|
||||
(navigation/navigate-to-cofx :tabs {:screen :chat-stack
|
||||
:params {:screen :home}})))))
|
||||
(create-only-events)))))
|
||||
|
||||
;; FIXME(Ferossgp): We should not copy keys as we denormalize the database,
|
||||
;; this create desync between actual accounts and the one on login causing broken state
|
||||
|
|
|
@ -11,9 +11,11 @@
|
|||
[{:keys [db] :as cofx} is-connected?]
|
||||
(fx/merge cofx
|
||||
{:db (assoc db :network-status (if is-connected? :online :offline))}
|
||||
(when is-connected?
|
||||
(if-not (= (count (get-in db [:wallet :accounts])) (count (get db :multiaccount/accounts)))
|
||||
(wallet/update-balances nil nil)))))
|
||||
(when (and is-connected?
|
||||
(or (not= (count (get-in db [:wallet :accounts]))
|
||||
(count (get db :multiaccount/accounts)))
|
||||
(wallet/has-empty-balances? db)))
|
||||
(wallet/update-balances nil nil))))
|
||||
|
||||
(fx/defn change-network-type
|
||||
[{:keys [db] :as cofx} old-network-type network-type expensive?]
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
[{:name :wallet
|
||||
:insets {:top false}
|
||||
:style {:padding-bottom tabbar.styles/tabs-diff}
|
||||
:on-focus [:wallet/tab-opened]
|
||||
:component wallet.accounts/accounts-overview}
|
||||
{:name :wallet-account
|
||||
:component wallet.account/account}
|
||||
|
|
|
@ -171,15 +171,17 @@
|
|||
balances)))
|
||||
|
||||
(defn get-token-balances
|
||||
[{:keys [addresses tokens init? assets]}]
|
||||
[{:keys [addresses tokens scan-all-tokens? assets]}]
|
||||
(json-rpc/call
|
||||
{:method "wallet_getTokensBalances"
|
||||
:params [addresses (keys tokens)]
|
||||
:number-of-retries 50
|
||||
:on-success
|
||||
(fn [results]
|
||||
(when-let [balances (clean-up-results results tokens (if init? nil assets))]
|
||||
(re-frame/dispatch (if init?
|
||||
(when-let [balances (clean-up-results
|
||||
results tokens
|
||||
(if scan-all-tokens? nil assets))]
|
||||
(re-frame/dispatch (if scan-all-tokens?
|
||||
;; NOTE: when there it is not a visible
|
||||
;; assets we make an initialization round
|
||||
[::tokens-found balances]
|
||||
|
@ -222,15 +224,18 @@
|
|||
{:events [:wallet/update-balances]}
|
||||
[{{:keys [network-status :wallet/all-tokens
|
||||
multiaccount :multiaccount/accounts] :as db} :db
|
||||
:as cofx} addresses init?]
|
||||
:as cofx} addresses scan-all-tokens?]
|
||||
(log/debug "update-balances"
|
||||
"accounts" addresses
|
||||
"scan-all-tokens?" scan-all-tokens?)
|
||||
(let [addresses (or addresses (map (comp string/lower-case :address) accounts))
|
||||
{:keys [:wallet/visible-tokens]} multiaccount
|
||||
chain (ethereum/chain-keyword db)
|
||||
assets (get visible-tokens chain)
|
||||
tokens (->> (vals all-tokens)
|
||||
(remove #(or (:hidden? %)
|
||||
;;if not init remove not visible tokens
|
||||
(and (not init?)
|
||||
;;if not scan-all-tokens? remove not visible tokens
|
||||
(and (not scan-all-tokens?)
|
||||
(not (get assets (:symbol %))))))
|
||||
(reduce (fn [acc {:keys [address symbol]}]
|
||||
(assoc acc address symbol))
|
||||
|
@ -240,10 +245,10 @@
|
|||
(fx/merge
|
||||
cofx
|
||||
{:wallet/get-balances addresses
|
||||
:wallet/get-tokens-balances {:addresses addresses
|
||||
:tokens tokens
|
||||
:assets assets
|
||||
:init? init?}
|
||||
:wallet/get-tokens-balances {:addresses addresses
|
||||
:tokens tokens
|
||||
:assets assets
|
||||
:scan-all-tokens? scan-all-tokens?}
|
||||
:db (prices/clear-error-message db :balance-update)}
|
||||
(when-not assets
|
||||
(multiaccounts.update/multiaccount-update
|
||||
|
@ -264,6 +269,10 @@
|
|||
[:wallet :accounts (eip55/address->checksum address) :balance :ETH]
|
||||
(money/bignumber balance))})
|
||||
|
||||
(defn has-empty-balances? [db]
|
||||
(some #(nil? (get-in % [:balance :ETH]))
|
||||
(get-in db [:wallet :accounts])))
|
||||
|
||||
(fx/defn update-toggle-in-settings
|
||||
[{{:keys [multiaccount] :as db} :db :as cofx} symbol checked?]
|
||||
(let [chain (ethereum/chain-keyword db)
|
||||
|
@ -300,6 +309,13 @@
|
|||
accounts
|
||||
balances))}))
|
||||
|
||||
(fx/defn set-zero-balances
|
||||
[cofx {:keys [address]}]
|
||||
(fx/merge
|
||||
cofx
|
||||
(update-balance address 0)
|
||||
(update-tokens-balances {address {:SNT 0}})))
|
||||
|
||||
(fx/defn configure-token-balance-and-visibility
|
||||
{:events [::tokens-found]}
|
||||
[{:keys [db] :as cofx} balances]
|
||||
|
@ -555,11 +571,29 @@
|
|||
(def ms-2-min (datetime/minutes 2))
|
||||
(def ms-4-min (datetime/minutes 4))
|
||||
|
||||
(defn get-restart-interval [db]
|
||||
(if (ethereum/custom-rpc-node?
|
||||
(defn get-max-block-with-transfer [db]
|
||||
(reduce
|
||||
(fn [block [_ {:keys [max-block]}]]
|
||||
(if (or (nil? block)
|
||||
(> max-block block))
|
||||
max-block
|
||||
block))
|
||||
nil
|
||||
(get-in db [:wallet :accounts])))
|
||||
|
||||
(defn get-restart-interval
|
||||
[db]
|
||||
(let [max-block (get-max-block-with-transfer db)]
|
||||
(cond
|
||||
(ethereum/custom-rpc-node?
|
||||
(ethereum/current-network db))
|
||||
ms-4-min
|
||||
ms-20-min))
|
||||
ms-4-min
|
||||
|
||||
(and max-block (zero? max-block))
|
||||
(log/info "[wallet] No transactions found")
|
||||
|
||||
:else
|
||||
ms-20-min)))
|
||||
|
||||
(defn get-watching-interval [db]
|
||||
(if (ethereum/custom-rpc-node?
|
||||
|
@ -573,9 +607,10 @@
|
|||
old-timeout (get db :wallet-service/restart-timeout)
|
||||
timeout (or
|
||||
old-timeout
|
||||
(utils.utils/set-timeout
|
||||
#(re-frame.core/dispatch [::restart])
|
||||
(get-restart-interval db)))
|
||||
(when-let [interval (get-restart-interval db)]
|
||||
(utils.utils/set-timeout
|
||||
#(re-frame.core/dispatch [::restart])
|
||||
interval)))
|
||||
max-known-block (get db :wallet/max-known-block 0)]
|
||||
{:db (-> db
|
||||
(update :wallet dissoc :fetching)
|
||||
|
@ -591,12 +626,14 @@
|
|||
[{:keys [db] :as cofx} watch-new-blocks?]
|
||||
(let [old-timeout (get db :wallet-service/restart-timeout)
|
||||
state (get db :wallet-service/state)
|
||||
timeout (utils.utils/set-timeout
|
||||
#(re-frame.core/dispatch [::restart])
|
||||
(get-restart-interval db))]
|
||||
timeout (when-let [interval (get-restart-interval db)]
|
||||
(utils.utils/set-timeout
|
||||
#(re-frame.core/dispatch [::restart])
|
||||
interval))]
|
||||
{:db (-> db
|
||||
(assoc :wallet-service/state :started)
|
||||
(assoc :wallet-service/restart-timeout timeout))
|
||||
(assoc :wallet-service/state :started
|
||||
:wallet-service/restart-timeout timeout
|
||||
:wallet/was-started? true))
|
||||
::start-wallet watch-new-blocks?
|
||||
::utils.utils/clear-timeouts
|
||||
[old-timeout]}))
|
||||
|
@ -625,9 +662,10 @@
|
|||
(def background-cooldown-time (datetime/minutes 3))
|
||||
|
||||
(fx/defn restart-wallet-service-after-background
|
||||
[{:keys [now] :as cofx} background-time]
|
||||
(when (> (- now background-time)
|
||||
background-cooldown-time)
|
||||
[{:keys [now db] :as cofx} background-time]
|
||||
(when (and (get db :wallet/was-started?)
|
||||
(> (- now background-time)
|
||||
background-cooldown-time))
|
||||
(restart-wallet-service
|
||||
cofx
|
||||
{:force-start? true})))
|
||||
|
@ -699,6 +737,7 @@
|
|||
|
||||
(fx/defn clear-timeouts
|
||||
[{:keys [db]}]
|
||||
(log/info "[wallet] clear-timeouts")
|
||||
(let [watch-timeout-id (get db :wallet/watch-txs-timeout)
|
||||
restart-timeout-id (get db :wallet-service/restart-timeout)]
|
||||
{:db (dissoc db :wallet/watch-txs-timeout
|
||||
|
@ -766,3 +805,52 @@
|
|||
(when on-close
|
||||
{:dispatch on-close})
|
||||
(navigation/navigate-back)))
|
||||
(fx/defn stop-fetching-on-empty-tx-history
|
||||
[{:keys [db] :as cofx} transfers]
|
||||
(let [non-empty-history? (get db :wallet/non-empty-tx-history?)
|
||||
watching-outgoing-tx? (get db :wallet/watch-txs-timeout)
|
||||
custom-node? (ethereum/custom-rpc-node?
|
||||
(ethereum/current-network db))]
|
||||
(if (and (not non-empty-history?)
|
||||
(not watching-outgoing-tx?)
|
||||
(empty? transfers)
|
||||
(not custom-node?))
|
||||
(clear-timeouts cofx)
|
||||
{:db (assoc db :wallet/non-empty-tx-history? true)})))
|
||||
|
||||
(re-frame/reg-fx
|
||||
::set-inital-range
|
||||
(fn []
|
||||
(json-rpc/call
|
||||
{:method "wallet_setInitialBlocksRange"
|
||||
:params []
|
||||
:number-of-retries 10
|
||||
:on-success #(log/info "Initial blocks range was successfully set")
|
||||
:on-error #(log/info "Initial blocks range was not set")})))
|
||||
|
||||
(fx/defn set-initial-blocks-range
|
||||
[{:keys [db]}]
|
||||
{::set-inital-range nil})
|
||||
|
||||
(fx/defn tab-opened
|
||||
{:events [:wallet/tab-opened]}
|
||||
[{:keys [db] :as cofx}]
|
||||
(when-not (get db :wallet/was-started?)
|
||||
(restart-wallet-service cofx {:force-start? true})))
|
||||
|
||||
(fx/defn set-max-block [{:keys [db]} address block]
|
||||
(log/debug "set-max-block"
|
||||
"address" address
|
||||
"block" block)
|
||||
{:db (assoc-in db [:wallet :accounts address :max-block] block)})
|
||||
|
||||
(fx/defn set-max-block-with-transfers
|
||||
[{:keys [db] :as cofx} address transfers]
|
||||
(let [max-block (reduce
|
||||
(fn [max-block {:keys [block]}]
|
||||
(if (> block max-block)
|
||||
block
|
||||
max-block))
|
||||
(get-in db [:wallet :accounts address :max-block] 0)
|
||||
transfers)]
|
||||
(set-max-block cofx address max-block)))
|
||||
|
|
|
@ -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.72.0",
|
||||
"commit-sha1": "f115b8d289684ac51dec30e5d27f57722c0a6724",
|
||||
"src-sha256": "0h94ki44by233abwg055nhm4wg7i6f8f8jmndm9813a965x51rgp"
|
||||
"version": "v0.73.1",
|
||||
"commit-sha1": "d21cd6aba1521ba30b79cfe71cf89088a35322fc",
|
||||
"src-sha256": "1if60j0kyw2llzia5xqqfk30iji8kvg5k7fq88q84nwx4pdpc04b"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue