Support for status-dev-cli 3.2.0 — NDS, responses and 3 more commands
This commit is contained in:
parent
edd191b705
commit
1b2f657bfb
|
@ -57,7 +57,7 @@
|
|||
"react-native-emoji-picker": "git+https://github.com/alwx/react-native-emoji-picker.git",
|
||||
"react-native-fs": "2.1.0-rc.1",
|
||||
"react-native-http": "github:tradle/react-native-http#834492d",
|
||||
"react-native-http-bridge": "^0.3.0",
|
||||
"react-native-http-bridge": "^0.4.1",
|
||||
"react-native-i18n": "0.0.8",
|
||||
"react-native-image-crop-picker": "^0.12.10",
|
||||
"react-native-image-resizer": "^0.1.0",
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[status-im.constants :refer [console-chat-id
|
||||
wallet-chat-id
|
||||
text-content-type
|
||||
content-type-log-message
|
||||
content-type-command
|
||||
content-type-command-request
|
||||
default-number-of-messages] :as c]
|
||||
|
@ -202,7 +203,7 @@
|
|||
|
||||
(register-handler :received-bot-response
|
||||
(u/side-effect!
|
||||
(fn [_ [_ {:keys [chat-id] :as params} {:keys [result] :as data}]]
|
||||
(fn [{:keys [contacts]} [_ {:keys [chat-id] :as params} {:keys [result] :as data}]]
|
||||
(let [{:keys [returned context]} result
|
||||
{:keys [markup text-message err]} returned
|
||||
{:keys [log-messages update-db default-db]} context
|
||||
|
@ -215,11 +216,13 @@
|
|||
:default-db default-db)])
|
||||
(doseq [message log-messages]
|
||||
(let [{:keys [message type]} message]
|
||||
(when (or (not= type "debug") js/goog.DEBUG)
|
||||
(when (or (not= type "debug")
|
||||
js/goog.DEBUG
|
||||
(get-in contacts [chat-id :debug?]))
|
||||
(dispatch [:received-message
|
||||
{:message-id (random/id)
|
||||
:content (str type ": " message)
|
||||
:content-type text-content-type
|
||||
:content-type content-type-log-message
|
||||
:outgoing false
|
||||
:chat-id chat-id
|
||||
:from chat-id
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
[status-im.constants :refer [console-chat-id
|
||||
wallet-chat-id
|
||||
text-content-type
|
||||
content-type-log-message
|
||||
content-type-status
|
||||
content-type-command
|
||||
content-type-command-request] :as c]
|
||||
|
@ -225,6 +226,10 @@
|
|||
[wrapper message]
|
||||
[wrapper message [text-message message]])
|
||||
|
||||
(defmethod message-content content-type-log-message
|
||||
[wrapper message]
|
||||
[wrapper message [text-message message]])
|
||||
|
||||
(defmethod message-content content-type-status
|
||||
[_ message]
|
||||
[message-content-status message])
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
;; (def server-address "http://localhost:3000/")
|
||||
|
||||
(def text-content-type "text/plain")
|
||||
(def content-type-log-message "log-message")
|
||||
(def content-type-command "command")
|
||||
(def content-type-command-request "command-request")
|
||||
(def content-type-wallet-command "wallet-command")
|
||||
|
|
|
@ -79,6 +79,12 @@
|
|||
(clojure.core/update message :content str-to-map)
|
||||
message))))))
|
||||
|
||||
(defn get-log-messages
|
||||
[chat-id]
|
||||
(->> (data-store/get-by-chat-id chat-id 0 100)
|
||||
(filter #(= (:content-type %) c/content-type-log-message))
|
||||
(map #(select-keys % [:content :timestamp]))))
|
||||
|
||||
(defn get-last-message
|
||||
[chat-id]
|
||||
(if-let [{:keys [content-type] :as message} (data-store/get-last-message chat-id)]
|
||||
|
|
|
@ -2,11 +2,20 @@
|
|||
(:require [re-frame.core :refer [after dispatch]]
|
||||
[status-im.utils.handlers :refer [register-handler] :as u]
|
||||
[status-im.components.react :refer [http-bridge]]
|
||||
[status-im.components.status :refer [cljs->json]]
|
||||
[status-im.data-store.messages :as messages]
|
||||
[status-im.data-store.accounts :as accounts]
|
||||
[taoensso.timbre :as log]))
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.utils.platform :as platform]))
|
||||
|
||||
(def debug-server-port 5561)
|
||||
|
||||
(defn respond [data]
|
||||
(.respond http-bridge
|
||||
200
|
||||
"application/json"
|
||||
(cljs->json data)))
|
||||
|
||||
(register-handler :init-debug-mode
|
||||
(u/side-effect!
|
||||
(fn [_ [_ address]]
|
||||
|
@ -19,6 +28,9 @@
|
|||
(fn [_]
|
||||
(.start http-bridge
|
||||
debug-server-port
|
||||
(if platform/ios?
|
||||
"Status iOS"
|
||||
"Status Android")
|
||||
(fn [req]
|
||||
(try
|
||||
(let [{:keys [postData url]} (js->clj req :keywordize-keys true)
|
||||
|
@ -38,43 +50,65 @@
|
|||
(register-handler :debug-request
|
||||
(u/side-effect!
|
||||
(fn [{:keys [web3]} [_ {url :url
|
||||
{:keys [encoded]} :postData}]]
|
||||
{:keys [encoded]
|
||||
:as post-data} :postData}]]
|
||||
(try
|
||||
(let [json (->> (.toAscii web3 encoded)
|
||||
(let [json (some->> encoded
|
||||
(.toAscii web3)
|
||||
(.parse js/JSON))
|
||||
obj (js->clj json :keywordize-keys true)]
|
||||
obj (when json
|
||||
(js->clj json :keywordize-keys true))]
|
||||
(case url
|
||||
"/add-dapp" (dispatch [:debug-add-contact obj])
|
||||
"/remove-dapp" (dispatch [:debug-remove-contact obj])
|
||||
"/dapp-changed" (dispatch [:debug-contact-changed obj])
|
||||
"/switch-node" (dispatch [:debug-switch-node obj])
|
||||
"/list" (dispatch [:debug-dapps-list])
|
||||
"/log" (dispatch [:debug-log post-data])
|
||||
:default))
|
||||
(catch js/Error e
|
||||
(respond {:type :error :text (str "Error: " e)})
|
||||
(log/debug "Error: " e))))))
|
||||
|
||||
(register-handler :debug-add-contact
|
||||
(u/side-effect!
|
||||
(fn [{:keys [contacts]} [_ {:keys [name whisper-identity dapp-url bot-url] :as dapp-data}]]
|
||||
(when (and name
|
||||
(if (and name
|
||||
whisper-identity
|
||||
(or dapp-url bot-url)
|
||||
(or (not (get contacts whisper-identity))
|
||||
(get-in contacts [whisper-identity :debug?])))
|
||||
(or dapp-url bot-url))
|
||||
(if (or (not (get contacts whisper-identity))
|
||||
(get-in contacts [whisper-identity :debug?]))
|
||||
(let [dapp (merge dapp-data {:dapp? true
|
||||
:debug? true})]
|
||||
(dispatch [:upsert-chat! {:chat-id whisper-identity
|
||||
:name name
|
||||
:debug? true}])
|
||||
(if (get contacts whisper-identity)
|
||||
(dispatch [:update-contact! dapp])
|
||||
(do (dispatch [:update-contact! dapp])
|
||||
(respond {:type :ok
|
||||
:text "The DApp or bot has been updated."}))
|
||||
(do (dispatch [:add-contacts [dapp]])
|
||||
(dispatch [:open-chat-with-contact dapp]))))))))
|
||||
(dispatch [:open-chat-with-contact dapp])
|
||||
(respond {:type :ok
|
||||
:text "The DApp or bot has been added."}))))
|
||||
(respond {:type :error
|
||||
:text "Your DApp or bot should be debuggable."}))
|
||||
(respond {:type :error
|
||||
:text (str "You can add either DApp or bot. The object should contain \"name\", "
|
||||
"\"whisper-identity\", and \"dapp-url\" or \"bot-url\" fields.")})))))
|
||||
|
||||
(register-handler :debug-remove-contact
|
||||
(u/side-effect!
|
||||
(fn [{:keys [chats]} [_ {:keys [whisper-identity]}]]
|
||||
(when (get-in chats [whisper-identity :debug?])
|
||||
(dispatch [:remove-chat whisper-identity]))
|
||||
(if (get chats whisper-identity)
|
||||
(if (get-in chats [whisper-identity :debug?])
|
||||
(do (dispatch [:remove-chat whisper-identity])
|
||||
(respond {:type :ok
|
||||
:text "The DApp or bot has been removed."}))
|
||||
(respond {:type :error
|
||||
:text "Your DApp or bot should be debuggable."}))
|
||||
(respond {:type :error
|
||||
:text "There is no such DApp or bot."}))
|
||||
(dispatch [:remove-contact whisper-identity #(and (:dapp? %) (:debug? %))]))))
|
||||
|
||||
(register-handler :debug-contact-changed
|
||||
|
@ -85,10 +119,37 @@
|
|||
webview-bridge)
|
||||
(.reload webview-bridge))
|
||||
(when (get-in contacts [whisper-identity :bot-url])
|
||||
(dispatch [:load-commands! whisper-identity]))))))
|
||||
(dispatch [:load-commands! whisper-identity])))
|
||||
(respond {:type :ok
|
||||
:text "Command has been executed."}))))
|
||||
|
||||
(register-handler :debug-switch-node
|
||||
(u/side-effect!
|
||||
(fn [{:keys [current-account-id]} [_ {:keys [url]}]]
|
||||
(dispatch [:initialize-protocol current-account-id url]))))
|
||||
(dispatch [:initialize-protocol current-account-id url])
|
||||
(respond {:type :ok
|
||||
:text "You've successfully switched the node."}))))
|
||||
|
||||
(register-handler :debug-dapps-list
|
||||
(u/side-effect!
|
||||
(fn [{:keys [contacts]}]
|
||||
(let [contacts (->> (vals contacts)
|
||||
(filter :debug?)
|
||||
(map #(select-keys % [:name :whisper-identity :dapp-url :bot-url])))]
|
||||
(if (seq contacts)
|
||||
(respond {:type :ok
|
||||
:data contacts})
|
||||
(respond {:type :error
|
||||
:text "No DApps or bots found."}))))))
|
||||
|
||||
(register-handler :debug-log
|
||||
(u/side-effect!
|
||||
(fn [db [_ {:keys [identity]}]]
|
||||
(let [log (messages/get-log-messages identity)]
|
||||
(if (seq log)
|
||||
(respond {:type :ok
|
||||
:data log})
|
||||
(respond {:type :error
|
||||
:text "No log messages found."}))))))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue