diff --git a/src/native_module/core.cljs b/src/native_module/core.cljs index 92615cc9d8..9b02cdf610 100644 --- a/src/native_module/core.cljs +++ b/src/native_module/core.cljs @@ -11,12 +11,13 @@ [taoensso.timbre :as log] [utils.transforms :as types])) -(defn- extract-from-native-modules [module] +(defn- extract-from-native-modules + [module] (if status-im.config/STATUS_BACKEND_ENABLED status-backend/fetch-js-obj (some-> react-native - (oops/gobj-get "NativeModules") - (oops/gobj-get module)))) + (oops/gobj-get "NativeModules") + (oops/gobj-get module)))) (defn status [] (extract-from-native-modules "Status")) (defn account-manager [] (extract-from-native-modules "AccountManager")) @@ -36,7 +37,9 @@ [handler] (if status-im.config/STATUS_BACKEND_ENABLED (status-backend/init-web-socket handler) - (.addListener ^js (.-DeviceEventEmitter ^js react-native) "gethEvent" #(handler (.-jsonEvent ^js %))))) + (.addListener ^js (.-DeviceEventEmitter ^js react-native) + "gethEvent" + #(handler (.-jsonEvent ^js %))))) (defn clear-web-data [] diff --git a/src/status_backend/config.cljs b/src/status_backend/config.cljs index 56f507fd40..0cfeb01765 100644 --- a/src/status_backend/config.cljs +++ b/src/status_backend/config.cljs @@ -7,7 +7,7 @@ ":" status-im.config/STATUS_BACKEND_PORT)) -(def ^:private data-dir-path +(def data-dir-path (str status-im.config/STATUS_BACKEND_STORAGE_DIR "/data")) (def ^:private public-storage-dir @@ -17,4 +17,4 @@ (def signals-url (str url "/signals")) (def keystore-dir-path (str data-dir-path "/keystore")) (def log-dir-path (str data-dir-path "/log")) -(def log-request-file-path (str public-storage-dir "/requests.log")) \ No newline at end of file +(def log-request-file-path (str public-storage-dir "/requests.log")) diff --git a/src/status_backend/core.cljs b/src/status_backend/core.cljs index 231ae5f3e8..cea2565ee0 100644 --- a/src/status_backend/core.cljs +++ b/src/status_backend/core.cljs @@ -1,10 +1,10 @@ (ns status-backend.core (:require - [status-backend.config :as config] - [utils.network.core :as network] - [clojure.string :as string] - [oops.core :as oops] - [taoensso.timbre :as log])) + [clojure.string :as string] + [oops.core :as oops] + [status-backend.config :as config] + [taoensso.timbre :as log] + [utils.network.core :as network])) (def ^:private default-fetch-params {:method :POST @@ -21,7 +21,8 @@ params (assoc default-fetch-params :body body-params)] (network/fetch url params callback)))) -(defn- method-name->endpoint [s] +(defn- method-name->endpoint + [s] (let [first-letter-capitalized (string/capitalize (first s))] (str first-letter-capitalized (subs s 1)))) @@ -31,16 +32,15 @@ This call: (.myMethod fetch-js-obj params) Is the same as: (fetch \"MyMethod\" params) " - (js/Proxy. #js{} - #js{:get (fn [_target native-module-method-name] - (let [endpoint (method-name->endpoint native-module-method-name)] - (partial fetch endpoint)))})) + (js/Proxy. #js {} + #js {:get (fn [_target native-module-method-name] + (let [endpoint (method-name->endpoint native-module-method-name)] + (partial fetch endpoint)))})) -(declare web-socket) - -(defn init-web-socket [on-message] - (defonce web-socket (js/WebSocket. config/signals-url)) - (oops/oset! web-socket "onopen" #(log/debug "[backend] Web Socket connected")) - (oops/oset! web-socket "onmessage" #(-> % (oops/oget "data") (on-message))) - (oops/oset! web-socket "onerror" #(log/error "[backend] Web Socket error" %)) - (oops/oset! web-socket "onclose" #(log/error "[backend] Web Socket closed" %))) +(defn init-web-socket + [on-message] + (let [web-socket (js/WebSocket. config/signals-url)] + (oops/oset! web-socket "onopen" #(log/debug "[backend] Web Socket connected")) + (oops/oset! web-socket "onmessage" #(-> % (oops/oget "data") on-message)) + (oops/oset! web-socket "onerror" #(log/error "[backend] Web Socket error" %)) + (oops/oset! web-socket "onclose" #(log/debug "[backend] Web Socket closed" %)))) diff --git a/src/utils/network/core.cljs b/src/utils/network/core.cljs index 726475d90d..cf8a54d553 100644 --- a/src/utils/network/core.cljs +++ b/src/utils/network/core.cljs @@ -42,7 +42,8 @@ (map :error) (not-any? identity))) -(defn fetch [url {:keys [body] :as params} callback] +(defn fetch + [url {:keys [body] :as params} callback] (let [js-params (cond-> params (map? body) (update :body (comp js/JSON.stringify clj->js)) :always clj->js)]