mirror of
https://github.com/status-im/status-mobile.git
synced 2025-01-14 02:35:54 +00:00
use global @browse command for opening dapps (#847)
This commit is contained in:
parent
239a0cbfe6
commit
1fbb447761
@ -1,10 +1,6 @@
|
|||||||
function browseSuggestions(params, context) {
|
function browseSuggestions(params, context) {
|
||||||
var url;
|
var url;
|
||||||
|
|
||||||
if (context["dapp-url"]) {
|
|
||||||
url = context["dapp-url"];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params.url && params.url !== "undefined" && params.url != "") {
|
if (params.url && params.url !== "undefined" && params.url != "") {
|
||||||
url = params.url;
|
url = params.url;
|
||||||
if (!/^[a-zA-Z-_]+:/.test(url)) {
|
if (!/^[a-zA-Z-_]+:/.test(url)) {
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
I18n.translations = {
|
|
||||||
en: {
|
|
||||||
browse_title: 'Browser',
|
|
||||||
browse_description: 'Open web browser'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
status.command({
|
|
||||||
name: "browse",
|
|
||||||
title: I18n.t('browse_title'),
|
|
||||||
description: I18n.t('browse_description'),
|
|
||||||
color: "#ffa500",
|
|
||||||
fullscreen: true,
|
|
||||||
params: [{
|
|
||||||
name: "url",
|
|
||||||
optional: true,
|
|
||||||
type: status.types.TEXT
|
|
||||||
}],
|
|
||||||
onSend: function (params, context) {
|
|
||||||
var url = params.url || params.metadata.url;
|
|
||||||
if (!/^[a-zA-Z-_]+:/.test(url)) {
|
|
||||||
url = 'http://' + url;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
title: params.metadata.name,
|
|
||||||
dynamicTitle: true,
|
|
||||||
markup: status.components.bridgedWebView(url)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
status.autorun("browse");
|
|
@ -150,9 +150,6 @@ var status = {
|
|||||||
registerFunction: function (name, fn) {
|
registerFunction: function (name, fn) {
|
||||||
_status_catalog.functions[name] = fn;
|
_status_catalog.functions[name] = fn;
|
||||||
},
|
},
|
||||||
autorun: function (commandName) {
|
|
||||||
_status_catalog.autorun = commandName;
|
|
||||||
},
|
|
||||||
localizeNumber: function (num, del, sep) {
|
localizeNumber: function (num, del, sep) {
|
||||||
return I18n.toNumber(
|
return I18n.toNumber(
|
||||||
num.replace(",", "."),
|
num.replace(",", "."),
|
||||||
|
@ -240,7 +240,7 @@
|
|||||||
db' (assoc db :current-chat-id chat-id)
|
db' (assoc db :current-chat-id chat-id)
|
||||||
commands-loaded? (if js/goog.DEBUG
|
commands-loaded? (if js/goog.DEBUG
|
||||||
false
|
false
|
||||||
(get-in db [:chats chat-id :commands-loaded]))]
|
(get-in db [:contacts chat-id :commands-loaded]))]
|
||||||
(dispatch [:load-requests! chat-id])
|
(dispatch [:load-requests! chat-id])
|
||||||
;; todo rewrite this. temporary fix for https://github.com/status-im/status-react/issues/607
|
;; todo rewrite this. temporary fix for https://github.com/status-im/status-react/issues/607
|
||||||
#_(dispatch [:load-commands! chat-id])
|
#_(dispatch [:load-commands! chat-id])
|
||||||
@ -442,13 +442,14 @@
|
|||||||
(let [{:keys [clock-value]} (messages/get-by-id message-id)]
|
(let [{:keys [clock-value]} (messages/get-by-id message-id)]
|
||||||
(send-clock-value! db to message-id clock-value)))))
|
(send-clock-value! db to message-id clock-value)))))
|
||||||
|
|
||||||
(register-handler :check-autorun
|
(register-handler :check-and-open-dapp!
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [current-chat-id contacts] :as db}]
|
(fn [{:keys [current-chat-id global-commands contacts] :as db}]
|
||||||
(let [autorun (get-in db [:chats current-chat-id :autorun])]
|
(let [dapp-url (get-in db [:contacts current-chat-id :dapp-url])]
|
||||||
(when autorun
|
(when dapp-url
|
||||||
(am/go
|
(am/go
|
||||||
(dispatch [:select-chat-input-command {:name autorun}])
|
(dispatch [:select-chat-input-command
|
||||||
|
(assoc (:browse global-commands) :prefill [dapp-url])])
|
||||||
(a/<! (a/timeout 100))
|
(a/<! (a/timeout 100))
|
||||||
(dispatch [:send-current-message])))))))
|
(dispatch [:send-current-message])))))))
|
||||||
|
|
||||||
|
@ -10,11 +10,11 @@
|
|||||||
|
|
||||||
(handlers/register-handler :request-command-data
|
(handlers/register-handler :request-command-data
|
||||||
(handlers/side-effect!
|
(handlers/side-effect!
|
||||||
(fn [{:keys [chats current-account-id] :as db}
|
(fn [{:keys [contacts current-account-id] :as db}
|
||||||
[_ {{:keys [command params content-command type]} :content
|
[_ {{:keys [command params content-command type]} :content
|
||||||
:keys [message-id chat-id on-requested jail-id] :as message} data-type]]
|
:keys [message-id chat-id on-requested jail-id] :as message} data-type]]
|
||||||
(let [jail-id (or jail-id chat-id)]
|
(let [jail-id (or jail-id chat-id)]
|
||||||
(if-not (get-in chats [jail-id :commands-loaded])
|
(if-not (get-in contacts [jail-id :commands-loaded])
|
||||||
(do (dispatch [:add-commands-loading-callback
|
(do (dispatch [:add-commands-loading-callback
|
||||||
jail-id
|
jail-id
|
||||||
#(dispatch [:request-command-data message data-type])])
|
#(dispatch [:request-command-data message data-type])])
|
||||||
@ -22,7 +22,7 @@
|
|||||||
(let [path [(if (= :response (keyword type)) :responses :commands)
|
(let [path [(if (= :response (keyword type)) :responses :commands)
|
||||||
(if content-command content-command command)
|
(if content-command content-command command)
|
||||||
data-type]
|
data-type]
|
||||||
to (get-in db [:contacts chat-id :address])
|
to (get-in contacts [chat-id :address])
|
||||||
params {:parameters params
|
params {:parameters params
|
||||||
:context (merge {:platform platform/platform
|
:context (merge {:platform platform/platform
|
||||||
:from current-account-id
|
:from current-account-id
|
||||||
|
@ -110,22 +110,23 @@
|
|||||||
(handlers/register-handler
|
(handlers/register-handler
|
||||||
:load-chat-parameter-box
|
:load-chat-parameter-box
|
||||||
(handlers/side-effect!
|
(handlers/side-effect!
|
||||||
(fn [{:keys [current-chat-id] :as db} [_ {:keys [name type] :as command}]]
|
(fn [{:keys [current-chat-id] :as db} [_ {:keys [name type bot] :as command}]]
|
||||||
(let [parameter-index (input-model/argument-position db current-chat-id)]
|
(let [parameter-index (input-model/argument-position db current-chat-id)]
|
||||||
(when (and command (> parameter-index -1))
|
(when (and command (> parameter-index -1))
|
||||||
(let [data (get-in db [:local-storage current-chat-id])
|
(let [jail-id (or bot current-chat-id)
|
||||||
path [(if (= :command type) :commands :responses)
|
data (get-in db [:local-storage current-chat-id])
|
||||||
name
|
path [(if (= :command type) :commands :responses)
|
||||||
:params
|
name
|
||||||
parameter-index
|
:params
|
||||||
:suggestions]
|
parameter-index
|
||||||
args (-> (get-in db [:chats current-chat-id :input-text])
|
:suggestions]
|
||||||
(input-model/split-command-args)
|
args (-> (get-in db [:chats jail-id :input-text])
|
||||||
(rest))
|
(input-model/split-command-args)
|
||||||
params {:parameters {:args args}
|
(rest))
|
||||||
:context (merge {:data data}
|
params {:parameters {:args args}
|
||||||
(input-model/command-dependent-context-params command))}]
|
:context (merge {:data data}
|
||||||
(status/call-jail current-chat-id
|
(input-model/command-dependent-context-params command))}]
|
||||||
|
(status/call-jail jail-id
|
||||||
path
|
path
|
||||||
params
|
params
|
||||||
#(dispatch [:suggestions-handler
|
#(dispatch [:suggestions-handler
|
||||||
|
@ -98,7 +98,7 @@
|
|||||||
(assoc-in db [:chats chat-id :last-message] message)))
|
(assoc-in db [:chats chat-id :last-message] message)))
|
||||||
|
|
||||||
(defn commands-loaded? [db chat-id]
|
(defn commands-loaded? [db chat-id]
|
||||||
(get-in db [:chats chat-id :commands-loaded]))
|
(get-in db [:contacts chat-id :commands-loaded]))
|
||||||
|
|
||||||
(def timeout 400)
|
(def timeout 400)
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@
|
|||||||
show-emoji? [:chat-ui-props :show-emoji?]
|
show-emoji? [:chat-ui-props :show-emoji?]
|
||||||
layout-height [:get :layout-height]
|
layout-height [:get :layout-height]
|
||||||
input-text [:chat :input-text]]
|
input-text [:chat :input-text]]
|
||||||
{:component-did-mount #(do (dispatch [:check-autorun])
|
{:component-did-mount #(do (dispatch [:check-and-open-dapp!])
|
||||||
(dispatch [:update-suggestions]))
|
(dispatch [:update-suggestions]))
|
||||||
:component-will-unmount #(dispatch [:set-chat-ui-props {:show-emoji? false}])}
|
:component-will-unmount #(dispatch [:set-chat-ui-props {:show-emoji? false}])}
|
||||||
[view {:style st/chat-view
|
[view {:style st/chat-view
|
||||||
|
@ -39,14 +39,15 @@
|
|||||||
(dispatch [::validate-hash params (js-res/get-resource bot-url)])
|
(dispatch [::validate-hash params (js-res/get-resource bot-url)])
|
||||||
|
|
||||||
(and dapp? dapp-url)
|
(and dapp? dapp-url)
|
||||||
(http-get (s/join "/" [dapp-url "commands.js"])
|
(let [url (s/join "/" [dapp-url "commands.js"])]
|
||||||
(fn [response]
|
(http-get url
|
||||||
(and
|
(fn [response]
|
||||||
(string? (.text response))
|
(and
|
||||||
(when-let [content-type (.. response -headers (get "Content-Type"))]
|
(string? (.text response))
|
||||||
(s/includes? "application/javascript" content-type))))
|
(when-let [content-type (.. response -headers (get "Content-Type"))]
|
||||||
#(dispatch [::validate-hash whisper-identity %])
|
(s/includes? "application/javascript" content-type))))
|
||||||
#(dispatch [::validate-hash whisper-identity js-res/dapp-js]))
|
#(dispatch [::validate-hash whisper-identity %])
|
||||||
|
#(log/debug (str "command.js wasn't found at " url))))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(dispatch [::validate-hash params js-res/commands-js])))
|
(dispatch [::validate-hash params js-res/commands-js])))
|
||||||
@ -107,7 +108,7 @@
|
|||||||
(into {})))
|
(into {})))
|
||||||
|
|
||||||
(defn add-commands
|
(defn add-commands
|
||||||
[db [id _ {:keys [commands responses autorun]}]]
|
[db [id _ {:keys [commands responses]}]]
|
||||||
(let [account @(subscribe [:get-current-account])
|
(let [account @(subscribe [:get-current-account])
|
||||||
commands' (filter-forbidden-names account id commands)
|
commands' (filter-forbidden-names account id commands)
|
||||||
global-command (:global commands')
|
global-command (:global commands')
|
||||||
@ -115,12 +116,14 @@
|
|||||||
responses' (filter-forbidden-names account id responses)]
|
responses' (filter-forbidden-names account id responses)]
|
||||||
(cond-> db
|
(cond-> db
|
||||||
|
|
||||||
|
true
|
||||||
|
(update-in [:contacts id] assoc
|
||||||
|
:commands-loaded true)
|
||||||
|
|
||||||
(get-in db [:chats id])
|
(get-in db [:chats id])
|
||||||
(update-in [:chats id] assoc
|
(update-in [:chats id] assoc
|
||||||
:commands (mark-as :command commands'')
|
:commands (mark-as :command commands'')
|
||||||
:responses (mark-as :response responses')
|
:responses (mark-as :response responses')
|
||||||
:commands-loaded true
|
|
||||||
:autorun autorun
|
|
||||||
:global-command global-command)
|
:global-command global-command)
|
||||||
|
|
||||||
global-command
|
global-command
|
||||||
@ -152,8 +155,8 @@
|
|||||||
|
|
||||||
(reg-handler :check-and-load-commands!
|
(reg-handler :check-and-load-commands!
|
||||||
(u/side-effect!
|
(u/side-effect!
|
||||||
(fn [{:keys [chats]} [identity callback]]
|
(fn [{:keys [contacts]} [identity callback]]
|
||||||
(if (get-in chats [identity :commands-loaded])
|
(if (get-in contacts [identity :commands-loaded])
|
||||||
(callback)
|
(callback)
|
||||||
(dispatch [:load-commands! identity callback])))))
|
(dispatch [:load-commands! identity callback])))))
|
||||||
|
|
||||||
@ -169,8 +172,8 @@
|
|||||||
(reg-handler ::add-commands
|
(reg-handler ::add-commands
|
||||||
[(after save-commands-js!)
|
[(after save-commands-js!)
|
||||||
(after save-global-command!)
|
(after save-global-command!)
|
||||||
(after #(dispatch [:check-autorun]))
|
;;(after #(dispatch [:check-and-open-dapp!]))
|
||||||
(after #(dispatch [:update-suggestions]))
|
;;(after #(dispatch [:update-suggestions]))
|
||||||
(after (fn [_ [id]]
|
(after (fn [_ [id]]
|
||||||
(dispatch [:invoke-commands-loading-callbacks id])
|
(dispatch [:invoke-commands-loading-callbacks id])
|
||||||
(dispatch [:invoke-chat-loaded-callbacks id])))]
|
(dispatch [:invoke-chat-loaded-callbacks id])))]
|
||||||
|
@ -34,8 +34,6 @@
|
|||||||
(def status-js (str (slurp "resources/status.js")
|
(def status-js (str (slurp "resources/status.js")
|
||||||
(slurp "resources/i18n.js")))
|
(slurp "resources/i18n.js")))
|
||||||
|
|
||||||
(def dapp-js (str (slurp "resources/dapp.js")))
|
|
||||||
|
|
||||||
(def webview-js (slurp "resources/webview.js"))
|
(def webview-js (slurp "resources/webview.js"))
|
||||||
(def jquery (str
|
(def jquery (str
|
||||||
" if (typeof jQuery2 == 'undefined') {"
|
" if (typeof jQuery2 == 'undefined') {"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user