Merge pull request #511 from status-im/feature/console-web3
Feature/console web3
This commit is contained in:
commit
4854021005
|
@ -14,5 +14,5 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.facebook.react:react-native:+'
|
compile 'com.facebook.react:react-native:+'
|
||||||
compile(group: 'status-im', name: 'status-go', version: 'rebase-to-1.5.4-unstable', ext: 'aar')
|
compile(group: 'status-im', name: 'status-go', version: 'local-storage', ext: 'aar')
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>status-im</groupId>
|
<groupId>status-im</groupId>
|
||||||
<artifactId>status-go-ios-simulator</artifactId>
|
<artifactId>status-go-ios-simulator</artifactId>
|
||||||
<version>rebase-to-1.5.4-unstable</version>
|
<version>local-storage</version>
|
||||||
<type>zip</type>
|
<type>zip</type>
|
||||||
<overWrite>true</overWrite>
|
<overWrite>true</overWrite>
|
||||||
<outputDirectory>./</outputDirectory>
|
<outputDirectory>./</outputDirectory>
|
||||||
|
|
1026
resources/console.js
1026
resources/console.js
File diff suppressed because it is too large
Load Diff
|
@ -80,17 +80,21 @@ function call(pathStr, paramsStr) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.messages = [];
|
||||||
|
|
||||||
callResult = fn(params.parameters, params.context);
|
callResult = fn(params.parameters, params.context);
|
||||||
result = {
|
result = {
|
||||||
returned: callResult,
|
returned: callResult,
|
||||||
context: context[message_id]
|
context: context[message_id],
|
||||||
|
messages: context.messages
|
||||||
};
|
};
|
||||||
|
|
||||||
return JSON.stringify(result);
|
return JSON.stringify(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function text(options, s) {
|
function text(options, s) {
|
||||||
return ['text', options, s];
|
s = Array.isArray(s) ? s : [s];
|
||||||
|
return ['text', options].concat(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
function view(options, elements) {
|
function view(options, elements) {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
[status-im.utils.handlers :refer [register-handler] :as u]
|
[status-im.utils.handlers :refer [register-handler] :as u]
|
||||||
[status-im.components.status :as status]
|
[status-im.components.status :as status]
|
||||||
[status-im.models.commands :as commands]
|
[status-im.models.commands :as commands]
|
||||||
|
[status-im.chat.utils :refer [console? not-console?]]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[status-im.commands.utils :as cu]
|
[status-im.commands.utils :as cu]
|
||||||
[status-im.utils.phone-number :as pn]
|
[status-im.utils.phone-number :as pn]
|
||||||
|
@ -21,13 +22,15 @@
|
||||||
[{:keys [current-chat-id canceled-command] :as db} _]
|
[{:keys [current-chat-id canceled-command] :as db} _]
|
||||||
(when-not canceled-command
|
(when-not canceled-command
|
||||||
(let [{:keys [command content params]} (get-in db [:chats current-chat-id :command-input])
|
(let [{:keys [command content params]} (get-in db [:chats current-chat-id :command-input])
|
||||||
|
data (get-in db [:local-storage current-chat-id])
|
||||||
{:keys [name type]} command
|
{:keys [name type]} command
|
||||||
path [(if (= :command type) :commands :responses)
|
path [(if (= :command type) :commands :responses)
|
||||||
name
|
name
|
||||||
:params
|
:params
|
||||||
0
|
0
|
||||||
:suggestions]
|
:suggestions]
|
||||||
params {:parameters (or params {})}]
|
params {:parameters (or params {})
|
||||||
|
:context {:data data}}]
|
||||||
(status/call-jail current-chat-id
|
(status/call-jail current-chat-id
|
||||||
path
|
path
|
||||||
params
|
params
|
||||||
|
@ -62,6 +65,16 @@
|
||||||
(assoc-in db [:chats current-chat-id :input-text] nil)
|
(assoc-in db [:chats current-chat-id :input-text] nil)
|
||||||
(assoc db :canceled-command (and command? (not starts-as-command?)))))))
|
(assoc db :canceled-command (and command? (not starts-as-command?)))))))
|
||||||
|
|
||||||
|
(register-handler :fill-chat-command-content
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [db [_ content]]
|
||||||
|
(let [command? (= :command (current-command db :type))]
|
||||||
|
(dispatch
|
||||||
|
[:set-chat-command-content
|
||||||
|
(if command?
|
||||||
|
(str cu/command-prefix content)
|
||||||
|
content)])))))
|
||||||
|
|
||||||
(defn invoke-command-preview!
|
(defn invoke-command-preview!
|
||||||
[{:keys [staged-command] :as db} [_ command-input chat-id]]
|
[{:keys [staged-command] :as db} [_ command-input chat-id]]
|
||||||
(let [{:keys [command id]} staged-command
|
(let [{:keys [command id]} staged-command
|
||||||
|
@ -72,10 +85,12 @@
|
||||||
:preview]
|
:preview]
|
||||||
params {:parameters parameters
|
params {:parameters parameters
|
||||||
:context {:platform platform/platform}}]
|
:context {:platform platform/platform}}]
|
||||||
(status/call-jail chat-id
|
(if (and (console? chat-id) (= name "js"))
|
||||||
path
|
(dispatch [:send-chat-message])
|
||||||
params
|
(status/call-jail chat-id
|
||||||
#(dispatch [:command-preview chat-id id %]))))
|
path
|
||||||
|
params
|
||||||
|
#(dispatch [:command-preview chat-id id %])))))
|
||||||
|
|
||||||
(defn command-input
|
(defn command-input
|
||||||
([{:keys [current-chat-id] :as db}]
|
([{:keys [current-chat-id] :as db}]
|
||||||
|
@ -270,3 +285,4 @@
|
||||||
(if (= :on-send suggestions-trigger)
|
(if (= :on-send suggestions-trigger)
|
||||||
(dispatch [:invoke-commands-suggestions!])
|
(dispatch [:invoke-commands-suggestions!])
|
||||||
(dispatch [:stage-command]))))))
|
(dispatch [:stage-command]))))))
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
(ns status-im.chat.handlers.console
|
(ns status-im.chat.handlers.console
|
||||||
(:require [re-frame.core :refer [dispatch dispatch-sync after]]
|
(:require [re-frame.core :refer [dispatch dispatch-sync after]]
|
||||||
[status-im.utils.handlers :refer [register-handler] :as u]
|
[status-im.utils.handlers :refer [register-handler] :as u]
|
||||||
[status-im.constants :refer [console-chat-id]]
|
[status-im.constants :refer [console-chat-id
|
||||||
[status-im.data-store.messages :as messages]))
|
text-content-type]]
|
||||||
|
[status-im.data-store.messages :as messages]
|
||||||
|
[taoensso.timbre :as log]
|
||||||
|
[status-im.utils.random :as random]))
|
||||||
|
|
||||||
(def console-commands
|
(def console-commands
|
||||||
{:password
|
{:password
|
||||||
|
@ -37,3 +40,37 @@
|
||||||
:message-status status})))
|
:message-status status})))
|
||||||
(fn [db [_ message-id status]]
|
(fn [db [_ message-id status]]
|
||||||
(assoc-in db [:message-statuses message-id] {:status status})))
|
(assoc-in db [:message-statuses message-id] {:status status})))
|
||||||
|
|
||||||
|
(register-handler :console-respond-command
|
||||||
|
(u/side-effect!
|
||||||
|
(fn [_ [_ {:keys [command] :as parameters}]]
|
||||||
|
(let [{:keys [command handler-data]} command]
|
||||||
|
(when command
|
||||||
|
(let [{:keys [name]} command]
|
||||||
|
(case name
|
||||||
|
"js" (let [{:keys [err data messages]} handler-data
|
||||||
|
content (if err
|
||||||
|
err
|
||||||
|
data)]
|
||||||
|
(doseq [message messages]
|
||||||
|
(let [{:keys [message type]} message]
|
||||||
|
(dispatch [:received-message
|
||||||
|
{:message-id (random/id)
|
||||||
|
:content (str type ": " message)
|
||||||
|
:content-type text-content-type
|
||||||
|
:outgoing false
|
||||||
|
:chat-id console-chat-id
|
||||||
|
:from console-chat-id
|
||||||
|
:to "me"}])))
|
||||||
|
(when content
|
||||||
|
(dispatch [:received-message
|
||||||
|
{:message-id (random/id)
|
||||||
|
:content (str content)
|
||||||
|
:content-type text-content-type
|
||||||
|
:outgoing false
|
||||||
|
:chat-id console-chat-id
|
||||||
|
:from console-chat-id
|
||||||
|
:to "me"}])))
|
||||||
|
(log/debug "ignoring command: " command))))))))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,8 @@
|
||||||
(log/debug "Handler data: " request handler-data (dissoc params :commands :staged-command))
|
(log/debug "Handler data: " request handler-data (dissoc params :commands :staged-command))
|
||||||
(dispatch [:clear-command chat-id (:id staged-command)])
|
(dispatch [:clear-command chat-id (:id staged-command)])
|
||||||
(dispatch [::send-command! add-to-chat-id (assoc params :command command')])
|
(dispatch [::send-command! add-to-chat-id (assoc params :command command')])
|
||||||
|
(when (cu/console? chat-id)
|
||||||
|
(dispatch [:console-respond-command params]))
|
||||||
(when (and (= "send" (get-in staged-command [:command :name]))
|
(when (and (= "send" (get-in staged-command [:command :name]))
|
||||||
(not= add-to-chat-id wallet-chat-id))
|
(not= add-to-chat-id wallet-chat-id))
|
||||||
(let [ct (if request
|
(let [ct (if request
|
||||||
|
|
|
@ -34,13 +34,17 @@
|
||||||
parameter [:get-command-parameter]
|
parameter [:get-command-parameter]
|
||||||
type [:command-type]
|
type [:command-type]
|
||||||
suggestions [:get-suggestions]
|
suggestions [:get-suggestions]
|
||||||
staged-commands [:get-chat-staged-commands]]
|
staged-commands [:get-chat-staged-commands]
|
||||||
|
message-input-height [:get-message-input-view-height]]
|
||||||
(let [on-top? (or (and (not (empty? suggestions))
|
(let [on-top? (or (and (not (empty? suggestions))
|
||||||
(not command?))
|
(not command?))
|
||||||
(not= response-height input-height))
|
(not= response-height input-height))
|
||||||
style (when-not (seq staged-commands)
|
style (when-not (seq staged-commands)
|
||||||
(get-in platform-specific [:component-styles :chat :new-message]))]
|
(get-in platform-specific [:component-styles :chat :new-message]))]
|
||||||
[view {:style (merge (st/new-message-container margin on-top?) style)
|
[view {:style (merge (st/new-message-container margin on-top?) style)
|
||||||
:on-layout #(dispatch [:set-message-input-view-height (get-height %)])}
|
:on-layout (fn [event]
|
||||||
|
(let [height (get-height event)]
|
||||||
|
(when (not= height message-input-height)
|
||||||
|
(dispatch [:set-message-input-view-height height]))))}
|
||||||
[plain-message-input-view
|
[plain-message-input-view
|
||||||
(when command? (get-options parameter type))]]))
|
(when command? (get-options parameter type))]]))
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
(defn suggestions-events-handler!
|
(defn suggestions-events-handler!
|
||||||
[db [[n data]]]
|
[db [[n data]]]
|
||||||
(case (keyword n)
|
(case (keyword n)
|
||||||
:set-value (dispatch [:set-chat-command-content data])
|
:set-value (dispatch [:fill-chat-command-content data])
|
||||||
;; todo show error?
|
;; todo show error?
|
||||||
nil))
|
nil))
|
||||||
|
|
||||||
|
@ -92,3 +92,8 @@
|
||||||
(reg-handler :command-preview
|
(reg-handler :command-preview
|
||||||
(after (print-error-message! "Error on command preview"))
|
(after (print-error-message! "Error on command preview"))
|
||||||
command-preview)
|
command-preview)
|
||||||
|
|
||||||
|
(reg-handler :set-local-storage
|
||||||
|
(fn [{:keys [current-chat-id] :as db} [{:keys [data] :as event}]]
|
||||||
|
(log/debug "Got event: " event)
|
||||||
|
(assoc-in db [:local-storage current-chat-id] data)))
|
|
@ -26,7 +26,7 @@
|
||||||
(swap! calls conj args))
|
(swap! calls conj args))
|
||||||
|
|
||||||
(defn call-module [f]
|
(defn call-module [f]
|
||||||
(log/debug :call-module f)
|
;(log/debug :call-module f)
|
||||||
(if @module-initialized?
|
(if @module-initialized?
|
||||||
(f)
|
(f)
|
||||||
(store-call f)))
|
(store-call f)))
|
||||||
|
@ -106,11 +106,15 @@
|
||||||
:debug js/goog.DEBUG
|
:debug js/goog.DEBUG
|
||||||
:locale i/i18n.locale)
|
:locale i/i18n.locale)
|
||||||
cb (fn [r]
|
cb (fn [r]
|
||||||
(let [r' (t/json->clj r)]
|
(let [{:keys [result] :as r'} (t/json->clj r)
|
||||||
|
{:keys [messages]} result]
|
||||||
(log/debug r')
|
(log/debug r')
|
||||||
|
(doseq [{:keys [type message]} messages]
|
||||||
|
(log/debug (str "VM console(" type ") - " message)))
|
||||||
(callback r')))]
|
(callback r')))]
|
||||||
(.callJail status chat-id (cljs->json path) (cljs->json params') cb))))))
|
(.callJail status chat-id (cljs->json path) (cljs->json params') cb))))))
|
||||||
|
|
||||||
|
|
||||||
(defn set-soft-input-mode [mode]
|
(defn set-soft-input-mode [mode]
|
||||||
(when status
|
(when status
|
||||||
(call-module #(.setSoftInputMode status mode))))
|
(call-module #(.setSoftInputMode status mode))))
|
||||||
|
|
|
@ -121,6 +121,7 @@
|
||||||
"transaction.failed" (dispatch [:transaction-failed event])
|
"transaction.failed" (dispatch [:transaction-failed event])
|
||||||
"node.started" (log/debug "Event *node.started* received")
|
"node.started" (log/debug "Event *node.started* received")
|
||||||
"module.initialized" (dispatch [:status-module-initialized!])
|
"module.initialized" (dispatch [:status-module-initialized!])
|
||||||
|
"local_storage.set" (dispatch [:set-local-storage event])
|
||||||
(log/debug "Event " type " not handled"))))))
|
(log/debug "Event " type " not handled"))))))
|
||||||
|
|
||||||
(register-handler :status-module-initialized!
|
(register-handler :status-module-initialized!
|
||||||
|
|
Loading…
Reference in New Issue