mirror of
https://github.com/status-im/status-mobile.git
synced 2025-03-01 00:30:49 +00:00
fix #987
This commit is contained in:
parent
03cab7ace2
commit
19d65a4d46
@ -1,7 +1,7 @@
|
|||||||
(ns status-im.commands.handlers.jail
|
(ns status-im.commands.handlers.jail
|
||||||
(:require [re-frame.core :refer [after dispatch subscribe trim-v debug]]
|
(:require [re-frame.core :refer [after dispatch subscribe trim-v debug]]
|
||||||
[status-im.utils.handlers :as handlers]
|
[status-im.utils.handlers :as handlers]
|
||||||
[status-im.utils.utils :refer [http-get show-popup]]
|
[status-im.utils.utils :refer [show-popup]]
|
||||||
[status-im.utils.types :refer [json->clj]]
|
[status-im.utils.types :refer [json->clj]]
|
||||||
[status-im.commands.utils :refer [generate-hiccup reg-handler]]
|
[status-im.commands.utils :refer [generate-hiccup reg-handler]]
|
||||||
[clojure.string :as s]
|
[clojure.string :as s]
|
||||||
|
@ -31,23 +31,28 @@
|
|||||||
(dispatch [::parse-commands! identity file])
|
(dispatch [::parse-commands! identity file])
|
||||||
(dispatch [::fetch-commands! identity])))
|
(dispatch [::fetch-commands! identity])))
|
||||||
|
|
||||||
|
|
||||||
|
(defn http-get-commands [params url]
|
||||||
|
(http-get url
|
||||||
|
(fn [response]
|
||||||
|
(when-let [content-type (.. response -headers (get "Content-Type"))]
|
||||||
|
(s/includes? content-type "application/javascript")))
|
||||||
|
#(dispatch [::validate-hash params %])
|
||||||
|
#(log/debug (str "command.js wasn't found at " url))))
|
||||||
|
|
||||||
|
|
||||||
(defn fetch-commands!
|
(defn fetch-commands!
|
||||||
[_ [{{:keys [dapp? dapp-url bot-url whisper-identity]} :contact
|
[_ [{{:keys [dapp? dapp-url bot-url whisper-identity]} :contact
|
||||||
:as params}]]
|
:as params}]]
|
||||||
(cond
|
(cond
|
||||||
(js-res/local-resource? bot-url)
|
bot-url
|
||||||
(dispatch [::validate-hash params (js-res/get-resource bot-url)])
|
(if-let [url (js-res/get-resource bot-url)]
|
||||||
|
(dispatch [::validate-hash params url])
|
||||||
|
(http-get-commands params bot-url))
|
||||||
|
|
||||||
(and dapp? dapp-url)
|
dapp-url
|
||||||
(let [url (s/join "/" [dapp-url "commands.js"])]
|
(let [url (s/join "/" [dapp-url "commands.js"])]
|
||||||
(http-get url
|
(http-get-commands params url))
|
||||||
(fn [response]
|
|
||||||
(and
|
|
||||||
(string? (.text response))
|
|
||||||
(when-let [content-type (.. response -headers (get "Content-Type"))]
|
|
||||||
(s/includes? "application/javascript" content-type))))
|
|
||||||
#(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])))
|
||||||
|
@ -50,7 +50,7 @@
|
|||||||
ok?' (if valid-response?
|
ok?' (if valid-response?
|
||||||
(and ok? (valid-response? response))
|
(and ok? (valid-response? response))
|
||||||
ok?)]
|
ok?)]
|
||||||
[(.text response) ok?'])))
|
[(.-_bodyText response) ok?'])))
|
||||||
(.then (fn [[response ok?]]
|
(.then (fn [[response ok?]]
|
||||||
(cond
|
(cond
|
||||||
ok? (on-success response)
|
ok? (on-success response)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user