diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 0e5d232d83..8984090691 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -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") diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs index 99f1a7b302..1de47b22c7 100644 --- a/src/status_im/native_module/core.cljs +++ b/src/status_im/native_module/core.cljs @@ -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") diff --git a/src/status_im/utils/datetime.cljs b/src/status_im/utils/datetime.cljs index 1aae2105b1..3a2654bb62 100644 --- a/src/status_im/utils/datetime.cljs +++ b/src/status_im/utils/datetime.cljs @@ -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} diff --git a/src/status_im/wallet/core.cljs b/src/status_im/wallet/core.cljs index f63811ed5a..48658b88c5 100644 --- a/src/status_im/wallet/core.cljs +++ b/src/status_im/wallet/core.cljs @@ -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))