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 {
|
||||
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>
|
||||
<groupId>status-im</groupId>
|
||||
<artifactId>status-go-ios-simulator</artifactId>
|
||||
<version>rebase-to-1.5.4-unstable</version>
|
||||
<version>local-storage</version>
|
||||
<type>zip</type>
|
||||
<overWrite>true</overWrite>
|
||||
<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;
|
||||
}
|
||||
|
||||
context.messages = [];
|
||||
|
||||
callResult = fn(params.parameters, params.context);
|
||||
result = {
|
||||
returned: callResult,
|
||||
context: context[message_id]
|
||||
context: context[message_id],
|
||||
messages: context.messages
|
||||
};
|
||||
|
||||
return JSON.stringify(result);
|
||||
}
|
||||
|
||||
function text(options, s) {
|
||||
return ['text', options, s];
|
||||
s = Array.isArray(s) ? s : [s];
|
||||
return ['text', options].concat(s);
|
||||
}
|
||||
|
||||
function view(options, elements) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
[status-im.utils.handlers :refer [register-handler] :as u]
|
||||
[status-im.components.status :as status]
|
||||
[status-im.models.commands :as commands]
|
||||
[status-im.chat.utils :refer [console? not-console?]]
|
||||
[clojure.string :as str]
|
||||
[status-im.commands.utils :as cu]
|
||||
[status-im.utils.phone-number :as pn]
|
||||
|
@ -21,13 +22,15 @@
|
|||
[{:keys [current-chat-id canceled-command] :as db} _]
|
||||
(when-not canceled-command
|
||||
(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
|
||||
path [(if (= :command type) :commands :responses)
|
||||
name
|
||||
:params
|
||||
0
|
||||
:suggestions]
|
||||
params {:parameters (or params {})}]
|
||||
params {:parameters (or params {})
|
||||
:context {:data data}}]
|
||||
(status/call-jail current-chat-id
|
||||
path
|
||||
params
|
||||
|
@ -62,6 +65,16 @@
|
|||
(assoc-in db [:chats current-chat-id :input-text] nil)
|
||||
(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!
|
||||
[{:keys [staged-command] :as db} [_ command-input chat-id]]
|
||||
(let [{:keys [command id]} staged-command
|
||||
|
@ -72,10 +85,12 @@
|
|||
:preview]
|
||||
params {:parameters parameters
|
||||
:context {:platform platform/platform}}]
|
||||
(if (and (console? chat-id) (= name "js"))
|
||||
(dispatch [:send-chat-message])
|
||||
(status/call-jail chat-id
|
||||
path
|
||||
params
|
||||
#(dispatch [:command-preview chat-id id %]))))
|
||||
#(dispatch [:command-preview chat-id id %])))))
|
||||
|
||||
(defn command-input
|
||||
([{:keys [current-chat-id] :as db}]
|
||||
|
@ -270,3 +285,4 @@
|
|||
(if (= :on-send suggestions-trigger)
|
||||
(dispatch [:invoke-commands-suggestions!])
|
||||
(dispatch [:stage-command]))))))
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
(ns status-im.chat.handlers.console
|
||||
(:require [re-frame.core :refer [dispatch dispatch-sync after]]
|
||||
[status-im.utils.handlers :refer [register-handler] :as u]
|
||||
[status-im.constants :refer [console-chat-id]]
|
||||
[status-im.data-store.messages :as messages]))
|
||||
[status-im.constants :refer [console-chat-id
|
||||
text-content-type]]
|
||||
[status-im.data-store.messages :as messages]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.utils.random :as random]))
|
||||
|
||||
(def console-commands
|
||||
{:password
|
||||
|
@ -37,3 +40,37 @@
|
|||
:message-status status})))
|
||||
(fn [db [_ message-id 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))
|
||||
(dispatch [:clear-command chat-id (:id staged-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]))
|
||||
(not= add-to-chat-id wallet-chat-id))
|
||||
(let [ct (if request
|
||||
|
|
|
@ -34,13 +34,17 @@
|
|||
parameter [:get-command-parameter]
|
||||
type [:command-type]
|
||||
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))
|
||||
(not command?))
|
||||
(not= response-height input-height))
|
||||
style (when-not (seq staged-commands)
|
||||
(get-in platform-specific [:component-styles :chat :new-message]))]
|
||||
[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
|
||||
(when command? (get-options parameter type))]]))
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
(defn suggestions-events-handler!
|
||||
[db [[n data]]]
|
||||
(case (keyword n)
|
||||
:set-value (dispatch [:set-chat-command-content data])
|
||||
:set-value (dispatch [:fill-chat-command-content data])
|
||||
;; todo show error?
|
||||
nil))
|
||||
|
||||
|
@ -92,3 +92,8 @@
|
|||
(reg-handler :command-preview
|
||||
(after (print-error-message! "Error on 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))
|
||||
|
||||
(defn call-module [f]
|
||||
(log/debug :call-module f)
|
||||
;(log/debug :call-module f)
|
||||
(if @module-initialized?
|
||||
(f)
|
||||
(store-call f)))
|
||||
|
@ -106,11 +106,15 @@
|
|||
:debug js/goog.DEBUG
|
||||
:locale i/i18n.locale)
|
||||
cb (fn [r]
|
||||
(let [r' (t/json->clj r)]
|
||||
(let [{:keys [result] :as r'} (t/json->clj r)
|
||||
{:keys [messages]} result]
|
||||
(log/debug r')
|
||||
(doseq [{:keys [type message]} messages]
|
||||
(log/debug (str "VM console(" type ") - " message)))
|
||||
(callback r')))]
|
||||
(.callJail status chat-id (cljs->json path) (cljs->json params') cb))))))
|
||||
|
||||
|
||||
(defn set-soft-input-mode [mode]
|
||||
(when status
|
||||
(call-module #(.setSoftInputMode status mode))))
|
||||
|
|
|
@ -121,6 +121,7 @@
|
|||
"transaction.failed" (dispatch [:transaction-failed event])
|
||||
"node.started" (log/debug "Event *node.started* received")
|
||||
"module.initialized" (dispatch [:status-module-initialized!])
|
||||
"local_storage.set" (dispatch [:set-local-storage event])
|
||||
(log/debug "Event " type " not handled"))))))
|
||||
|
||||
(register-handler :status-module-initialized!
|
||||
|
|
Loading…
Reference in New Issue