[wallet #12000] Check tx history in 2/3/5/10/20 minutes on buy crypto
This commit is contained in:
parent
4dacc95de6
commit
3dfa7beacd
|
@ -45,31 +45,28 @@
|
||||||
(log/debug "[wallet-subs] recent-history-fetching-ended"
|
(log/debug "[wallet-subs] recent-history-fetching-ended"
|
||||||
"accounts" accounts
|
"accounts" accounts
|
||||||
"block" blockNumber)
|
"block" blockNumber)
|
||||||
(fx/merge
|
{:db (-> db
|
||||||
cofx
|
(assoc :ethereum/current-block blockNumber)
|
||||||
{:db (-> db
|
(update-in [:wallet :accounts]
|
||||||
(assoc :ethereum/current-block blockNumber)
|
wallet/remove-transactions-since-block blockNumber)
|
||||||
(update-in [:wallet :accounts]
|
(transactions/update-fetching-status accounts :recent? false)
|
||||||
wallet/remove-transactions-since-block blockNumber)
|
(dissoc :wallet/waiting-for-recent-history?
|
||||||
(transactions/update-fetching-status accounts :recent? false)
|
:wallet/refreshing-history?
|
||||||
(dissoc :wallet/waiting-for-recent-history?
|
:wallet/fetching-error
|
||||||
:wallet/refreshing-history?
|
:wallet/recent-history-fetching-started?))
|
||||||
:wallet/fetching-error
|
:transactions/get-transfers
|
||||||
:wallet/recent-history-fetching-started?))
|
{:chain-tokens (:wallet/all-tokens db)
|
||||||
:transactions/get-transfers
|
:addresses (reduce
|
||||||
{:chain-tokens (:wallet/all-tokens db)
|
(fn [v address]
|
||||||
:addresses (reduce
|
(let [normalized-address
|
||||||
(fn [v address]
|
(eip55/address->checksum address)]
|
||||||
(let [normalized-address
|
(if (contains? v normalized-address)
|
||||||
(eip55/address->checksum address)]
|
v
|
||||||
(if (contains? v normalized-address)
|
(conj v address))))
|
||||||
v
|
[]
|
||||||
(conj v address))))
|
accounts)
|
||||||
[]
|
:before-block blockNumber
|
||||||
accounts)
|
:limit 20}})
|
||||||
:before-block blockNumber
|
|
||||||
:limit 20}}
|
|
||||||
(wallet.core/restart-wallet-service-default)))
|
|
||||||
|
|
||||||
(fx/defn fetching-error
|
(fx/defn fetching-error
|
||||||
[{:keys [db] :as cofx} {:keys [message]}]
|
[{:keys [db] :as cofx} {:keys [message]}]
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
(and logged-in? initialized?)
|
(and logged-in? initialized?)
|
||||||
[(mailserver/process-next-messages-request)
|
[(mailserver/process-next-messages-request)
|
||||||
(bottom-sheet/hide-bottom-sheet)
|
(bottom-sheet/hide-bottom-sheet)
|
||||||
(wallet/restart-wallet-service {:force-start? true})]
|
(wallet/restart-wallet-service nil)]
|
||||||
|
|
||||||
logged-in?
|
logged-in?
|
||||||
[(mailserver/process-next-messages-request)
|
[(mailserver/process-next-messages-request)
|
||||||
|
@ -69,7 +69,7 @@
|
||||||
:remember-syncing-choice? (boolean remember-choice?) {})
|
:remember-syncing-choice? (boolean remember-choice?) {})
|
||||||
(when (and cellular? sync?)
|
(when (and cellular? sync?)
|
||||||
(mailserver/process-next-messages-request))
|
(mailserver/process-next-messages-request))
|
||||||
(wallet/restart-wallet-service {:force-start? true}))))))
|
(wallet/restart-wallet-service nil))))))
|
||||||
|
|
||||||
(fx/defn mobile-network-continue-syncing
|
(fx/defn mobile-network-continue-syncing
|
||||||
{:events [:mobile-network/continue-syncing]}
|
{:events [:mobile-network/continue-syncing]}
|
||||||
|
|
|
@ -99,7 +99,7 @@
|
||||||
:else
|
:else
|
||||||
(wallet/update-balances nil scan-all-tokens?))
|
(wallet/update-balances nil scan-all-tokens?))
|
||||||
(when-not (get db :wallet/new-account)
|
(when-not (get db :wallet/new-account)
|
||||||
(wallet/restart-wallet-service {:force-start? true}))
|
(wallet/restart-wallet-service nil))
|
||||||
(when-not (utils.mobile-sync/syncing-allowed? cofx)
|
(when-not (utils.mobile-sync/syncing-allowed? cofx)
|
||||||
(transactions/get-fetched-transfers))
|
(transactions/get-fetched-transfers))
|
||||||
(prices/update-prices)))
|
(prices/update-prices)))
|
||||||
|
@ -359,8 +359,7 @@
|
||||||
:pin
|
:pin
|
||||||
:multiaccount)
|
:multiaccount)
|
||||||
(assoc :logged-in-since now)
|
(assoc :logged-in-since now)
|
||||||
(assoc :view-id :home)
|
(assoc :view-id :home))
|
||||||
(assoc :wallet/waiting-for-recent-history? true))
|
|
||||||
::json-rpc/call
|
::json-rpc/call
|
||||||
[{:method "web3_clientVersion"
|
[{:method "web3_clientVersion"
|
||||||
:on-success #(re-frame/dispatch [::initialize-web3-client-version %])}]}
|
:on-success #(re-frame/dispatch [::initialize-web3-client-version %])}]}
|
||||||
|
|
|
@ -564,11 +564,27 @@
|
||||||
:on-success #(log/info "[wallet] wallet_checkRecentHistory success")
|
:on-success #(log/info "[wallet] wallet_checkRecentHistory success")
|
||||||
:on-error #(log/error "[wallet] wallet_checkRecentHistory error" %)})))
|
:on-error #(log/error "[wallet] wallet_checkRecentHistory error" %)})))
|
||||||
|
|
||||||
|
(def ms-2-min (datetime/minutes 2))
|
||||||
|
(def ms-3-min (datetime/minutes 3))
|
||||||
|
(def ms-5-min (datetime/minutes 5))
|
||||||
(def ms-10-min (datetime/minutes 10))
|
(def ms-10-min (datetime/minutes 10))
|
||||||
(def ms-20-min (datetime/minutes 20))
|
(def ms-20-min (datetime/minutes 20))
|
||||||
|
|
||||||
(def ms-2-min (datetime/minutes 2))
|
(def custom-intervals
|
||||||
(def ms-4-min (datetime/minutes 4))
|
{:ms-2-min ms-2-min
|
||||||
|
:ms-3-min ms-3-min
|
||||||
|
:ms-5-min ms-5-min
|
||||||
|
:ms-10-min ms-10-min
|
||||||
|
:ms-20-min ms-20-min})
|
||||||
|
|
||||||
|
(def next-custom-interval
|
||||||
|
{:ms-2-min :ms-3-min
|
||||||
|
:ms-3-min :ms-5-min
|
||||||
|
:ms-5-min :ms-10-min})
|
||||||
|
|
||||||
|
(defn get-next-custom-interval
|
||||||
|
[{:keys [:wallet-service/custom-interval]}]
|
||||||
|
(get next-custom-interval custom-interval))
|
||||||
|
|
||||||
(defn get-max-block-with-transfer [db]
|
(defn get-max-block-with-transfer [db]
|
||||||
(reduce
|
(reduce
|
||||||
|
@ -580,13 +596,13 @@
|
||||||
nil
|
nil
|
||||||
(get-in db [:wallet :accounts])))
|
(get-in db [:wallet :accounts])))
|
||||||
|
|
||||||
(defn get-restart-interval
|
(defn get-restart-interval [db]
|
||||||
[db]
|
(let [max-block (get-max-block-with-transfer db)
|
||||||
(let [max-block (get-max-block-with-transfer db)]
|
custom-interval (get db :wallet-service/custom-interval)]
|
||||||
(cond
|
(cond
|
||||||
(ethereum/custom-rpc-node?
|
(ethereum/custom-rpc-node?
|
||||||
(ethereum/current-network db))
|
(ethereum/current-network db))
|
||||||
ms-4-min
|
ms-2-min
|
||||||
|
|
||||||
(and max-block
|
(and max-block
|
||||||
(zero? max-block)
|
(zero? max-block)
|
||||||
|
@ -594,7 +610,7 @@
|
||||||
(log/info "[wallet] No transactions found")
|
(log/info "[wallet] No transactions found")
|
||||||
|
|
||||||
:else
|
:else
|
||||||
ms-20-min)))
|
(get custom-intervals custom-interval ms-20-min))))
|
||||||
|
|
||||||
(defn get-watching-interval [db]
|
(defn get-watching-interval [db]
|
||||||
(if (ethereum/custom-rpc-node?
|
(if (ethereum/custom-rpc-node?
|
||||||
|
@ -607,40 +623,43 @@
|
||||||
(log/info "[wallet] after-checking-history")
|
(log/info "[wallet] after-checking-history")
|
||||||
{:db (dissoc db
|
{:db (dissoc db
|
||||||
:wallet/recent-history-fetching-started?
|
:wallet/recent-history-fetching-started?
|
||||||
:wallet/waiting-for-recent-history?
|
|
||||||
:wallet/refreshing-history?)})
|
:wallet/refreshing-history?)})
|
||||||
|
|
||||||
|
(defn set-timeout [db]
|
||||||
|
(when-let [interval (get-restart-interval db)]
|
||||||
|
(utils.utils/set-timeout
|
||||||
|
#(re-frame.core/dispatch [::restart])
|
||||||
|
interval)))
|
||||||
|
|
||||||
(fx/defn check-recent-history
|
(fx/defn check-recent-history
|
||||||
[{:keys [db] :as cofx} on-recent-history-fetching]
|
[{:keys [db] :as cofx}
|
||||||
|
{:keys [on-recent-history-fetching force-restart?]}]
|
||||||
(let [addresses (map :address (get db :multiaccount/accounts))
|
(let [addresses (map :address (get db :multiaccount/accounts))
|
||||||
old-timeout (get db :wallet-service/restart-timeout)
|
old-timeout (get db :wallet-service/restart-timeout)
|
||||||
timeout (when-let [interval (get-restart-interval db)]
|
timeout (if force-restart?
|
||||||
(utils.utils/set-timeout
|
old-timeout
|
||||||
#(re-frame.core/dispatch [::restart])
|
(set-timeout db))]
|
||||||
interval))]
|
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
(assoc :wallet-service/restart-timeout timeout
|
(assoc :wallet-service/restart-timeout timeout
|
||||||
|
:wallet-service/custom-interval (get-next-custom-interval db)
|
||||||
:wallet/was-started? true
|
:wallet/was-started? true
|
||||||
:wallet/on-recent-history-fetching on-recent-history-fetching))
|
:wallet/on-recent-history-fetching on-recent-history-fetching))
|
||||||
::check-recent-history addresses
|
::check-recent-history addresses
|
||||||
::utils.utils/clear-timeouts
|
::utils.utils/clear-timeouts
|
||||||
[old-timeout]}))
|
[(when (not= timeout old-timeout) old-timeout)]}))
|
||||||
|
|
||||||
(fx/defn restart-wallet-service
|
(fx/defn restart-wallet-service
|
||||||
[{:keys [db] :as cofx}
|
[{:keys [db] :as cofx}
|
||||||
{:keys [force-start? ignore-syncing-settings? on-recent-history-fetching]}]
|
{:keys [force-restart? on-recent-history-fetching]
|
||||||
(when (or force-start? (:multiaccount db))
|
:as params}]
|
||||||
(let [waiting? (get db :wallet/waiting-for-recent-history?)
|
(when (:multiaccount db)
|
||||||
syncing-allowed? (mobile-network-utils/syncing-allowed? cofx)]
|
(let [syncing-allowed? (mobile-network-utils/syncing-allowed? cofx)]
|
||||||
(log/info "restart-wallet-service"
|
(log/info "restart-wallet-service"
|
||||||
"force-start?" force-start?
|
"force-restart?" force-restart?
|
||||||
"syncing-allowed?" syncing-allowed?)
|
"syncing-allowed?" syncing-allowed?)
|
||||||
(if (and (or syncing-allowed?
|
(if (or syncing-allowed?
|
||||||
ignore-syncing-settings?)
|
force-restart?)
|
||||||
(or
|
(check-recent-history cofx params)
|
||||||
waiting?
|
|
||||||
force-start?))
|
|
||||||
(check-recent-history cofx on-recent-history-fetching)
|
|
||||||
(after-checking-history cofx)))))
|
(after-checking-history cofx)))))
|
||||||
|
|
||||||
(def background-cooldown-time (datetime/minutes 3))
|
(def background-cooldown-time (datetime/minutes 3))
|
||||||
|
@ -650,21 +669,14 @@
|
||||||
(when (and (get db :wallet/was-started?)
|
(when (and (get db :wallet/was-started?)
|
||||||
(> (- now background-time)
|
(> (- now background-time)
|
||||||
background-cooldown-time))
|
background-cooldown-time))
|
||||||
(restart-wallet-service
|
(restart-wallet-service cofx nil)))
|
||||||
cofx
|
|
||||||
{:force-start? true})))
|
|
||||||
|
|
||||||
(fx/defn restart-wallet-service-default
|
|
||||||
[cofx]
|
|
||||||
(restart-wallet-service cofx nil))
|
|
||||||
|
|
||||||
(fx/defn restart
|
(fx/defn restart
|
||||||
{:events [::restart]}
|
{:events [::restart]}
|
||||||
[{:keys [db] :as cofx} ignore-syncing-settings?]
|
[{:keys [db] :as cofx} force-restart?]
|
||||||
(restart-wallet-service
|
(restart-wallet-service
|
||||||
cofx
|
cofx
|
||||||
{:force-start? true
|
{:force-restart? force-restart?}))
|
||||||
:ignore-syncing-settings? ignore-syncing-settings?}))
|
|
||||||
|
|
||||||
(def pull-to-refresh-cooldown-period (* 1 60 1000))
|
(def pull-to-refresh-cooldown-period (* 1 60 1000))
|
||||||
|
|
||||||
|
@ -681,8 +693,7 @@
|
||||||
:wallet/last-pull-time now
|
:wallet/last-pull-time now
|
||||||
:wallet/refreshing-history? true)}
|
:wallet/refreshing-history? true)}
|
||||||
(restart-wallet-service
|
(restart-wallet-service
|
||||||
{:force-start? true
|
{:force-restart? true})))))
|
||||||
:ignore-syncing-settings? true})))))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::start-watching
|
::start-watching
|
||||||
|
@ -794,15 +805,14 @@
|
||||||
{:events [:wallet/keep-watching]}
|
{:events [:wallet/keep-watching]}
|
||||||
[{:keys [db now] :as cofx}]
|
[{:keys [db now] :as cofx}]
|
||||||
(let [non-empty-history? (get db :wallet/non-empty-tx-history?)
|
(let [non-empty-history? (get db :wallet/non-empty-tx-history?)
|
||||||
restart? (and (not (get db :wallet/non-empty-tx-history?))
|
old-timeout (get db :wallet-service/restart-timeout)
|
||||||
(not (get db :wallet-service/restart-timeout)))]
|
db (assoc db :wallet-service/custom-interval :ms-2-min)
|
||||||
(fx/merge
|
timeout (set-timeout db)]
|
||||||
cofx
|
{:db (assoc db
|
||||||
(when-not non-empty-history?
|
:wallet/keep-watching-until-ms (+ now (datetime/minutes 30))
|
||||||
{:db (assoc db :wallet/keep-watching-until-ms
|
:wallet-service/restart-timeout timeout
|
||||||
(+ now (datetime/minutes 30)))})
|
:wallet-service/custom-interval (get-next-custom-interval db))
|
||||||
(when restart?
|
::utils.utils/clear-timeouts [old-timeout]}))
|
||||||
(restart-wallet-service {:force-start? true})))))
|
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
::set-inital-range
|
::set-inital-range
|
||||||
|
@ -823,7 +833,7 @@
|
||||||
{:events [:wallet/tab-opened]}
|
{:events [:wallet/tab-opened]}
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db] :as cofx}]
|
||||||
(when-not (get db :wallet/was-started?)
|
(when-not (get db :wallet/was-started?)
|
||||||
(restart-wallet-service cofx {:force-start? true})))
|
(restart-wallet-service cofx nil)))
|
||||||
|
|
||||||
(fx/defn set-max-block [{:keys [db]} address block]
|
(fx/defn set-max-block [{:keys [db]} address block]
|
||||||
(log/debug "set-max-block"
|
(log/debug "set-max-block"
|
||||||
|
|
Loading…
Reference in New Issue