From 3aef0f2d9cfccfa240f39da8d8f77f3fba4760f5 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Fri, 10 Jun 2016 17:04:12 +0300 Subject: [PATCH] jail component --- src/status_im/commands/handlers.cljs | 21 ++++++++------------- src/status_im/components/jail.cljs | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 src/status_im/components/jail.cljs diff --git a/src/status_im/commands/handlers.cljs b/src/status_im/commands/handlers.cljs index d413a3b011..9c43f0ab55 100644 --- a/src/status_im/commands/handlers.cljs +++ b/src/status_im/commands/handlers.cljs @@ -5,7 +5,8 @@ [status-im.components.react :as r] [status-im.utils.utils :refer [http-get toast]] [clojure.string :as s] - [status-im.persistence.realm :as realm])) + [status-im.persistence.realm :as realm] + [status-im.components.jail :as j])) (defn reg-handler ([name handler] (reg-handler name nil handler)) @@ -42,12 +43,6 @@ ;; todo tbd hashing algorithm (hash file)) -(defn get-jail [] - (.-Jail (.-NativeModules r/react))) - -(defn parse [file success-callback fail-callback] - (.parse (get-jail) file success-callback fail-callback)) - (defn json->clj [json] (js->clj (.parse js/JSON json) :keywordize-keys true)) @@ -69,12 +64,12 @@ :icon "icon_lock_white"}}}) (defn parse-commands! [_ [identity file]] - (parse file - (fn [result] - (let [commands (json->clj result)] - ;; todo use commands from jail - (dispatch [::add-commands identity file res]))) - #(dispatch [::loading-failed! identity ::error-in-jail %]))) + (j/parse identity file + (fn [result] + (let [commands (json->clj result)] + ;; todo use commands from jail + (dispatch [::add-commands identity file res]))) + #(dispatch [::loading-failed! identity ::error-in-jail %]))) (defn validate-hash [db [identity file]] diff --git a/src/status_im/components/jail.cljs b/src/status_im/components/jail.cljs new file mode 100644 index 0000000000..23e904417b --- /dev/null +++ b/src/status_im/components/jail.cljs @@ -0,0 +1,15 @@ +(ns status-im.components.jail + (:require [status-im.components.react :as r])) + +(def jail (.-Jail (.-NativeModules r/react))) + +(defn parse [chat-id file success-callback fail-callback] + (.parse jail chat-id file success-callback fail-callback)) + +(defn call + [chat-id path params callback] + (.call jail chat-id (clj->js path) (clj->js params) callback)) + +(defn add-listener + [chat-id callback] + (.addListener jail chat-id callback))