From 23399c63e172479876fe2a76b4eb9f5b9785f9b5 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sun, 16 Jul 2017 12:04:35 +0300 Subject: [PATCH] extract React Native dependencies --- Jenkinsfile | 5 ++ project.clj | 39 ++++++------ react-native/src/cljsjs/react.cljs | 5 ++ .../src}/cljsjs/react/dom.cljs | 0 .../src}/cljsjs/react/dom/server.cljs | 0 .../react_native/js_dependencies.cljs | 35 +++++++++++ .../src/status_im/react_native/resources.cljs | 29 +++++++++ src/cljsjs/react.cljs | 4 -- src/status_im/android/platform.cljs | 7 +-- .../chat/handlers/webview_bridge.cljs | 2 - src/status_im/chat/models/input.cljs | 5 +- src/status_im/chat/views/message/message.cljs | 2 +- src/status_im/components/camera.cljs | 12 ++-- .../components/carousel/carousel.cljs | 5 +- .../components/chat_icon/screen.cljs | 4 +- src/status_im/components/context_menu.cljs | 7 +-- .../components/icons/custom_icons.cljs | 5 +- .../components/invertible_scroll_view.cljs | 8 +-- src/status_im/components/item_checkbox.cljs | 5 +- src/status_im/components/mapbox.cljs | 9 ++- .../components/native_action_button.cljs | 11 ++-- src/status_im/components/nfc.cljs | 13 ++-- src/status_im/components/permissions.cljs | 5 +- src/status_im/components/qr_code.cljs | 9 ++- src/status_im/components/react.cljs | 61 +++++++++++-------- .../components/sortable_list_view.cljs | 10 +-- src/status_im/components/status.cljs | 12 ++-- src/status_im/components/text_field/view.cljs | 3 +- src/status_im/components/webview_bridge.cljs | 5 +- src/status_im/contacts/handlers.cljs | 9 +-- src/status_im/contacts/validations.cljs | 1 - src/status_im/contacts/views/new_contact.cljs | 2 +- src/status_im/data_store/realm/core.cljs | 14 ++--- src/status_im/handlers.cljs | 29 ++++----- src/status_im/i18n.cljs | 20 +++--- src/status_im/ios/platform.cljs | 7 +-- src/status_im/js_dependencies.cljs | 9 +++ src/status_im/network/net_info.cljs | 14 ++--- src/status_im/new_group/screen_public.cljs | 2 +- src/status_im/participants/views/add.cljs | 2 +- src/status_im/participants/views/remove.cljs | 2 +- src/status_im/protocol/encryption.cljs | 13 ++-- src/status_im/protocol/web3/utils.cljs | 13 ++-- src/status_im/resources.cljs | 35 ----------- src/status_im/utils/crypt.cljs | 15 ++--- src/status_im/utils/ethereum_network.cljs | 7 +-- src/status_im/utils/fs.cljs | 9 ++- src/status_im/utils/homoglyph.cljs | 7 +-- src/status_im/utils/identicon.cljs | 8 +-- src/status_im/utils/image_processing.cljs | 7 +-- src/status_im/utils/instabug.cljs | 7 +-- src/status_im/utils/phone_number.cljs | 14 ++--- src/status_im/utils/platform.cljs | 7 +-- src/status_im/utils/random.cljs | 7 +-- src/status_im/utils/sms_listener.cljs | 8 +-- src/status_im/utils/utils.cljs | 32 +++------- .../{web_provider.cljs => web3_provider.cljs} | 2 +- test/cljs/cljsjs/react.cljs | 2 + test/cljs/cljsjs/react/dom.cljs | 1 + test/cljs/cljsjs/react/dom/server.cljs | 1 + test/cljs/reagent/core.cljs | 14 +++++ .../react_native/js_dependencies.cljs | 38 ++++++++++++ .../status_im/react_native/resources.cljs | 29 +++++++++ .../status_im/test/commands/handlers.cljs | 20 ------ test/cljs/status_im/test/runner.cljs | 6 +- 65 files changed, 409 insertions(+), 321 deletions(-) create mode 100644 react-native/src/cljsjs/react.cljs rename {src => react-native/src}/cljsjs/react/dom.cljs (100%) rename {src => react-native/src}/cljsjs/react/dom/server.cljs (100%) create mode 100644 react-native/src/status_im/react_native/js_dependencies.cljs create mode 100644 react-native/src/status_im/react_native/resources.cljs delete mode 100644 src/cljsjs/react.cljs create mode 100644 src/status_im/js_dependencies.cljs delete mode 100644 src/status_im/resources.cljs rename src/status_im/utils/{web_provider.cljs => web3_provider.cljs} (93%) create mode 100644 test/cljs/cljsjs/react.cljs create mode 100644 test/cljs/cljsjs/react/dom.cljs create mode 100644 test/cljs/cljsjs/react/dom/server.cljs create mode 100644 test/cljs/reagent/core.cljs create mode 100644 test/cljs/status_im/react_native/js_dependencies.cljs create mode 100644 test/cljs/status_im/react_native/resources.cljs delete mode 100644 test/cljs/status_im/test/commands/handlers.cljs diff --git a/Jenkinsfile b/Jenkinsfile index 2abc70bca7..2e1d209d74 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,6 +20,11 @@ node { sh 'mvn -f modules/react-native-status/ios/RCTStatus dependency:unpack' sh 'cd ios && pod install && cd ..' } + + stage('Tests') { + sh 'lein test-cljs' + } + stage('Build') { sh 'lein prod-build' } diff --git a/project.clj b/project.clj index 9439a4bc59..68f90a43d4 100644 --- a/project.clj +++ b/project.clj @@ -17,12 +17,12 @@ [lein-re-frisk "0.4.7"] [rasom/lein-externs "0.1.7"]] :clean-targets ["target/" "index.ios.js" "index.android.js"] - :aliases {"prod-build" ^{:doc "Recompile code with prod profile."} - ["do" "clean" - ["with-profile" "prod" "cljsbuild" "once" "ios"] - ["with-profile" "prod" "cljsbuild" "once" "android"]] + :aliases {"prod-build" ^{:doc "Recompile code with prod profile."} + ["do" "clean" + ["with-profile" "prod" "cljsbuild" "once" "ios"] + ["with-profile" "prod" "cljsbuild" "once" "android"]] "generate-externs" ["with-profile" "prod" "externs" "android" "externs/externs.js"] - "test" ["doo" "phantom" "test" "once"]} + "test-cljs" ["with-profile" "test" "doo" "node" "test" "once"]} :test-paths ["test/clj"] :figwheel {:nrepl-port 7888} :profiles {:dev {:dependencies [[figwheel-sidecar "0.5.11"] @@ -31,34 +31,37 @@ [com.cemerick/piggieback "0.2.1"] [io.appium/java-client "3.4.1"] [hawk "0.2.10"]] - :plugins [[lein-doo "0.1.7"]] :source-paths ["src" "env/dev"] :cljsbuild {:builds {:ios - {:source-paths ["src" "env/dev"] + {:source-paths ["react-native/src" "src" "env/dev"] :figwheel true :compiler {:output-to "target/ios/app.js" :main "env.ios.main" :output-dir "target/ios" :optimizations :none}} :android - {:source-paths ["src" "env/dev"] + {:source-paths ["react-native/src" "src" "env/dev"] :figwheel true :compiler {:output-to "target/android/app.js" :main "env.android.main" :output-dir "target/android" - :optimizations :none}} - :test - {:source-paths ["src" "test/cljs"] - :compiler {:main status-im.test.runner - :output-to "target/test/test.js" - :output-dir "target" :optimizations :none}}}} :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl] :timeout 240000}} + :test {:plugins [[lein-doo "0.1.7"]] + :cljsbuild {:builds + [{:id "test" + :source-paths ["src" "test/cljs"] + :compiler + {:main status-im.test.runner + :output-to "target/test/test.js" + :output-dir "target/test" + :optimizations :none + :target :nodejs}}]}} :prod {:cljsbuild {:builds {:ios - {:source-paths ["src" "env/prod"] + {:source-paths ["react-native/src" "src" "env/prod"] :compiler {:output-to "index.ios.js" :main "env.ios.main" :output-dir "target/ios-prod" @@ -67,9 +70,9 @@ :optimizations :advanced :externs ["externs/externs.js"] :closure-defines {"goog.DEBUG" false} - :parallel-build true}} + :parallel-build true}} :android - {:source-paths ["src" "env/prod"] + {:source-paths ["react-native/src" "src" "env/prod"] :compiler {:output-to "index.android.js" :main "env.android.main" :output-dir "target/android-prod" @@ -78,4 +81,4 @@ :optimizations :advanced :externs ["externs/externs.js"] :closure-defines {"goog.DEBUG" false} - :parallel-build true}}}}}}) + :parallel-build true}}}}}}) diff --git a/react-native/src/cljsjs/react.cljs b/react-native/src/cljsjs/react.cljs new file mode 100644 index 0000000000..81d07942a1 --- /dev/null +++ b/react-native/src/cljsjs/react.cljs @@ -0,0 +1,5 @@ +(ns cljsjs.react + (:require [status-im.react-native.js-dependencies :as rn-dependencies])) + +(when (exists? js/window) + (set! js/ReactNative rn-dependencies/react-native)) diff --git a/src/cljsjs/react/dom.cljs b/react-native/src/cljsjs/react/dom.cljs similarity index 100% rename from src/cljsjs/react/dom.cljs rename to react-native/src/cljsjs/react/dom.cljs diff --git a/src/cljsjs/react/dom/server.cljs b/react-native/src/cljsjs/react/dom/server.cljs similarity index 100% rename from src/cljsjs/react/dom/server.cljs rename to react-native/src/cljsjs/react/dom/server.cljs diff --git a/react-native/src/status_im/react_native/js_dependencies.cljs b/react-native/src/status_im/react_native/js_dependencies.cljs new file mode 100644 index 0000000000..6dcf455490 --- /dev/null +++ b/react-native/src/status_im/react_native/js_dependencies.cljs @@ -0,0 +1,35 @@ +(ns status-im.react-native.js-dependencies) + +(def action-button (js/require "react-native-action-button")) +(def android-sms-listener (js/require "react-native-android-sms-listener")) +(def autolink (js/require "react-native-autolink")) +(def camera (js/require "react-native-camera")) +(def circle-checkbox (js/require "react-native-circle-checkbox")) +;; TODO see https://github.com/rt2zz/react-native-contacts/issues/45 +(def contacts (js/require "react-native-contacts")) +(def dialogs (js/require "react-native-dialogs")) +(def dismiss-keyboard (js/require "dismissKeyboard")) +(def drawer (js/require "react-native-drawer-layout")) +(def emoji-picker (js/require "react-native-emoji-picker")) +(def fs (js/require "react-native-fs")) +(def http-bridge (js/require "react-native-http-bridge")) +(def i18n (js/require "react-native-i18n")) +(def image-crop-picker (js/require "react-native-image-crop-picker")) +(def image-resizer (js/require "react-native-image-resizer")) +(def instabug (js/require "instabug-reactnative")) +(def invertible-scroll-view (js/require "react-native-invertible-scroll-view")) +(def linear-gradient (js/require "react-native-linear-gradient")) +(def mapbox-gl (js/require "react-native-mapbox-gl")) +(def nfc (js/require "nfc-react-native")) +(def orientation (js/require "react-native-orientation")) +(def popup-menu (js/require "react-native-popup-menu")) +(def qr-code (js/require "react-native-qrcode")) +(def random-bytes (js/require "react-native-randombytes")) +(def react-native (js/require "react-native")) +(def realm (js/require "realm")) +(def sortable-listview (js/require "react-native-sortable-listview")) +(def swiper (js/require "react-native-swiper")) +(def vector-icons (js/require "react-native-vector-icons/Ionicons")) +(def webview-bridge (js/require "react-native-webview-bridge")) + + diff --git a/react-native/src/status_im/react_native/resources.cljs b/react-native/src/status_im/react_native/resources.cljs new file mode 100644 index 0000000000..9fa7f295f7 --- /dev/null +++ b/react-native/src/status_im/react_native/resources.cljs @@ -0,0 +1,29 @@ +(ns status-im.react-native.resources) + +(def add-icon (js/require "./images/add.png")) +(def att (js/require "./images/att.png")) +(def chat-icon (js/require "./images/chat.png")) +(def icon-close-gray (js/require "./images/icon_close_gray.png")) +(def logo-icon (js/require "./images/logo.png")) +(def nav-back-icon (js/require "./images/nav-back.png")) +(def user-no-photo (js/require "./images/no-photo.png")) +(def online-icon (js/require "./images/online.png")) +(def play (js/require "./images/play.png")) +(def trash-icon (js/require "./images/trash.png")) +(def v (js/require "./images/v.png")) + +(def contacts + {:auction-house (js/require "./images/contacts/auction-house.png") + :mkr-market (js/require "./images/contacts/mkr-market.png") + :oaken-water-meter (js/require "./images/contacts/oaken-water-meter.png") + :flight-delays-suck (js/require "./images/contacts/flight-delays-suck.png") + :jarrad (js/require "./images/contacts/jarrad.png") + :firstblood (js/require "./images/contacts/FirstBlood.png") + :gnosis (js/require "./images/contacts/gnosis.png") + :melonport (js/require "./images/contacts/melonport.png") + :bchat (js/require "./images/contacts/bchat.png") + :dentacoin (js/require "./images/contacts/Dentacoin.png") + :augur (js/require "./images/contacts/augur.png") + :ethlance (js/require "./images/contacts/ethlance.png") + :commiteth (js/require "./images/contacts/commiteth.png") + :etherplay (js/require "./images/contacts/etherplay.png")}) diff --git a/src/cljsjs/react.cljs b/src/cljsjs/react.cljs deleted file mode 100644 index 5a52465be6..0000000000 --- a/src/cljsjs/react.cljs +++ /dev/null @@ -1,4 +0,0 @@ -(ns cljsjs.react) - -(when (exists? js/window) - (set! js/ReactNative (js/require "react-native"))) diff --git a/src/status_im/android/platform.cljs b/src/status_im/android/platform.cljs index 78eda83509..1c5d4d6165 100644 --- a/src/status_im/android/platform.cljs +++ b/src/status_im/android/platform.cljs @@ -1,5 +1,6 @@ (ns status-im.android.platform - (:require [status-im.components.styles :as styles])) + (:require [status-im.components.styles :as styles] + [status-im.react-native.js-dependencies :as rn-dependencies])) (def component-styles {:status-bar {:default {:height 25 @@ -59,10 +60,8 @@ ;; Dialogs -(def react-native-dialogs (js/require "react-native-dialogs")) - (defn show-dialog [{:keys [title options callback]}] - (let [dialog (new react-native-dialogs)] + (let [dialog (new rn-dependencies/dialogs)] (.set dialog (clj->js {:title title :items (mapv :text options) :itemsCallback callback})) diff --git a/src/status_im/chat/handlers/webview_bridge.cljs b/src/status_im/chat/handlers/webview_bridge.cljs index 07c51dbe42..febda4cbe0 100644 --- a/src/status_im/chat/handlers/webview_bridge.cljs +++ b/src/status_im/chat/handlers/webview_bridge.cljs @@ -14,8 +14,6 @@ [cljs.reader :refer [read-string]] [status-im.navigation.handlers :as nav])) -(def web3 (js/require "web3")) - (defn by-public-key [public-key contacts] (when-let [{:keys [address]} (contacts public-key)] (when address {:address address}))) diff --git a/src/status_im/chat/models/input.cljs b/src/status_im/chat/models/input.cljs index 5389b48ce8..f4a3928ac9 100644 --- a/src/status_im/chat/models/input.cljs +++ b/src/status_im/chat/models/input.cljs @@ -8,6 +8,7 @@ [status-im.utils.phone-number :as phone-number] [status-im.chat.utils :as chat-utils] [status-im.bots.constants :as bots-constants] + [status-im.js-dependencies :as dependencies] [taoensso.timbre :as log])) (defn text->emoji @@ -17,7 +18,7 @@ (str/replace text #":([a-z_\-+0-9]*):" (fn [[original emoji-id]] - (if-let [emoji-map (aget rc/emojilib "lib" emoji-id)] + (if-let [emoji-map (aget dependencies/emojis "lib" emoji-id)] (aget emoji-map "char") original))))) @@ -266,4 +267,4 @@ (proceed) (set-errors [validation-message {:title (i18n/label :t/phone-number) - :description (i18n/label :t/invalid-phone)}])))) \ No newline at end of file + :description (i18n/label :t/invalid-phone)}])))) diff --git a/src/status_im/chat/views/message/message.cljs b/src/status_im/chat/views/message/message.cljs index b20bf79dc0..d3c1aa2534 100644 --- a/src/status_im/chat/views/message/message.cljs +++ b/src/status_im/chat/views/message/message.cljs @@ -23,7 +23,7 @@ [status-im.chat.views.message.datemark :refer [chat-datemark]] [status-im.models.commands :refer [parse-command-message-content parse-command-request]] - [status-im.resources :as res] + [status-im.react-native.resources :as res] [status-im.constants :refer [console-chat-id wallet-chat-id text-content-type diff --git a/src/status_im/components/camera.cljs b/src/status_im/components/camera.cljs index f1dfac22fc..465809e889 100644 --- a/src/status_im/components/camera.cljs +++ b/src/status_im/components/camera.cljs @@ -1,13 +1,13 @@ (ns status-im.components.camera (:require [reagent.core :as r] [clojure.walk :refer [keywordize-keys]] - [status-im.utils.platform :as platform])) + [status-im.utils.platform :as platform] + [status-im.react-native.js-dependencies :as rn-dependecies])) -(def camera-class (js/require "react-native-camera")) -(def camera-default (.-default camera-class)) +(def default-camera (.-default rn-dependecies/camera)) (defn constants [t] - (-> (aget camera-default "constants" t) + (-> (aget rn-dependecies/camera "constants" t) (js->clj) (keywordize-keys))) @@ -17,9 +17,9 @@ (defn request-access [callback] (if platform/android? (callback true) - (-> (.checkVideoAuthorizationStatus camera-default) + (-> (.checkVideoAuthorizationStatus default-camera) (.then #(callback %)) (.catch #(callback false))))) (defn camera [props] - (r/create-element camera-default (clj->js (merge {:inverted true} props)))) + (r/create-element default-camera (clj->js (merge {:inverted true} props)))) diff --git a/src/status_im/components/carousel/carousel.cljs b/src/status_im/components/carousel/carousel.cljs index bef7f195d5..95632c9be9 100644 --- a/src/status_im/components/carousel/carousel.cljs +++ b/src/status_im/components/carousel/carousel.cljs @@ -6,11 +6,12 @@ text]] [status-im.components.carousel.styles :as st] [taoensso.timbre :as log] - [status-im.components.react :as r])) + [status-im.components.react :as r] + [status-im.react-native.js-dependencies :as rn-dependencies])) (defn window-page-width [] - (.-width (.get (.. r/react-native -Dimensions) "window"))) + (.-width (.get (.. rn-dependencies/react-native -Dimensions) "window"))) (def defaults {:gap 8 :sneak 8 diff --git a/src/status_im/components/chat_icon/screen.cljs b/src/status_im/components/chat_icon/screen.cljs index 9df7b69e00..72819f9d36 100644 --- a/src/status_im/components/chat_icon/screen.cljs +++ b/src/status_im/components/chat_icon/screen.cljs @@ -7,7 +7,7 @@ icon]] [status-im.components.chat-icon.styles :as st] [status-im.components.styles :refer [default-chat-color]] - [status-im.resources :as resources] + [status-im.react-native.resources :as resources] [status-im.constants :refer [console-chat-id]] [clojure.string :as s])) @@ -159,4 +159,4 @@ edit? :edit?}] (let [color default-chat-color size (if edit? 70 56)] - [profile-icon-view photo-path name color edit? size])) \ No newline at end of file + [profile-icon-view photo-path name color edit? size])) diff --git a/src/status_im/components/context_menu.cljs b/src/status_im/components/context_menu.cljs index ffd3e12ed8..49b7006c94 100644 --- a/src/status_im/components/context_menu.cljs +++ b/src/status_im/components/context_menu.cljs @@ -4,12 +4,11 @@ [status-im.i18n :refer [label]] [status-im.utils.platform :refer [platform-specific ios?]] [re-frame.core :refer [dispatch]] - [status-im.components.react :refer [view touchable-highlight text]])) - -(def react-native-popup-menu (js/require "react-native-popup-menu")) + [status-im.components.react :refer [view touchable-highlight text]] + [status-im.react-native.js-dependencies :as rn-dependencies])) (defn get-property [name] - (aget react-native-popup-menu name)) + (aget rn-dependencies/popup-menu name)) (defn adapt-class [class] (when class diff --git a/src/status_im/components/icons/custom_icons.cljs b/src/status_im/components/icons/custom_icons.cljs index f88d23b6ab..e9ece8c50b 100644 --- a/src/status_im/components/icons/custom_icons.cljs +++ b/src/status_im/components/icons/custom_icons.cljs @@ -1,5 +1,6 @@ (ns status-im.components.icons.custom-icons - (:require [reagent.core :as r])) + (:require [reagent.core :as r] + [status-im.react-native.js-dependencies :as rn-dependencies])) (def ion-icon - (r/adapt-react-class (.-default (js/require "react-native-vector-icons/Ionicons")))) \ No newline at end of file + (r/adapt-react-class (.-default rn-dependencies/vector-icons))) diff --git a/src/status_im/components/invertible_scroll_view.cljs b/src/status_im/components/invertible_scroll_view.cljs index 429d66d6ed..d7b00172d3 100644 --- a/src/status_im/components/invertible_scroll_view.cljs +++ b/src/status_im/components/invertible_scroll_view.cljs @@ -1,8 +1,8 @@ (ns status-im.components.invertible-scroll-view - (:require [reagent.core :as r])) - -(def class (js/require "react-native-invertible-scroll-view")) + (:require [reagent.core :as r] + [status-im.react-native.js-dependencies :as rn-dependencies])) (defn invertible-scroll-view [props] - (r/create-element class (clj->js (merge {:inverted true} props)))) + (r/create-element rn-dependencies/invertible-scroll-view + (clj->js (merge {:inverted true} props)))) diff --git a/src/status_im/components/item_checkbox.cljs b/src/status_im/components/item_checkbox.cljs index 45c667141d..7bb8c02e23 100644 --- a/src/status_im/components/item_checkbox.cljs +++ b/src/status_im/components/item_checkbox.cljs @@ -1,5 +1,6 @@ (ns status-im.components.item-checkbox - (:require [reagent.core :as r])) + (:require [reagent.core :as r] + [status-im.react-native.js-dependencies :as rn-dependencies])) -(def item-checkbox (r/adapt-react-class (js/require "react-native-circle-checkbox"))) +(def item-checkbox rn-dependencies/camera) diff --git a/src/status_im/components/mapbox.cljs b/src/status_im/components/mapbox.cljs index 0b021ff556..fdde7df033 100644 --- a/src/status_im/components/mapbox.cljs +++ b/src/status_im/components/mapbox.cljs @@ -4,12 +4,11 @@ [status-im.i18n :refer [label]] [status-im.utils.platform :refer [platform-specific ios?]] [re-frame.core :refer [dispatch]] - [status-im.components.react :refer [view touchable-highlight text]])) - -(def react-native-mapbox-gl (js/require "react-native-mapbox-gl")) + [status-im.components.react :refer [view touchable-highlight text]] + [status-im.react-native.js-dependencies :as rn-dependencies])) (defn get-property [name] - (aget react-native-mapbox-gl name)) + (aget rn-dependencies/mapbox-gl name)) (defn adapt-class [class] (when class @@ -18,6 +17,6 @@ (defn get-class [name] (adapt-class (get-property name))) -(.setAccessToken react-native-mapbox-gl "pk.eyJ1Ijoic3RhdHVzaW0iLCJhIjoiY2oydmtnZjRrMDA3czMzcW9kemR4N2lxayJ9.Rz8L6xdHBjfO8cR3CDf3Cw") +(.setAccessToken rn-dependencies/mapbox-gl "pk.eyJ1Ijoic3RhdHVzaW0iLCJhIjoiY2oydmtnZjRrMDA3czMzcW9kemR4N2lxayJ9.Rz8L6xdHBjfO8cR3CDf3Cw") (def mapview (get-class "MapView")) diff --git a/src/status_im/components/native_action_button.cljs b/src/status_im/components/native_action_button.cljs index 8ff80c068f..07a484b689 100644 --- a/src/status_im/components/native_action_button.cljs +++ b/src/status_im/components/native_action_button.cljs @@ -1,7 +1,10 @@ (ns status-im.components.native-action-button - (:require [reagent.core :as r])) + (:require [reagent.core :as r] + [status-im.react-native.js-dependencies :as rn-dependencies])) -(def class (js/require "react-native-action-button")) +(def native-action-button + (r/adapt-react-class (.-default rn-dependencies/action-button))) -(def native-action-button (r/adapt-react-class (.-default class))) -(def native-action-button-item (r/adapt-react-class (.. class -default -Item))) + +(def native-action-button-item + (r/adapt-react-class (.. rn-dependencies/action-button -default -Item))) diff --git a/src/status_im/components/nfc.cljs b/src/status_im/components/nfc.cljs index 1aa6150ceb..957bab5de0 100644 --- a/src/status_im/components/nfc.cljs +++ b/src/status_im/components/nfc.cljs @@ -1,30 +1,27 @@ (ns status-im.components.nfc (:require [cljs.spec.alpha :as s] - [status-im.utils.platform :as platform])) - -(def class - (when platform/android? - (js/require "nfc-react-native"))) + [status-im.utils.platform :as platform] + [status-im.react-native.js-dependencies :as rn-dependencies])) (def android-only-error "NFC API is available only on Android") (defn get-card-id [on-success on-error] (if platform/android? - (-> (.getCardId class) + (-> (.getCardId rn-dependencies/nfc) (.then on-success) (.catch on-error)) (on-error android-only-error))) (defn read-tag [sectors on-success on-error] (if platform/android? - (-> (.readTag class (clj->js sectors)) + (-> (.readTag rn-dependencies/nfc (clj->js sectors)) (.then on-success) (.catch on-error)) (on-error android-only-error))) (defn write-tag [sectors card-id on-success on-error] (if platform/android? - (-> (.writeTag class (clj->js sectors) card-id) + (-> (.writeTag rn-dependencies/nfc (clj->js sectors) card-id) (.then on-success) (.catch on-error)) (on-error android-only-error))) diff --git a/src/status_im/components/permissions.cljs b/src/status_im/components/permissions.cljs index f8dd425759..f440f0fd6f 100644 --- a/src/status_im/components/permissions.cljs +++ b/src/status_im/components/permissions.cljs @@ -1,8 +1,9 @@ (ns status-im.components.permissions (:require [status-im.utils.platform :as platform] - [taoensso.timbre :as log])) + [taoensso.timbre :as log] + [status-im.react-native.js-dependencies :as rn-dependencies])) -(def permissions-class (.-PermissionsAndroid js/ReactNative)) +(def permissions-class (.-PermissionsAndroid rn-dependencies/react-native)) (def permissions-map {:read-external-storage "android.permission.READ_EXTERNAL_STORAGE" diff --git a/src/status_im/components/qr_code.cljs b/src/status_im/components/qr_code.cljs index e06b1e25ab..300629786d 100644 --- a/src/status_im/components/qr_code.cljs +++ b/src/status_im/components/qr_code.cljs @@ -1,9 +1,8 @@ (ns status-im.components.qr-code - (:require [reagent.core :as r])) - -(def class (js/require "react-native-qrcode")) + (:require [reagent.core :as r] + [status-im.react-native.js-dependencies :as rn-dependencies])) (defn qr-code [props] (r/create-element - class - (clj->js (merge {:inverted true} props)))) \ No newline at end of file + rn-dependencies/qr-code + (clj->js (merge {:inverted true} props)))) diff --git a/src/status_im/components/react.cljs b/src/status_im/components/react.cljs index 47c1181e08..8b6fff07dd 100644 --- a/src/status_im/components/react.cljs +++ b/src/status_im/components/react.cljs @@ -1,18 +1,29 @@ (ns status-im.components.react (:require [reagent.core :as r] [status-im.components.styles :as st] - [status-im.utils.utils :as u - :refer [get-react-property get-class adapt-class]] + [status-im.utils.utils :as u] [status-im.utils.platform :refer [platform-specific ios?]] - [status-im.i18n :as i18n])) + [status-im.i18n :as i18n] + [status-im.react-native.js-dependencies :as rn-dependencies])) -(def react-native (js/require "react-native")) -(def native-modules (.-NativeModules react-native)) -(def device-event-emitter (.-DeviceEventEmitter react-native)) -(def dismiss-keyboard! (js/require "dismissKeyboard")) -(def orientation (js/require "react-native-orientation")) +(defn get-react-property [name] + (if rn-dependencies/react-native + (aget rn-dependencies/react-native name) + #js {})) + +(defn adapt-class [class] + (when class + (r/adapt-react-class class))) + +(defn get-class [name] + (adapt-class (get-react-property name))) + +(def native-modules (.-NativeModules rn-dependencies/react-native)) +(def device-event-emitter (.-DeviceEventEmitter rn-dependencies/react-native)) +(def dismiss-keyboard! rn-dependencies/dismiss-keyboard) +(def orientation rn-dependencies/orientation) (def back-android (get-react-property "BackAndroid")) -(def drawer (js/require "react-native-drawer-layout")) +(def drawer rn-dependencies/drawer) (def splash-screen (.-SplashScreen native-modules)) @@ -20,6 +31,7 @@ (def app-registry (get-react-property "AppRegistry")) (def app-state (get-react-property "AppState")) +(def net-info (get-react-property "NetInfo")) (def navigator (get-class "Navigator")) (def view (get-class "View")) @@ -43,14 +55,14 @@ (def modal (get-class "Modal")) (def picker (get-class "Picker")) -(def pan-responder (.-PanResponder js/ReactNative)) -(def animated (.-Animated js/ReactNative)) +(def pan-responder (.-PanResponder rn-dependencies/react-native)) +(def animated (.-Animated rn-dependencies/react-native)) (def animated-view (r/adapt-react-class (.-View animated))) (def animated-text (r/adapt-react-class (.-Text animated))) -(def dimensions (.-Dimensions js/ReactNative)) -(def keyboard (.-Keyboard react-native)) -(def linking (.-Linking js/ReactNative)) +(def dimensions (.-Dimensions rn-dependencies/react-native)) +(def keyboard (.-Keyboard rn-dependencies/react-native)) +(def linking (.-Linking rn-dependencies/react-native)) (def slider (get-class "Slider")) ;; Accessor methods for React Components @@ -108,17 +120,17 @@ (defn get-dimensions [name] (js->clj (.get dimensions name) :keywordize-keys true)) +(def gradient (adapt-class (.-default rn-dependencies/linear-gradient))) + (defn linear-gradient [props] - (let [class (js/require "react-native-linear-gradient") - gradient (adapt-class (.-default class))] - [gradient props])) + [gradient props]) (defn list-item [component] (r/as-element component)) ;; Image picker -(def image-picker-class (js/require "react-native-image-crop-picker")) +(def image-picker-class rn-dependencies/image-crop-picker) (defn show-access-error [o] (when (= "ERROR_PICKER_UNAUTHORIZED_KEY" (aget o "code")) ; Do not show error when user cancel selection @@ -132,19 +144,19 @@ (.then images-fn) (.catch show-access-error)))) -(def swiper (adapt-class (js/require "react-native-swiper"))) +(def swiper (adapt-class rn-dependencies/swiper)) ;; Clipboard (def sharing - (.-Share js/ReactNative)) + (.-Share rn-dependencies/react-native)) (defn copy-to-clipboard [text] - (.setString (.-Clipboard react-native) text)) + (.setString (.-Clipboard rn-dependencies/react-native) text)) ;; Emoji -(def emoji-picker-class (js/require "react-native-emoji-picker")) +(def emoji-picker-class rn-dependencies/emoji-picker) (def emoji-picker (let [emoji-picker (.-default emoji-picker-class)] @@ -152,7 +164,7 @@ ;; Autolink -(def autolink-class (r/adapt-react-class (.-default (js/require "react-native-autolink")))) +(def autolink-class (r/adapt-react-class (.-default rn-dependencies/autolink))) (defn autolink [opts] (r/as-element @@ -160,8 +172,7 @@ ;; HTTP Bridge -(def http-bridge - (js/require "react-native-http-bridge")) +(def http-bridge rn-dependencies/http-bridge) ;; KeyboardAvoidingView diff --git a/src/status_im/components/sortable_list_view.cljs b/src/status_im/components/sortable_list_view.cljs index bda52af1b4..72feeb884d 100644 --- a/src/status_im/components/sortable_list_view.cljs +++ b/src/status_im/components/sortable_list_view.cljs @@ -2,12 +2,14 @@ (:require [reagent.core :as r] [status-im.components.react :refer [view touchable-highlight - list-item]])) + list-item]] + [status-im.react-native.js-dependencies :as rn-dependencies])) -(def sortable-list-view-class (r/adapt-react-class (js/require "react-native-sortable-listview"))) +(def sortable-listview-class + (r/adapt-react-class rn-dependencies/sortable-listview)) (defn sortable-list-view [{:keys [on-row-moved render-row] :as props}] - [sortable-list-view-class + [sortable-listview-class (assoc props :on-row-moved #(on-row-moved (js->clj % :keywordize-keys true)) :render-row #(render-row (js->clj % :keywordize-keys true)))]) @@ -17,4 +19,4 @@ inner]]) (defn sortable-item [inner] - (list-item [touchable inner])) \ No newline at end of file + (list-item [touchable inner])) diff --git a/src/status_im/components/status.cljs b/src/status_im/components/status.cljs index f2de4f43ec..1b0ae633f3 100644 --- a/src/status_im/components/status.cljs +++ b/src/status_im/components/status.cljs @@ -7,9 +7,9 @@ [taoensso.timbre :as log] [cljs.core.async :refer [json [data] (.stringify js/JSON (clj->js data))) @@ -48,11 +48,11 @@ (recur (clj r) {:keys [messages]} result] diff --git a/src/status_im/components/text_field/view.cljs b/src/status_im/components/text_field/view.cljs index 9bf569eaa3..71c8ed4765 100644 --- a/src/status_im/components/text_field/view.cljs +++ b/src/status_im/components/text_field/view.cljs @@ -2,8 +2,7 @@ (:require [clojure.string :as s] [re-frame.core :refer [subscribe dispatch dispatch-sync]] [reagent.core :as r] - [status-im.components.react :refer [react-native - view + [status-im.components.react :refer [view text animated-text animated-view diff --git a/src/status_im/components/webview_bridge.cljs b/src/status_im/components/webview_bridge.cljs index e41023aa49..ff5f142841 100644 --- a/src/status_im/components/webview_bridge.cljs +++ b/src/status_im/components/webview_bridge.cljs @@ -1,8 +1,9 @@ (ns status-im.components.webview-bridge - (:require [reagent.core :as r])) + (:require [reagent.core :as r] + [status-im.react-native.js-dependencies :as rn-dependencies])) (def webview-bridge-class - (r/adapt-react-class (.-default (js/require "react-native-webview-bridge")))) + (r/adapt-react-class (.-default rn-dependencies/webview-bridge))) (defn webview-bridge [opts] [webview-bridge-class opts]) diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index c92a78b916..b64566cf8d 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -8,13 +8,13 @@ [status-im.utils.utils :refer [http-post]] [status-im.utils.phone-number :refer [format-phone-number]] [status-im.utils.handlers :as u] - [status-im.utils.utils :refer [require]] [status-im.navigation.handlers :as nav] [status-im.utils.random :as random] [status-im.i18n :refer [label]] [taoensso.timbre :as log] [cljs.reader :refer [read-string]] - [status-im.utils.js-resources :as js-res])) + [status-im.utils.js-resources :as js-res] + [status-im.react-native.js-dependencies :as rn-dependencies])) (defmethod nav/preload-data! :group-contacts [db [_ _ group show-search?]] @@ -122,9 +122,6 @@ (register-handler :load-contacts load-contacts!) -;; TODO see https://github.com/rt2zz/react-native-contacts/issues/45 -(def react-native-contacts (js/require "react-native-contacts")) - (defn contact-name [contact] (->> contact ((juxt :givenName :middleName :familyName)) @@ -140,7 +137,7 @@ (defn fetch-contacts-from-phone! [_ _] - (.getAll react-native-contacts + (.getAll rn-dependencies/contacts (fn [error contacts] (if error (log/debug :error-on-fetching-loading error) diff --git a/src/status_im/contacts/validations.cljs b/src/status_im/contacts/validations.cljs index 0540aedeb8..429ece54a0 100644 --- a/src/status_im/contacts/validations.cljs +++ b/src/status_im/contacts/validations.cljs @@ -3,7 +3,6 @@ [clojure.string :as str] [status-im.data-store.contacts :as contacts])) -(def web3 (js/require "web3")) (defn is-address? [s] (.isAddress web3.prototype s)) diff --git a/src/status_im/contacts/views/new_contact.cljs b/src/status_im/contacts/views/new_contact.cljs index 395b557b7d..fb23b875a4 100644 --- a/src/status_im/contacts/views/new_contact.cljs +++ b/src/status_im/contacts/views/new_contact.cljs @@ -14,7 +14,7 @@ [status-im.components.toolbar.styles :refer [toolbar-title-container toolbar-title-text toolbar-background1]] - [status-im.utils.utils :refer [log http-post]] + [status-im.utils.utils :refer [http-post]] [status-im.components.styles :refer [icon-ok button-input-container button-input diff --git a/src/status_im/data_store/realm/core.cljs b/src/status_im/data_store/realm/core.cljs index 808b5ddcd2..959a0ea019 100644 --- a/src/status_im/data_store/realm/core.cljs +++ b/src/status_im/data_store/realm/core.cljs @@ -5,23 +5,23 @@ [taoensso.timbre :as log] [status-im.utils.fs :as fs] [clojure.string :as str] - [goog.string :as gstr]) + [goog.string :as gstr] + [status-im.react-native.js-dependencies :as rn-dependencies]) (:refer-clojure :exclude [exists?])) -(def realm-class (js/require "realm")) - (defn realm-version [file-name] - (.schemaVersion realm-class file-name)) + (.schemaVersion rn-dependencies/realm file-name)) (defn open-realm [options file-name] (let [options (merge options {:path file-name})] (when (cljs.core/exists? js/window) - (realm-class. (clj->js options))))) + (rn-dependencies/realm. (clj->js options))))) (defn close [realm] - (.close realm)) + (when realm + (.close realm))) (defn migrate [file-name schemas] (let [current-version (realm-version file-name)] @@ -37,7 +37,7 @@ (def new-account-filename "new-account") -(def base-realm (open-migrated-realm (.-defaultPath realm-class) base/schemas)) +(def base-realm (open-migrated-realm (.-defaultPath rn-dependencies/realm) base/schemas)) (def account-realm (atom (open-migrated-realm new-account-filename account/schemas))) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index cb876833a6..abfd3260ce 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -30,7 +30,8 @@ [status-im.constants :refer [console-chat-id]] [status-im.utils.ethereum-network :as enet] [status-im.utils.instabug :as inst] - [status-im.utils.platform :as p])) + [status-im.utils.platform :as p] + [status-im.js-dependencies :as dependencies])) ;; -- Common -------------------------------------------------------------- @@ -100,23 +101,23 @@ (dispatch [:load-commands!]) (when callback (callback)))))) -(def ecc (js/require "eccjs")) - (register-handler :initialize-crypt (u/side-effect! (fn [_ _] (log/debug "initializing crypt") - (gen-random-bytes 1024 (fn [{:keys [error buffer]}] - (if error - (do - (log/error "Failed to generate random bytes to initialize sjcl crypto") - (dispatch [:notify-user {:type :error - :error error}])) - (do - (->> (.toString buffer "hex") - (.toBits (.. ecc -sjcl -codec -hex)) - (.addEntropy (.. ecc -sjcl -random))) - (dispatch [:crypt-initialized])))))))) + (gen-random-bytes + 1024 + (fn [{:keys [error buffer]}] + (if error + (do + (log/error "Failed to generate random bytes to initialize sjcl crypto") + (dispatch [:notify-user {:type :error + :error error}])) + (do + (->> (.toString buffer "hex") + (.toBits (.. dependencies/eccjs -sjcl -codec -hex)) + (.addEntropy (.. dependencies/eccjs -sjcl -random))) + (dispatch [:crypt-initialized])))))))) (defn node-started [_ _] (log/debug "Started Node") diff --git a/src/status_im/i18n.cljs b/src/status_im/i18n.cljs index 7c43380d40..8115770311 100644 --- a/src/status_im/i18n.cljs +++ b/src/status_im/i18n.cljs @@ -1,5 +1,6 @@ (ns status-im.i18n (:require + [status-im.react-native.js-dependencies :as rn-dependencies] [status-im.translations.af :as af] [status-im.translations.ar :as ar] [status-im.translations.bel :as be] @@ -48,11 +49,10 @@ [taoensso.timbre :as log] [clojure.string :as str])) -(def i18n (js/require "react-native-i18n")) -(set! (.-fallbacks i18n) true) -(set! (.-defaultSeparator i18n) "/") +(set! (.-fallbacks rn-dependencies/i18n) true) +(set! (.-defaultSeparator rn-dependencies/i18n) "/") -(set! (.-translations i18n) (clj->js {:af af/translations +(set! (.-translations rn-dependencies/i18n) (clj->js {:af af/translations :ar ar/translations :be be/translations :da da/translations @@ -124,7 +124,7 @@ (defn label-number [number] (when number (let [{:keys [delimiter separator]} delimeters] - (.toNumber i18n + (.toNumber rn-dependencies/i18n (str/replace number #"," ".") (clj->js {:precision 10 :strip_insignificant_zeros true @@ -134,14 +134,14 @@ (defn label ([path] (label path {})) ([path options] - (if (exists? i18n.t) + (if (exists? rn-dependencies/i18n.t) (let [options (update options :amount label-number)] - (.t i18n (name path) (clj->js options))) + (.t rn-dependencies/i18n (name path) (clj->js options))) (name path)))) (defn label-pluralize [count path & options] - (if (exists? i18n.t) - (.p i18n count (name path) (clj->js options)) + (if (exists? rn-dependencies/i18n.t) + (.p rn-dependencies/i18n count (name path) (clj->js options)) (name path))) (defn message-status-label [status] @@ -152,7 +152,7 @@ (label))) (def locale - (.-locale i18n)) + (.-locale rn-dependencies/i18n)) (defn get-contact-translated [contact-id key fallback] (let [translation #(get-in default-contacts [(keyword contact-id) key (keyword %)])] diff --git a/src/status_im/ios/platform.cljs b/src/status_im/ios/platform.cljs index 206272bd1d..2b547e3618 100644 --- a/src/status_im/ios/platform.cljs +++ b/src/status_im/ios/platform.cljs @@ -1,7 +1,8 @@ (ns status-im.ios.platform (:require [status-im.components.styles :as styles] [status-im.i18n :refer [label]] - [status-im.utils.utils :as utils])) + [status-im.utils.utils :as utils] + [status-im.react-native.js-dependencies :as rn-dependencies])) (def component-styles {:status-bar {:default {:height 20 @@ -69,8 +70,6 @@ ;; Dialogs -(def react-native (js/require "react-native")) - (defn action-sheet-options [options] (let [destructive-opt-index (utils/first-index :destructive? options) cancel-option {:text (label :t/cancel)} @@ -80,7 +79,7 @@ (when destructive-opt-index {:destructiveButtonIndex destructive-opt-index}))))) (defn show-action-sheet [{:keys [options callback]}] - (.showActionSheetWithOptions (.-ActionSheetIOS react-native) + (.showActionSheetWithOptions (.-ActionSheetIOS rn-dependencies/react-native) (action-sheet-options options) callback)) diff --git a/src/status_im/js_dependencies.cljs b/src/status_im/js_dependencies.cljs new file mode 100644 index 0000000000..952dacdcb3 --- /dev/null +++ b/src/status_im/js_dependencies.cljs @@ -0,0 +1,9 @@ +(ns status-im.js-dependencies) + +(def awesome-phonenumber (js/require "awesome-phonenumber")) +(def Chance (js/require "chance")) +(def eccjs (js/require "eccjs")) +(def emojis (js/require "emojilib")) +(def homoglyph-finder (js/require "homoglyph-finder")) +(def identicon-js (js/require "identicon.js")) +(def Web3 (js/require "web3")) diff --git a/src/status_im/network/net_info.cljs b/src/status_im/network/net_info.cljs index 86bfcd6d0c..9559c10f91 100644 --- a/src/status_im/network/net_info.cljs +++ b/src/status_im/network/net_info.cljs @@ -1,16 +1,14 @@ (ns status-im.network.net-info - (:require [status-im.utils.utils :as u] - [taoensso.timbre :as log])) - -(def net-info (u/get-react-property "NetInfo")) + (:require [taoensso.timbre :as log] + [status-im.components.react :as react-components])) (defn init [callback] - (when net-info - (.then (.fetch (.-isConnected net-info)) + (when react-components/net-info + (.then (.fetch (.-isConnected react-components/net-info)) (fn [is-connected?] (log/debug "Is connected?" is-connected?) (callback is-connected?))))) (defn add-listener [listener] - (when net-info - (.addEventListener (.-isConnected net-info) "change" listener))) + (when react-components/net-info + (.addEventListener (.-isConnected react-components/net-info) "change" listener))) diff --git a/src/status_im/new_group/screen_public.cljs b/src/status_im/new_group/screen_public.cljs index ce50cfaacc..f375b72959 100644 --- a/src/status_im/new_group/screen_public.cljs +++ b/src/status_im/new_group/screen_public.cljs @@ -1,7 +1,7 @@ (ns status-im.new-group.screen-public (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch]] - [status-im.resources :as res] + [status-im.react-native.resources :as res] [status-im.components.react :refer [view text image diff --git a/src/status_im/participants/views/add.cljs b/src/status_im/participants/views/add.cljs index 5a43bfef47..92c3b7ba8d 100644 --- a/src/status_im/participants/views/add.cljs +++ b/src/status_im/participants/views/add.cljs @@ -1,7 +1,7 @@ (ns status-im.participants.views.add (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch]] - [status-im.resources :as res] + [status-im.react-native.resources :as res] [status-im.components.react :refer [view list-view list-item]] [status-im.components.status-bar :refer [status-bar]] [status-im.components.toolbar.view :refer [toolbar]] diff --git a/src/status_im/participants/views/remove.cljs b/src/status_im/participants/views/remove.cljs index d7628d33fb..c3cd2424b2 100644 --- a/src/status_im/participants/views/remove.cljs +++ b/src/status_im/participants/views/remove.cljs @@ -1,7 +1,7 @@ (ns status-im.participants.views.remove (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch]] - [status-im.resources :as res] + [status-im.react-native.resources :as res] [status-im.components.react :refer [view text image diff --git a/src/status_im/protocol/encryption.cljs b/src/status_im/protocol/encryption.cljs index cc4791bc20..5fb9fa23bd 100644 --- a/src/status_im/protocol/encryption.cljs +++ b/src/status_im/protocol/encryption.cljs @@ -1,22 +1,21 @@ -(ns status-im.protocol.encryption) +(ns status-im.protocol.encryption + (:require [status-im.js-dependencies :as dependencies])) (def default-curve 384) -(def ecc (js/require "eccjs")) - (defn new-keypair! "Returns {:private \"private key\" :public \"public key\"" [] (let [{:keys [enc dec]} - (-> ecc - (.generate (.-ENC_DEC ecc) default-curve) + (-> dependencies/eccjs + (.generate (.-ENC_DEC dependencies/eccjs) default-curve) (js->clj :keywordize-keys true))] {:private dec :public enc})) (defn encrypt [public-key content] - (.encrypt ecc public-key content)) + (.encrypt dependencies/eccjs public-key content)) (defn decrypt [private-key content] - (.decrypt ecc private-key content)) + (.decrypt dependencies/eccjs private-key content)) diff --git a/src/status_im/protocol/web3/utils.cljs b/src/status_im/protocol/web3/utils.cljs index e42882f2a5..683b033730 100644 --- a/src/status_im/protocol/web3/utils.cljs +++ b/src/status_im/protocol/web3/utils.cljs @@ -1,18 +1,17 @@ (ns status-im.protocol.web3.utils (:require [cljs-time.core :refer [now]] [cljs-time.coerce :refer [to-long]] - [status-im.utils.web-provider :as w3])) - -(def web3 (js/require "web3")) + [status-im.utils.web3-provider :as w3] + [status-im.js-dependencies :as dependencies])) (defn from-utf8 [s] - (.fromUtf8 web3.prototype s)) + (.fromUtf8 dependencies/Web3.prototype s)) (defn to-ascii [s] - (.toAscii web3.prototype s)) + (.toAscii dependencies/Web3.prototype s)) (defn to-utf8 [s] - (.toUtf8 web3.prototype (str s))) + (.toUtf8 dependencies/Web3.prototype (str s))) (defn shh [web3] (.-shh web3)) @@ -20,7 +19,7 @@ (defn make-web3 [rpc-url] (->> rpc-url w3/get-provider - web3.)) + dependencies/Web3.)) (defn timestamp [] (to-long (now))) diff --git a/src/status_im/resources.cljs b/src/status_im/resources.cljs deleted file mode 100644 index bd5e6f395d..0000000000 --- a/src/status_im/resources.cljs +++ /dev/null @@ -1,35 +0,0 @@ -(ns status-im.resources) - -(def add-icon (js/require "./images/add.png")) -(def att (js/require "./images/att.png")) -(def chat-icon (js/require "./images/chat.png")) -(def delivered-icon (js/require "./images/delivered.png")) -(def delivery-failed-icon (js/require "./images/deliveryfailed.png")) -(def icon-close-gray (js/require "./images/icon_close_gray.png")) -(def leave-icon (js/require "./images/leave.png")) -(def logo-icon (js/require "./images/logo.png")) -(def mic (js/require "./images/mic.png")) -(def nav-back-icon (js/require "./images/nav-back.png")) -(def user-no-photo (js/require "./images/no-photo.png")) -(def online-icon (js/require "./images/online.png")) -(def play (js/require "./images/play.png")) -(def seen-icon (js/require "./images/seen.png")) -(def smile (js/require "./images/smile.png")) -(def trash-icon (js/require "./images/trash.png")) -(def v (js/require "./images/v.png")) - -(def contacts - {:auction-house (js/require "./images/contacts/auction-house.png") - :mkr-market (js/require "./images/contacts/mkr-market.png") - :oaken-water-meter (js/require "./images/contacts/oaken-water-meter.png") - :flight-delays-suck (js/require "./images/contacts/flight-delays-suck.png") - :jarrad (js/require "./images/contacts/jarrad.png") - :firstblood (js/require "./images/contacts/FirstBlood.png") - :gnosis (js/require "./images/contacts/gnosis.png") - :melonport (js/require "./images/contacts/melonport.png") - :bchat (js/require "./images/contacts/bchat.png") - :dentacoin (js/require "./images/contacts/Dentacoin.png") - :augur (js/require "./images/contacts/augur.png") - :ethlance (js/require "./images/contacts/ethlance.png") - :commiteth (js/require "./images/contacts/commiteth.png") - :etherplay (js/require "./images/contacts/etherplay.png")}) diff --git a/src/status_im/utils/crypt.cljs b/src/status_im/utils/crypt.cljs index 87730efe8c..b62f3f262c 100644 --- a/src/status_im/utils/crypt.cljs +++ b/src/status_im/utils/crypt.cljs @@ -1,10 +1,9 @@ (ns status-im.utils.crypt (:require [goog.crypt :refer [byteArrayToHex]] - [clojure.string :as s]) + [clojure.string :as s] + [status-im.react-native.js-dependencies :as rn-dependencies]) (:import goog.crypt.Sha256)) -(def random-bytes (js/require "react-native-randombytes")) - (def sha-256 (Sha256.)) (defn bytes-to-str [arr] @@ -19,7 +18,9 @@ (byteArrayToHex (.digest sha-256))) (defn gen-random-bytes [length cb] - (.randomBytes random-bytes length (fn [& [err buf]] - (if err - (cb {:error err}) - (cb {:buffer buf}))))) + (.randomBytes rn-dependencies/random-bytes + length + (fn [& [err buf]] + (if err + (cb {:error err}) + (cb {:buffer buf}))))) diff --git a/src/status_im/utils/ethereum_network.cljs b/src/status_im/utils/ethereum_network.cljs index 084aad1cb6..f101ef42d1 100644 --- a/src/status_im/utils/ethereum_network.cljs +++ b/src/status_im/utils/ethereum_network.cljs @@ -1,11 +1,10 @@ (ns status-im.utils.ethereum-network (:require [status-im.constants :as c] - [status-im.utils.web-provider :as w3])) - -(def Web3 (js/require "web3")) + [status-im.utils.web3-provider :as w3] + [status-im.js-dependencies :as dependencies])) (defn web3 [] - (Web3. (w3/get-provider c/ethereum-rpc-url))) + (dependencies/Web3. (w3/get-provider c/ethereum-rpc-url))) (def networks {"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" :mainnet diff --git a/src/status_im/utils/fs.cljs b/src/status_im/utils/fs.cljs index 528ad496f4..38b02db7be 100644 --- a/src/status_im/utils/fs.cljs +++ b/src/status_im/utils/fs.cljs @@ -1,13 +1,12 @@ -(ns status-im.utils.fs) - -(def fs (js/require "react-native-fs")) +(ns status-im.utils.fs + (:require [status-im.react-native.js-dependencies :as rn-dependencies])) (defn move-file [src dst handler] - (-> (.moveFile fs src dst) + (-> (.moveFile rn-dependencies/fs src dst) (.then #(handler nil %)) (.catch #(handler % nil)))) (defn read-file [path encoding on-read on-error] - (-> (.readFile fs path encoding) + (-> (.readFile rn-dependencies/fs path encoding) (.then on-read) (.catch on-error))) diff --git a/src/status_im/utils/homoglyph.cljs b/src/status_im/utils/homoglyph.cljs index b19e56ffbc..ad2dffe555 100644 --- a/src/status_im/utils/homoglyph.cljs +++ b/src/status_im/utils/homoglyph.cljs @@ -1,6 +1,5 @@ -(ns status-im.utils.homoglyph) - -(def homoglyph-finder (js/require "homoglyph-finder")) +(ns status-im.utils.homoglyph + (:require [status-im.js-dependencies :as dependencies])) (defn matches [s1 s2] - (.isMatches homoglyph-finder s1 s2)) + (.isMatches dependencies/homoglyph-finder s1 s2)) diff --git a/src/status_im/utils/identicon.cljs b/src/status_im/utils/identicon.cljs index d4eeae1937..f81c7c9409 100644 --- a/src/status_im/utils/identicon.cljs +++ b/src/status_im/utils/identicon.cljs @@ -1,11 +1,11 @@ -(ns status-im.utils.identicon) +(ns status-im.utils.identicon + (:require [status-im.js-dependencies :as dependencies])) (def default-size 40) -(def identicon-js (js/require "identicon.js")) - (defn identicon ([hash] (identicon hash default-size)) ([hash options] - (str "data:image/png;base64," (str (new identicon-js hash options))))) + (str "data:image/png;base64," + (str (new dependencies/identicon-js hash options))))) diff --git a/src/status_im/utils/image_processing.cljs b/src/status_im/utils/image_processing.cljs index b639e33e1e..74ac2c9c3f 100644 --- a/src/status_im/utils/image_processing.cljs +++ b/src/status_im/utils/image_processing.cljs @@ -1,12 +1,11 @@ (ns status-im.utils.image-processing (:require [status-im.utils.fs :refer [read-file]] [taoensso.timbre :as log] - [clojure.string :as str])) - -(def resizer-class (js/require "react-native-image-resizer")) + [clojure.string :as str] + [status-im.react-native.js-dependencies :as rn-dependencies])) (defn- resize [path max-width max-height on-resize on-error] - (let [resize-fn (aget resizer-class "default" "createResizedImage")] + (let [resize-fn (aget rn-dependencies/image-resizer "default" "createResizedImage")] (-> (resize-fn path max-width max-height "JPEG" 75 0 nil) (.then on-resize) (.catch on-error)))) diff --git a/src/status_im/utils/instabug.cljs b/src/status_im/utils/instabug.cljs index c757154c1a..7ca1d5a932 100644 --- a/src/status_im/utils/instabug.cljs +++ b/src/status_im/utils/instabug.cljs @@ -1,12 +1,11 @@ (ns status-im.utils.instabug - (:require [taoensso.timbre :as log])) - -(def instabug-rn (js/require "instabug-reactnative")) + (:require [taoensso.timbre :as log] + [status-im.react-native.js-dependencies :as rn-dependencies])) (defn log [str] (if js/goog.DEBUG (log/debug str) - (.IBGLog instabug-rn str))) + (.IBGLog rn-dependencies/instabug str))) (defn instabug-appender [] {:enabled? true diff --git a/src/status_im/utils/phone_number.cljs b/src/status_im/utils/phone_number.cljs index 488cd784f4..a95baecefb 100644 --- a/src/status_im/utils/phone_number.cljs +++ b/src/status_im/utils/phone_number.cljs @@ -1,17 +1,17 @@ (ns status-im.utils.phone-number - (:require [status-im.i18n :refer [label]])) + (:require [status-im.i18n :refer [label]] + [status-im.react-native.js-dependencies :as rn-dependencies] + [status-im.js-dependencies :as dependencies])) -(def i18n (js/require "react-native-i18n")) -(def locale (or (.-locale i18n) "___en")) +(def locale (or (.-locale rn-dependencies/i18n) "___en")) (def country-code (subs locale 3 5)) -(def awesome-phonenumber (js/require "awesome-phonenumber")) ;; todo check wrong numbers, .getNumber returns empty string (defn format-phone-number [number] - (str (.getNumber (awesome-phonenumber. number country-code) "international"))) + (str (.getNumber (dependencies/awesome-phonenumber number country-code) "international"))) (defn get-examples [] - (when-let [example (.getExample awesome-phonenumber country-code "mobile")] + (when-let [example (.getExample dependencies/awesome-phonenumber country-code "mobile")] [{:number (.getNumber example) :description (label :t/phone-e164)} {:number (.getNumber example "international") @@ -23,7 +23,7 @@ (defn valid-mobile-number? [number] (when (string? number) - (let [{:keys [valid type]} (-> (awesome-phonenumber. number country-code) + (let [{:keys [valid type]} (-> (dependencies/awesome-phonenumber. number country-code) (.toJSON) (js->clj :keywordize-keys true))] (and valid diff --git a/src/status_im/utils/platform.cljs b/src/status_im/utils/platform.cljs index 7656d97825..d0c3adff13 100644 --- a/src/status_im/utils/platform.cljs +++ b/src/status_im/utils/platform.cljs @@ -1,11 +1,10 @@ (ns status-im.utils.platform (:require [status-im.android.platform :as android] - [status-im.ios.platform :as ios])) - -(def react-native (js/require "react-native")) + [status-im.ios.platform :as ios] + [status-im.react-native.js-dependencies :as rn-dependencies])) (def platform - (when-let [pl (.-Platform react-native)] + (when-let [pl (.-Platform rn-dependencies/react-native)] (.-OS pl))) (def android? (= platform "android")) diff --git a/src/status_im/utils/random.cljs b/src/status_im/utils/random.cljs index 7553790cc0..7bbc5f4bea 100644 --- a/src/status_im/utils/random.cljs +++ b/src/status_im/utils/random.cljs @@ -1,11 +1,10 @@ -(ns status-im.utils.random) +(ns status-im.utils.random + (:require [status-im.js-dependencies :as dependencies])) (defn timestamp [] (.getTime (js/Date.))) -(def Chance (js/require "chance")) - -(def chance (Chance.)) +(def chance (dependencies/Chance.)) (defn id [] (str (timestamp) "-" (.guid chance))) diff --git a/src/status_im/utils/sms_listener.cljs b/src/status_im/utils/sms_listener.cljs index c80b1914b8..faacf87764 100644 --- a/src/status_im/utils/sms_listener.cljs +++ b/src/status_im/utils/sms_listener.cljs @@ -1,16 +1,14 @@ (ns status-im.utils.sms-listener - (:require [status-im.utils.platform :refer [android?]])) - -(def sms-listener (.-default (js/require "react-native-android-sms-listener"))) + (:require [status-im.utils.platform :refer [android?]] + [status-im.react-native.js-dependencies :as rn-dependencies])) ;; Only android is supported! - (defn add-sms-listener "Message format: {:originatingAddress string, :body string}. Returns cancelable subscription." [listen-fn] (when android? - (.addListener sms-listener + (.addListener rn-dependencies/android-sms-listener (fn [message] (listen-fn (js->clj message :keywordize-keys true)))))) diff --git a/src/status_im/utils/utils.cljs b/src/status_im/utils/utils.cljs index 4d7c2b2ba2..744436d309 100644 --- a/src/status_im/utils/utils.cljs +++ b/src/status_im/utils/utils.cljs @@ -2,20 +2,12 @@ (:require [status-im.constants :as const] [status-im.i18n :refer [label]] [reagent.core :as r] - [clojure.string :as str])) - -(defn require [module] - (if (exists? js/window) - (js/require module) - #js {})) - -(defn log [obj] - (.log js/console obj)) - -(def react-native (js/require "react-native")) + [clojure.string :as str] + [taoensso.timbre :as log] + [status-im.react-native.js-dependencies :as rn-dependencies])) (defn show-popup [title content] - (.alert (.-Alert react-native) + (.alert (.-Alert rn-dependencies/react-native) title content)) @@ -25,7 +17,7 @@ ([title content s on-accept] (show-confirmation title content s on-accept nil)) ([title content s on-accept on-cancel] - (.alert (.-Alert react-native) + (.alert (.-Alert rn-dependencies/react-native) title content ; Styles are only relevant on iOS. On Android first button is 'neutral' and second is 'positive' @@ -45,7 +37,7 @@ :content-type "application/json"} :body (.stringify js/JSON (clj->js data))})) (.then (fn [response] - (log response) + (log/debug response) (.text response))) (.then (fn [text] (let [json (.parse js/JSON text) @@ -62,7 +54,7 @@ (-> (.fetch js/window url (clj->js {:method "GET" :headers {"Cache-Control" "no-cache"}})) (.then (fn [response] - (log response) + (log/debug response) (let [ok? (.-ok response) ok?' (if valid-response? (and ok? (valid-response? response)) @@ -101,15 +93,5 @@ index (recur (inc index) cond (next coll)))))) -(defn get-react-property [name] - (aget react-native name)) - -(defn adapt-class [class] - (when class - (r/adapt-react-class class))) - -(defn get-class [name] - (adapt-class (get-react-property name))) - (defn hash-tag? [s] (= \# (first s))) diff --git a/src/status_im/utils/web_provider.cljs b/src/status_im/utils/web3_provider.cljs similarity index 93% rename from src/status_im/utils/web_provider.cljs rename to src/status_im/utils/web3_provider.cljs index dd83bca474..83541d041e 100644 --- a/src/status_im/utils/web_provider.cljs +++ b/src/status_im/utils/web3_provider.cljs @@ -1,4 +1,4 @@ -(ns status-im.utils.web-provider +(ns status-im.utils.web3-provider (:require [taoensso.timbre :as log] [status-im.components.status :as status])) diff --git a/test/cljs/cljsjs/react.cljs b/test/cljs/cljsjs/react.cljs new file mode 100644 index 0000000000..69f52779e9 --- /dev/null +++ b/test/cljs/cljsjs/react.cljs @@ -0,0 +1,2 @@ +(ns cljsjs.react) + diff --git a/test/cljs/cljsjs/react/dom.cljs b/test/cljs/cljsjs/react/dom.cljs new file mode 100644 index 0000000000..3c69f0090f --- /dev/null +++ b/test/cljs/cljsjs/react/dom.cljs @@ -0,0 +1 @@ +(ns cljsjs.react.dom) \ No newline at end of file diff --git a/test/cljs/cljsjs/react/dom/server.cljs b/test/cljs/cljsjs/react/dom/server.cljs new file mode 100644 index 0000000000..c7ffcf638f --- /dev/null +++ b/test/cljs/cljsjs/react/dom/server.cljs @@ -0,0 +1 @@ +(ns cljsjs.react.dom.server) \ No newline at end of file diff --git a/test/cljs/reagent/core.cljs b/test/cljs/reagent/core.cljs new file mode 100644 index 0000000000..3d48e131ce --- /dev/null +++ b/test/cljs/reagent/core.cljs @@ -0,0 +1,14 @@ +(ns reagent.core) + +(defn create-element [& args]) + +(defn adapt-react-class [& args]) +(defn atom [& args]) +(defn as-element [& args]) +(defn create-class [& args]) +(defn set-state [& args]) +(defn state [& args]) +(defn after-render [& args]) +(defn props [& args]) +(defn current-component [& args]) +(defn reactify-component [& args]) diff --git a/test/cljs/status_im/react_native/js_dependencies.cljs b/test/cljs/status_im/react_native/js_dependencies.cljs new file mode 100644 index 0000000000..fa7040a695 --- /dev/null +++ b/test/cljs/status_im/react_native/js_dependencies.cljs @@ -0,0 +1,38 @@ +(ns status-im.react-native.js-dependencies) + +(def action-button #js {}) +(def android-sms-listener #js {}) +(def autolink #js {}) +(def camera #js {:constants #js {}}) +(def circle-checkbox #js {}) +(def contacts #js {}) +(def dialogs #js {}) +(def dismiss-keyboard #js {}) +(def drawer #js {}) +(def emoji-picker #js {}) +(def fs #js {}) +(def http-bridge #js {}) +(def i18n #js {}) +(def image-crop-picker #js {}) +(def image-resizer #js {}) +(def instabug #js {}) +(def invertible-scroll-view #js {}) +(def linear-gradient #js {}) +(def mapbox-gl #js {:setAccessToken (fn [])}) +(def nfc #js {}) +(def orientation #js {}) +(def popup-menu #js {}) +(def qr-code #js {}) +(def random-bytes #js {}) +(def react-native + #js {:NativeModules #js {} + :Animated #js {} + :DeviceEventEmitter #js {:addListener (fn [])}}) +(def realm #js {:schemaVersion (fn []) + :close (fn [])}) +(def sortable-listview #js {}) +(def swiper #js {}) +(def vector-icons #js {}) +(def webview-bridge #js {}) + + diff --git a/test/cljs/status_im/react_native/resources.cljs b/test/cljs/status_im/react_native/resources.cljs new file mode 100644 index 0000000000..66f7db072d --- /dev/null +++ b/test/cljs/status_im/react_native/resources.cljs @@ -0,0 +1,29 @@ +(ns status-im.react-native.resources) + +(def add-icon nil) +(def att nil) +(def chat-icon nil) +(def icon-close-gray nil) +(def logo-icon nil) +(def nav-back-icon nil) +(def user-no-photo nil) +(def online-icon nil) +(def play nil) +(def trash-icon nil) +(def v nil) + +(def contacts + {:auction-house nil + :mkr-market nil + :oaken-water-meter nil + :flight-delays-suck nil + :jarrad nil + :firstblood nil + :gnosis nil + :melonport nil + :bchat nil + :dentacoin nil + :augur nil + :ethlance nil + :commiteth nil + :etherplay nil}) diff --git a/test/cljs/status_im/test/commands/handlers.cljs b/test/cljs/status_im/test/commands/handlers.cljs deleted file mode 100644 index cf356be4e2..0000000000 --- a/test/cljs/status_im/test/commands/handlers.cljs +++ /dev/null @@ -1,20 +0,0 @@ -(ns status-im.test.commands.handlers - (:require [cljs.test :refer-macros [deftest is]] - [status-im.commands.handlers.loading :as h])) - -(deftest test-validate-hash - (let [file "some-js" - db (-> {} - (assoc-in [:chats :user :dapp-hash] -731917028) - (assoc-in [:chats :user2 :dapp-hash] 123))] - (is (::h/valid-hash (h/validate-hash db [:user file]))) - (is (not (::h/valid-hash (h/validate-hash db [:user2 file])))) - (is (not (::h/valid-hash (h/validate-hash db [:user3 file])))))) - -(deftest test-add-commands - (let [obj {:commands {:test {:name "name" - :description "desc"}} - :responses {:test-r {:name "r" - :description "desc-r"}}} - db (h/add-commands {} [:user nil obj])] - (is (= obj (select-keys (get-in db [:chats :user]) [:commands :responses]))))) diff --git a/test/cljs/status_im/test/runner.cljs b/test/cljs/status_im/test/runner.cljs index 9729c2be33..29353afa6d 100644 --- a/test/cljs/status_im/test/runner.cljs +++ b/test/cljs/status_im/test/runner.cljs @@ -1,8 +1,7 @@ (ns status-im.test.runner (:require [doo.runner :refer-macros [doo-tests]] [status-im.test.chat.models.input] - [status-im.test.handlers] - [status-im.test.commands.handlers])) + [status-im.test.handlers])) (enable-console-print!) @@ -13,5 +12,4 @@ (set! goog.DEBUG false) (doo-tests 'status-im.test.chat.models.input - 'status-im.test.handlers - 'status-im.test.commands.handlers) + 'status-im.test.handlers)