Fix network status change logic and #8951

This commit is contained in:
acolytec3 2019-10-11 14:23:14 -04:00 committed by Roman Volosovskyi
parent eb00df147d
commit 33af176246
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
1 changed files with 10 additions and 5 deletions

View File

@ -7,12 +7,16 @@
[status-im.mailserver.core :as mailserver] [status-im.mailserver.core :as mailserver]
[status-im.chaos-mode.core :as chaos-mode] [status-im.chaos-mode.core :as chaos-mode]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.ui.screens.mobile-network-settings.events :as mobile-network])) [status-im.ui.screens.mobile-network-settings.events :as mobile-network]
[status-im.wallet.core :as wallet]))
(fx/defn change-network-status (fx/defn change-network-status
[{:keys [db] :as cofx} is-connected?] [{:keys [db] :as cofx} is-connected?]
(fx/merge cofx (fx/merge cofx
{:db (assoc db :network-status (if is-connected? :online :offline))} {:db (assoc db :network-status (if is-connected? :online :offline))}
(when is-connected?
(if-not (= (count (get-in db [:wallet :accounts])) (count (get-in db [:multiaccount :accounts])))
(wallet/update-balances nil)))
(mailserver/network-connection-status-changed is-connected?))) (mailserver/network-connection-status-changed is-connected?)))
(fx/defn change-network-type (fx/defn change-network-type
@ -26,12 +30,13 @@
(fx/defn handle-network-info-change (fx/defn handle-network-info-change
{:events [::network-info-changed]} {:events [::network-info-changed]}
[{:keys [db] :as cofx} {:keys [is-connected type details] :as state}] [{:keys [db] :as cofx} {:keys [isConnected type details] :as state}]
(let [old-network-status (:network-status db) (let [old-network-status (:network-status db)
old-network-type (:network/type db)] old-network-type (:network/type db)
connectivity-status (if isConnected :online :offline)]
(fx/merge cofx (fx/merge cofx
(when-not (= is-connected old-network-status) (when-not (= connectivity-status old-network-status)
(change-network-status is-connected)) (change-network-status isConnected))
(when-not (= type old-network-type) (when-not (= type old-network-type)
(change-network-type old-network-type type (:is-connection-expensive details)))))) (change-network-type old-network-type type (:is-connection-expensive details))))))