[wallet] Watch txs history while app is in the background (Android only)

This commit is contained in:
Roman Volosovskyi 2020-12-10 18:02:45 +02:00
parent 8748280279
commit c33e2be76b
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
4 changed files with 26 additions and 13 deletions

View File

@ -1191,19 +1191,16 @@
(dissoc :app-in-background-since)
(assoc :app-active-since now))}
(mailserver/process-next-messages-request)
(wallet/restart-wallet-service {:force-start? true})
(wallet/restart-wallet-service-after-background app-in-background-since)
#(when requires-bio-auth
(biometric/authenticate % on-biometric-auth-result authentication-options)))))
(fx/defn on-going-in-background
[{:keys [db now] :as cofx}]
(fx/merge
cofx
{:db (-> db
(dissoc :app-active-since)
(assoc :app-in-background-since now))
:dispatch-n [[:audio-recorder/on-background] [:audio-message/on-background]]}
(wallet/clear-timeouts)))
{:db (-> db
(dissoc :app-active-since)
(assoc :app-in-background-since now))
:dispatch-n [[:audio-recorder/on-background] [:audio-message/on-background]]})
(defn app-state-change [state {:keys [db] :as cofx}]
(let [app-coming-from-background? (= state "active")

View File

@ -269,7 +269,8 @@
(defn start-wallet [watch-new-blocks?]
(log/debug "[native-module] start-wallet" watch-new-blocks?)
(.startWallet ^js (status) watch-new-blocks?))
(when (status)
(.startWallet ^js (status) watch-new-blocks?)))
(defn stop-local-notifications []
(log/debug "[native-module] stop-local-notifications")

View File

@ -13,8 +13,12 @@
(defn now []
(t/now))
(def hour (* 1000 60 60))
(def day (* hour 24))
(def one-second 1000)
(def minute (* 60 one-second))
(defn minutes [m]
(* m minute))
(def hour (* 60 minute))
(def day (* 24 hour))
(def week (* 7 day))
(def units [{:name :t/datetime-second-short :limit 60 :in-second 1}
{:name :t/datetime-minute-short :limit 3600 :in-second 60}

View File

@ -24,6 +24,7 @@
[status-im.wallet.utils :as wallet.utils]
[status-im.native-module.core :as status]
[status-im.ui.screens.mobile-network-settings.utils :as mobile-network-utils]
[status-im.utils.datetime :as datetime]
status-im.wallet.recipient.core))
(defn get-balance
@ -543,8 +544,8 @@
(log/info "start-wallet fx" watch-new-blocks?)
(status/start-wallet watch-new-blocks?)))
(def ms-10-min (* 10 60 1000))
(def ms-20-min (* 20 60 1000))
(def ms-10-min (datetime/minutes 10))
(def ms-20-min (datetime/minutes 20))
(fx/defn stop-wallet
[{:keys [db] :as cofx}]
@ -595,6 +596,16 @@
(start-wallet cofx (boolean (or watch-new-blocks? watching-txs?)))
(stop-wallet cofx)))))
(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)
(restart-wallet-service
cofx
{:force-start? true})))
(fx/defn restart-wallet-service-default
[cofx]
(restart-wallet-service cofx nil))