Devtools 3.0 support

This commit is contained in:
alwx 2017-05-16 16:24:51 +03:00 committed by Roman Volosovskyi
parent 0919b4364e
commit f165492b33
4 changed files with 30 additions and 22 deletions

View File

@ -372,8 +372,9 @@
(register-handler :upsert-chat! (register-handler :upsert-chat!
(fn [db [_ {:keys [chat-id] :as opts}]] (fn [db [_ {:keys [chat-id] :as opts}]]
(let [chat (if (chats/exists? chat-id) (let [chat (if (chats/exists? chat-id)
(let [chat (chats/get-by-id chat-id)] (-> (chats/get-by-id chat-id)
(assoc chat :timestamp (random/timestamp))) (assoc :timestamp (random/timestamp))
(merge opts))
(prepare-chat db chat-id opts))] (prepare-chat db chat-id opts))]
(chats/save chat) (chats/save chat)
(update-in db [:chats chat-id] merge chat)))) (update-in db [:chats chat-id] merge chat))))

View File

@ -15,7 +15,8 @@
[status-im.utils.js-resources :as js-res] [status-im.utils.js-resources :as js-res]
[status-im.utils.random :as random] [status-im.utils.random :as random]
[status-im.chat.sign-up :as sign-up] [status-im.chat.sign-up :as sign-up]
[status-im.bots.constants :as bots-constants])) [status-im.bots.constants :as bots-constants]
[status-im.utils.datetime :as time]))
(defn load-commands! (defn load-commands!

View File

@ -38,48 +38,53 @@
(register-handler :debug-request (register-handler :debug-request
(u/side-effect! (u/side-effect!
(fn [{:keys [web3]} [_ {url :url (fn [{:keys [web3]} [_ {url :url
{:keys [encoded]} :postData :as d}]] {:keys [encoded]} :postData}]]
(try (try
(let [json (->> (.toAscii web3 encoded) (let [json (->> (.toAscii web3 encoded)
(.parse js/JSON)) (.parse js/JSON))
obj (js->clj json :keywordize-keys true)] obj (js->clj json :keywordize-keys true)]
(case url (case url
"/add-dapp" (dispatch [:debug-add-dapp obj]) "/add-dapp" (dispatch [:debug-add-contact obj])
"/remove-dapp" (dispatch [:debug-remove-dapp obj]) "/remove-dapp" (dispatch [:debug-remove-contact obj])
"/dapp-changed" (dispatch [:debug-dapp-changed obj]) "/dapp-changed" (dispatch [:debug-contact-changed obj])
"/switch-node" (dispatch [:debug-switch-node obj]) "/switch-node" (dispatch [:debug-switch-node obj])
:default)) :default))
(catch js/Error e (catch js/Error e
(log/debug "Error: " e)))))) (log/debug "Error: " e))))))
(register-handler :debug-add-dapp (register-handler :debug-add-contact
(u/side-effect! (u/side-effect!
(fn [{:keys [contacts]} [_ {:keys [name whisper-identity dapp-url] :as dapp-data}]] (fn [{:keys [contacts]} [_ {:keys [name whisper-identity dapp-url bot-url] :as dapp-data}]]
(when (and name (when (and name
whisper-identity whisper-identity
dapp-url (or dapp-url bot-url)
(or (not (get contacts whisper-identity)) (or (not (get contacts whisper-identity))
(get-in contacts [whisper-identity :debug?]))) (get-in contacts [whisper-identity :debug?])))
(let [dapp (merge dapp-data {:dapp? true (let [dapp (merge dapp-data {:dapp? true
:debug? true})] :debug? true})]
(dispatch [:add-chat whisper-identity {:name name (dispatch [:upsert-chat! {:chat-id whisper-identity
:debug? true}]) :name name
(dispatch [:add-contacts [dapp]])))))) :debug? true}])
(if (get contacts whisper-identity)
(dispatch [:update-contact! dapp])
(dispatch [:add-contacts [dapp]])))))))
(register-handler :debug-remove-dapp (register-handler :debug-remove-contact
(u/side-effect! (u/side-effect!
(fn [{:keys [chats]} [_ {:keys [whisper-identity]}]] (fn [{:keys [chats]} [_ {:keys [whisper-identity]}]]
(when (get-in chats [whisper-identity :debug?]) (when (get-in chats [whisper-identity :debug?])
(dispatch [:remove-chat whisper-identity])) (dispatch [:remove-chat whisper-identity]))
(dispatch [:remove-contact whisper-identity #(and (:dapp? %) (:debug? %))])))) (dispatch [:remove-contact whisper-identity #(and (:dapp? %) (:debug? %))]))))
(register-handler :debug-dapp-changed (register-handler :debug-contact-changed
(u/side-effect! (u/side-effect!
(fn [{:keys [webview-bridge current-chat-id chats]} [_ {:keys [whisper-identity]}]] (fn [{:keys [webview-bridge current-chat-id contacts]} [_ {:keys [whisper-identity] :as dapp-data}]]
(when (and (= current-chat-id whisper-identity) (when (get-in contacts [whisper-identity :debug?])
(get-in chats [whisper-identity :debug?]) (when (and (= current-chat-id whisper-identity)
webview-bridge) webview-bridge)
(.reload webview-bridge))))) (.reload webview-bridge))
(when (get-in contacts [whisper-identity :bot-url])
(dispatch [:load-commands! whisper-identity]))))))
(register-handler :debug-switch-node (register-handler :debug-switch-node
(u/side-effect! (u/side-effect!

View File

@ -43,7 +43,8 @@
([url on-success on-error] ([url on-success on-error]
(http-get url nil on-success on-error)) (http-get url nil on-success on-error))
([url valid-response? on-success on-error] ([url valid-response? on-success on-error]
(-> (.fetch js/window url (clj->js {:method "GET"})) (-> (.fetch js/window url (clj->js {:method "GET"
:headers {"Cache-Control" "no-cache"}}))
(.then (fn [response] (.then (fn [response]
(log response) (log response)
(let [ok? (.-ok response) (let [ok? (.-ok response)