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

View File

@ -5,7 +5,8 @@
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[status-im.models.transactions :as transactions] [status-im.models.transactions :as transactions]
[status-im.node.core :as node] [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 (fx/defn logout
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
@ -14,7 +15,8 @@
:dev-server/stop nil} :dev-server/stop nil}
(transactions/stop-sync) (transactions/stop-sync)
(transport/stop-whisper (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 (fx/defn leave-account
[cofx] [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.node.core :as node]
[status-im.stickers.core :as stickers] [status-im.stickers.core :as stickers]
[status-im.utils.config :as config] [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 ;; init module
@ -170,10 +171,26 @@
(fn [cofx [_ dev-mode?]] (fn [cofx [_ dev-mode?]]
(accounts/switch-dev-mode 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 (handlers/register-handler-fx
:accounts.ui/chaos-mode-switched :accounts.ui/chaos-mode-switched
(fn [cofx [_ dev-mode?]] (fn [{:keys [db] :as cofx} [_ chaos-mode?]]
(accounts/switch-chaos-mode cofx dev-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 (handlers/register-handler-fx
:accounts.ui/notifications-enabled :accounts.ui/notifications-enabled
@ -384,7 +401,7 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:mailserver.ui/connect-pressed :mailserver.ui/connect-pressed
(fn [cofx [_ mailserver-id]] (fn [cofx [_ mailserver-id]]
(mailserver/show-connection-confirmation cofx mailserver-id))) (mailserver/show-connection-confirmation cofx mailserver-id)))
(handlers/register-handler-fx (handlers/register-handler-fx
@ -809,9 +826,9 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:chat.ui/set-command-parameter :chat.ui/set-command-parameter
(fn [{{:keys [chats current-chat-id chat-ui-props id->command access-scope->command-id]} :db :as cofx} [_ value]] (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) (let [current-chat (get chats current-chat-id)
selection (get-in chat-ui-props [current-chat-id :selection]) selection (get-in chat-ui-props [current-chat-id :selection])
commands (commands/chat-commands id->command access-scope->command-id current-chat) commands (commands/chat-commands id->command access-scope->command-id current-chat)
{:keys [current-param-position params]} (commands.input/selected-chat-command {:keys [current-param-position params]} (commands.input/selected-chat-command
(:input-text current-chat) selection commands) (:input-text current-chat) selection commands)
last-param-idx (dec (count params))] last-param-idx (dec (count params))]

View File

@ -13,7 +13,8 @@
[status-im.utils.handlers :as handlers] [status-im.utils.handlers :as handlers]
[status-im.utils.http :as http] [status-im.utils.http :as http]
[status-im.utils.types :as types] [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 (def url-regex
#"https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)") #"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 (fx/defn handle-network-status-change
[{:keys [db] :as cofx} {:keys [type] :as data}] [{:keys [db] :as cofx} {:keys [type] :as data}]
(fx/merge (let [old-network-type (:network/type db)]
cofx (fx/merge
{:db (assoc db :network/type type) cofx
:network/notify-status-go data} {:db (assoc db :network/type type)
(mobile-network/on-network-status-change))) :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 (re-frame/reg-fx
:network/listen-to-network-status :network/listen-to-network-status

View File

@ -102,10 +102,12 @@
([url on-success] (get url on-success nil)) ([url on-success] (get url on-success nil))
([url on-success on-error] ([url on-success on-error]
(get url on-success on-error nil)) (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 (-> (rn-dependencies/fetch url
(clj->js {:method "GET" (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)})) :timeout (or timeout-ms http-request-default-timeout-ms)}))
(.then (fn [response] (.then (fn [response]
(-> (->

View File

@ -1,7 +1,8 @@
(ns status-im.utils.utils (ns status-im.utils.utils
(:require [status-im.i18n :as i18n] (:require [status-im.i18n :as i18n]
[status-im.react-native.js-dependencies :as rn-dependencies] [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 (defn show-popup
([title content] ([title content]
@ -71,7 +72,9 @@
;; background-timer ;; background-timer
(defn set-timeout [cb ms] (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 (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" "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)))) (set-timeout #(re-frame/dispatch dispatch) ms))))
(defn clear-timeout [id] (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] (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] (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": "",
"status-not-sent-without-tap": "", "status-not-sent-without-tap": "",
"confirm-install": "Confirm Install", "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!"
} }