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-emoji-picker": "git+https://github.com/alwx/react-native-emoji-picker.git",
|
||||||
"react-native-fs": "2.1.0-rc.1",
|
"react-native-fs": "2.1.0-rc.1",
|
||||||
"react-native-http": "github:tradle/react-native-http#834492d",
|
"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-i18n": "0.0.8",
|
||||||
"react-native-image-crop-picker": "^0.12.10",
|
"react-native-image-crop-picker": "^0.12.10",
|
||||||
"react-native-image-resizer": "^0.1.0",
|
"react-native-image-resizer": "^0.1.0",
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
[status-im.constants :refer [console-chat-id
|
[status-im.constants :refer [console-chat-id
|
||||||
wallet-chat-id
|
wallet-chat-id
|
||||||
text-content-type
|
text-content-type
|
||||||
|
content-type-log-message
|
||||||
content-type-command
|
content-type-command
|
||||||
content-type-command-request
|
content-type-command-request
|
||||||
default-number-of-messages] :as c]
|
default-number-of-messages] :as c]
|
||||||
|
@ -202,7 +203,7 @@
|
||||||
|
|
||||||
(register-handler :received-bot-response
|
(register-handler :received-bot-response
|
||||||
(u/side-effect!
|
(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
|
(let [{:keys [returned context]} result
|
||||||
{:keys [markup text-message err]} returned
|
{:keys [markup text-message err]} returned
|
||||||
{:keys [log-messages update-db default-db]} context
|
{:keys [log-messages update-db default-db]} context
|
||||||
|
@ -215,11 +216,13 @@
|
||||||
:default-db default-db)])
|
:default-db default-db)])
|
||||||
(doseq [message log-messages]
|
(doseq [message log-messages]
|
||||||
(let [{:keys [message type]} message]
|
(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
|
(dispatch [:received-message
|
||||||
{:message-id (random/id)
|
{:message-id (random/id)
|
||||||
:content (str type ": " message)
|
:content (str type ": " message)
|
||||||
:content-type text-content-type
|
:content-type content-type-log-message
|
||||||
:outgoing false
|
:outgoing false
|
||||||
:chat-id chat-id
|
:chat-id chat-id
|
||||||
:from chat-id
|
:from chat-id
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
[status-im.constants :refer [console-chat-id
|
[status-im.constants :refer [console-chat-id
|
||||||
wallet-chat-id
|
wallet-chat-id
|
||||||
text-content-type
|
text-content-type
|
||||||
|
content-type-log-message
|
||||||
content-type-status
|
content-type-status
|
||||||
content-type-command
|
content-type-command
|
||||||
content-type-command-request] :as c]
|
content-type-command-request] :as c]
|
||||||
|
@ -225,6 +226,10 @@
|
||||||
[wrapper message]
|
[wrapper message]
|
||||||
[wrapper message [text-message 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
|
(defmethod message-content content-type-status
|
||||||
[_ message]
|
[_ message]
|
||||||
[message-content-status message])
|
[message-content-status message])
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
;; (def server-address "http://localhost:3000/")
|
;; (def server-address "http://localhost:3000/")
|
||||||
|
|
||||||
(def text-content-type "text/plain")
|
(def text-content-type "text/plain")
|
||||||
|
(def content-type-log-message "log-message")
|
||||||
(def content-type-command "command")
|
(def content-type-command "command")
|
||||||
(def content-type-command-request "command-request")
|
(def content-type-command-request "command-request")
|
||||||
(def content-type-wallet-command "wallet-command")
|
(def content-type-wallet-command "wallet-command")
|
||||||
|
|
|
@ -79,6 +79,12 @@
|
||||||
(clojure.core/update message :content str-to-map)
|
(clojure.core/update message :content str-to-map)
|
||||||
message))))))
|
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
|
(defn get-last-message
|
||||||
[chat-id]
|
[chat-id]
|
||||||
(if-let [{:keys [content-type] :as message} (data-store/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]]
|
(:require [re-frame.core :refer [after dispatch]]
|
||||||
[status-im.utils.handlers :refer [register-handler] :as u]
|
[status-im.utils.handlers :refer [register-handler] :as u]
|
||||||
[status-im.components.react :refer [http-bridge]]
|
[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]
|
[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)
|
(def debug-server-port 5561)
|
||||||
|
|
||||||
|
(defn respond [data]
|
||||||
|
(.respond http-bridge
|
||||||
|
200
|
||||||
|
"application/json"
|
||||||
|
(cljs->json data)))
|
||||||
|
|
||||||
(register-handler :init-debug-mode
|
(register-handler :init-debug-mode
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [_ [_ address]]
|
(fn [_ [_ address]]
|
||||||
|
@ -19,6 +28,9 @@
|
||||||
(fn [_]
|
(fn [_]
|
||||||
(.start http-bridge
|
(.start http-bridge
|
||||||
debug-server-port
|
debug-server-port
|
||||||
|
(if platform/ios?
|
||||||
|
"Status iOS"
|
||||||
|
"Status Android")
|
||||||
(fn [req]
|
(fn [req]
|
||||||
(try
|
(try
|
||||||
(let [{:keys [postData url]} (js->clj req :keywordize-keys true)
|
(let [{:keys [postData url]} (js->clj req :keywordize-keys true)
|
||||||
|
@ -38,43 +50,65 @@
|
||||||
(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}]]
|
{:keys [encoded]
|
||||||
|
:as post-data} :postData}]]
|
||||||
(try
|
(try
|
||||||
(let [json (->> (.toAscii web3 encoded)
|
(let [json (some->> encoded
|
||||||
(.parse js/JSON))
|
(.toAscii web3)
|
||||||
obj (js->clj json :keywordize-keys true)]
|
(.parse js/JSON))
|
||||||
|
obj (when json
|
||||||
|
(js->clj json :keywordize-keys true))]
|
||||||
(case url
|
(case url
|
||||||
"/add-dapp" (dispatch [:debug-add-contact obj])
|
"/add-dapp" (dispatch [:debug-add-contact obj])
|
||||||
"/remove-dapp" (dispatch [:debug-remove-contact obj])
|
"/remove-dapp" (dispatch [:debug-remove-contact obj])
|
||||||
"/dapp-changed" (dispatch [:debug-contact-changed obj])
|
"/dapp-changed" (dispatch [:debug-contact-changed obj])
|
||||||
"/switch-node" (dispatch [:debug-switch-node obj])
|
"/switch-node" (dispatch [:debug-switch-node obj])
|
||||||
|
"/list" (dispatch [:debug-dapps-list])
|
||||||
|
"/log" (dispatch [:debug-log post-data])
|
||||||
:default))
|
:default))
|
||||||
(catch js/Error e
|
(catch js/Error e
|
||||||
|
(respond {:type :error :text (str "Error: " e)})
|
||||||
(log/debug "Error: " e))))))
|
(log/debug "Error: " e))))))
|
||||||
|
|
||||||
(register-handler :debug-add-contact
|
(register-handler :debug-add-contact
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [contacts]} [_ {:keys [name whisper-identity dapp-url bot-url] :as dapp-data}]]
|
(fn [{:keys [contacts]} [_ {:keys [name whisper-identity dapp-url bot-url] :as dapp-data}]]
|
||||||
(when (and name
|
(if (and name
|
||||||
whisper-identity
|
whisper-identity
|
||||||
(or dapp-url bot-url)
|
(or dapp-url bot-url))
|
||||||
(or (not (get contacts whisper-identity))
|
(if (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 [:upsert-chat! {:chat-id whisper-identity
|
(dispatch [:upsert-chat! {:chat-id whisper-identity
|
||||||
:name name
|
:name name
|
||||||
:debug? true}])
|
:debug? true}])
|
||||||
(if (get contacts whisper-identity)
|
(if (get contacts whisper-identity)
|
||||||
(dispatch [:update-contact! dapp])
|
(do (dispatch [:update-contact! dapp])
|
||||||
(do (dispatch [:add-contacts [dapp]])
|
(respond {:type :ok
|
||||||
(dispatch [:open-chat-with-contact dapp]))))))))
|
:text "The DApp or bot has been updated."}))
|
||||||
|
(do (dispatch [:add-contacts [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
|
(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?])
|
(if (get chats whisper-identity)
|
||||||
(dispatch [:remove-chat 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? %))]))))
|
(dispatch [:remove-contact whisper-identity #(and (:dapp? %) (:debug? %))]))))
|
||||||
|
|
||||||
(register-handler :debug-contact-changed
|
(register-handler :debug-contact-changed
|
||||||
|
@ -85,10 +119,37 @@
|
||||||
webview-bridge)
|
webview-bridge)
|
||||||
(.reload webview-bridge))
|
(.reload webview-bridge))
|
||||||
(when (get-in contacts [whisper-identity :bot-url])
|
(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
|
(register-handler :debug-switch-node
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [current-account-id]} [_ {:keys [url]}]]
|
(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