Request if chaos mode was enabled

This commit is contained in:
Roman Volosovskyi 2019-03-19 14:24:57 +02:00
parent 4e942a169a
commit 6a3468c800
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
8 changed files with 109 additions and 24 deletions

View File

@ -17,7 +17,8 @@
[status-im.models.transactions :as transactions]
[status-im.i18n :as i18n]
[status-im.node.core :as node]
[status-im.ui.screens.mobile-network-settings.events :as mobile-network]))
[status-im.ui.screens.mobile-network-settings.events :as mobile-network]
[status-im.chaos-mode.core :as chaos-mode]))
(defn login! [address password]
(status/login address password #(re-frame/dispatch [:accounts.login.callback/login-success %])))
@ -113,6 +114,7 @@
(mobile-network/on-network-status-change)
(protocol/initialize-protocol)
(universal-links/process-stored-event)
(chaos-mode/check-chaos-mode)
#(when-not platform/desktop?
(initialize-wallet %)))
(account-and-db-password-do-not-match cofx error)))))

View File

@ -5,7 +5,8 @@
[status-im.utils.fx :as fx]
[status-im.models.transactions :as transactions]
[status-im.node.core :as node]
[status-im.init.core :as init]))
[status-im.init.core :as init]
[status-im.chaos-mode.core :as chaos-mode]))
(fx/defn logout
[{:keys [db] :as cofx}]
@ -14,7 +15,8 @@
:dev-server/stop nil}
(transactions/stop-sync)
(transport/stop-whisper
#(re-frame/dispatch [:accounts.logout/filters-removed]))))
#(re-frame/dispatch [:accounts.logout/filters-removed]))
(chaos-mode/stop-checking)))
(fx/defn leave-account
[cofx]

View File

@ -0,0 +1,46 @@
(ns status-im.chaos-mode.core
(:require [status-im.utils.fx :as fx]
[re-frame.core :as re-frame]
[status-im.utils.utils :as utils]
[status-im.utils.http :as http]
[status-im.utils.types :as types]))
(def interval-5m (* 5 60 1000))
(defonce interval-id (atom nil))
(def url "https://cloudflare-dns.com/dns-query?name=chaos-unicorn-day.status.im&type=TXT")
(defn chaos-mode-switched [chaos-mode?]
(re-frame/dispatch [:accounts.ui/chaos-mode-switched chaos-mode?]))
(defn handle-response [response]
(let [status-id (:Status (types/json->clj response))
chaos-mode? (zero? status-id)]
(chaos-mode-switched chaos-mode?)))
(defn check-record []
(http/get url
handle-response
(fn [])
nil
{"accept" "application/dns-json"}))
(re-frame/reg-fx
:chaos-mode/start-checking
(fn []
(when @interval-id
(utils/clear-interval @interval-id))
(check-record)
(reset!
interval-id
(utils/set-interval check-record interval-5m))))
(re-frame/reg-fx
:chaos-mode/stop-checking
(fn []
(utils/clear-interval @interval-id)))
(fx/defn check-chaos-mode [_]
{:chaos-mode/start-checking nil})
(fx/defn stop-checking [_]
{:chaos-mode/stop-checking nil})

View File

@ -52,7 +52,8 @@
[status-im.node.core :as node]
[status-im.stickers.core :as stickers]
[status-im.utils.config :as config]
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]))
[status-im.ui.components.bottom-sheet.core :as bottom-sheet]
[status-im.ui.components.react :as react]))
;; init module
@ -170,10 +171,26 @@
(fn [cofx [_ dev-mode?]]
(accounts/switch-dev-mode cofx dev-mode?)))
(def CUD-url "https://chaos-unicorn-day.org")
(defn open-chaos-unicorn-day-link []
(.openURL react/linking CUD-url))
(handlers/register-handler-fx
:accounts.ui/chaos-mode-switched
(fn [cofx [_ dev-mode?]]
(accounts/switch-chaos-mode cofx dev-mode?)))
(fn [{:keys [db] :as cofx} [_ chaos-mode?]]
(let [old-chaos-mode? (get-in db [:account/account :settings :chaos-mode?])]
(when (not= old-chaos-mode? chaos-mode?)
(fx/merge
cofx
(when chaos-mode?
{:ui/show-confirmation
{:title (i18n/label :t/chaos-unicorn-day)
:content (i18n/label :t/chaos-unicorn-day-details)
:confirm-button-text (i18n/label :t/see-details)
:cancel-button-text (i18n/label :t/cancel)
:on-accept open-chaos-unicorn-day-link}})
(accounts/switch-chaos-mode chaos-mode?))))))
(handlers/register-handler-fx
:accounts.ui/notifications-enabled
@ -384,7 +401,7 @@
(handlers/register-handler-fx
:mailserver.ui/connect-pressed
(fn [cofx [_ mailserver-id]]
(fn [cofx [_ mailserver-id]]
(mailserver/show-connection-confirmation cofx mailserver-id)))
(handlers/register-handler-fx
@ -809,9 +826,9 @@
(handlers/register-handler-fx
:chat.ui/set-command-parameter
(fn [{{:keys [chats current-chat-id chat-ui-props id->command access-scope->command-id]} :db :as cofx} [_ value]]
(let [current-chat (get chats current-chat-id)
selection (get-in chat-ui-props [current-chat-id :selection])
commands (commands/chat-commands id->command access-scope->command-id current-chat)
(let [current-chat (get chats current-chat-id)
selection (get-in chat-ui-props [current-chat-id :selection])
commands (commands/chat-commands id->command access-scope->command-id current-chat)
{:keys [current-param-position params]} (commands.input/selected-chat-command
(:input-text current-chat) selection commands)
last-param-idx (dec (count params))]

View File

@ -13,7 +13,8 @@
[status-im.utils.handlers :as handlers]
[status-im.utils.http :as http]
[status-im.utils.types :as types]
[status-im.ui.screens.mobile-network-settings.events :as mobile-network]))
[status-im.ui.screens.mobile-network-settings.events :as mobile-network]
[status-im.chaos-mode.core :as chaos-mode]))
(def url-regex
#"https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)")
@ -239,11 +240,14 @@
(fx/defn handle-network-status-change
[{:keys [db] :as cofx} {:keys [type] :as data}]
(fx/merge
cofx
{:db (assoc db :network/type type)
:network/notify-status-go data}
(mobile-network/on-network-status-change)))
(let [old-network-type (:network/type db)]
(fx/merge
cofx
{:db (assoc db :network/type type)
:network/notify-status-go data}
(when (= "none" old-network-type)
(chaos-mode/check-chaos-mode))
(mobile-network/on-network-status-change))))
(re-frame/reg-fx
:network/listen-to-network-status

View File

@ -102,10 +102,12 @@
([url on-success] (get url on-success nil))
([url on-success on-error]
(get url on-success on-error nil))
([url on-success on-error {:keys [valid-response? timeout-ms]}]
([url on-success on-error params]
(get url on-success on-error params nil))
([url on-success on-error {:keys [valid-response? timeout-ms]} headers]
(-> (rn-dependencies/fetch url
(clj->js {:method "GET"
:headers {"Cache-Control" "no-cache"}
:headers (merge {"Cache-Control" "no-cache"} headers)
:timeout (or timeout-ms http-request-default-timeout-ms)}))
(.then (fn [response]
(->

View File

@ -1,7 +1,8 @@
(ns status-im.utils.utils
(:require [status-im.i18n :as i18n]
[status-im.react-native.js-dependencies :as rn-dependencies]
[re-frame.core :as re-frame]))
[re-frame.core :as re-frame]
[status-im.utils.platform :as platform]))
(defn show-popup
([title content]
@ -71,7 +72,9 @@
;; background-timer
(defn set-timeout [cb ms]
(.setTimeout rn-dependencies/background-timer cb ms))
(if platform/desktop?
(js/setTimeout cb ms)
(.setTimeout rn-dependencies/background-timer cb ms)))
(defn unread-messages-count
"display actual # if less than 1K, round to the lowest thousand if between 1 and 10K, otherwise 10K+ for anything larger"
@ -94,10 +97,16 @@
(set-timeout #(re-frame/dispatch dispatch) ms))))
(defn clear-timeout [id]
(.clearTimeout rn-dependencies/background-timer id))
(if platform/desktop?
(js/clearTimeout id)
(.clearTimeout rn-dependencies/background-timer id)))
(defn set-interval [cb ms]
(.setInterval rn-dependencies/background-timer cb ms))
(if platform/desktop?
(js/setInterval cb ms)
(.setInterval rn-dependencies/background-timer cb ms)))
(defn clear-interval [id]
(.clearInterval rn-dependencies/background-timer id))
(if platform/desktop?
(js/clearInterval id)
(.clearInterval rn-dependencies/background-timer id)))

View File

@ -981,5 +981,8 @@
"status-not-sent": "",
"status-not-sent-without-tap": "",
"confirm-install": "Confirm Install",
"extension-install-alert": "Development mode is required to install an extension. Do you want to enable and continue installing?"
"extension-install-alert": "Development mode is required to install an extension. Do you want to enable and continue installing?",
"see-details": "See details",
"chaos-unicorn-day": "Chaos Unicorn Day",
"chaos-unicorn-day-details": "\uD83E\uDD84\uD83E\uDD84\uD83E\uDD84\uD83E\uDD84\uD83E\uDD84\uD83E\uDD84\uD83E\uDD84\uD83D\uDE80!"
}