Skip to content

Commit

Permalink
Fix network status change logic and status-im#8951
Browse files Browse the repository at this point in the history
  • Loading branch information
acolytec3 committed Oct 24, 2019
1 parent 9cd8913 commit b9afe7c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/status_im/network/net_info.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
[status-im.mailserver.core :as mailserver]
[status-im.chaos-mode.core :as chaos-mode]
[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
[{: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-in db [:multiaccount :accounts])))
(wallet/update-balances nil)))
(mailserver/network-connection-status-changed is-connected?)))

(fx/defn change-network-type
Expand All @@ -26,12 +30,13 @@

(fx/defn handle-network-info-change
{: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)
old-network-type (:network/type db)]
old-network-type (:network/type db)
connectivity-status (if isConnected :online :offline)]
(fx/merge cofx
(when-not (= is-connected old-network-status)
(change-network-status is-connected))
(when-not (= connectivity-status old-network-status)
(change-network-status isConnected))
(when-not (= type old-network-type)
(change-network-type old-network-type type (:is-connection-expensive details))))))

Expand Down

0 comments on commit b9afe7c

Please sign in to comment.