This commit is contained in:
Roman Volosovskyi 2017-04-13 12:37:03 +03:00 committed by Roman Volosovskyi
parent 03cab7ace2
commit 19d65a4d46
3 changed files with 18 additions and 13 deletions

View File

@ -1,7 +1,7 @@
(ns status-im.commands.handlers.jail
(:require [re-frame.core :refer [after dispatch subscribe trim-v debug]]
[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.commands.utils :refer [generate-hiccup reg-handler]]
[clojure.string :as s]

View File

@ -31,23 +31,28 @@
(dispatch [::parse-commands! identity file])
(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!
[_ [{{:keys [dapp? dapp-url bot-url whisper-identity]} :contact
:as params}]]
(cond
(js-res/local-resource? bot-url)
(dispatch [::validate-hash params (js-res/get-resource bot-url)])
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"])]
(http-get 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))))
(http-get-commands params url))
:else
(dispatch [::validate-hash params js-res/commands-js])))

View File

@ -50,7 +50,7 @@
ok?' (if valid-response?
(and ok? (valid-response? response))
ok?)]
[(.text response) ok?'])))
[(.-_bodyText response) ok?'])))
(.then (fn [[response ok?]]
(cond
ok? (on-success response)