diff --git a/.env b/.env index 8eb195e1d5..f10c4f1143 100644 --- a/.env +++ b/.env @@ -1,4 +1,5 @@ TESTFAIRY_ENABLED=0 WALLET_WIP_ENABLED=1 NOTIFICATIONS_WIP_ENABLED=1 -DEBUG_LOGS_ENABLED=1 \ No newline at end of file +DEBUG_LOGS_ENABLED=1 +STUB_STATUS_GO=0 diff --git a/.env.jenkins b/.env.jenkins index cef8760256..c10fd298c7 100644 --- a/.env.jenkins +++ b/.env.jenkins @@ -2,3 +2,5 @@ TESTFAIRY_ENABLED=1 WALLET_WIP_ENABLED=1 NOTIFICATIONS_WIP_ENABLED=0 DEBUG_LOGS_ENABLED=1 +STUB_STATUS_GO=0 + diff --git a/env/dev/env/android/main.cljs b/env/dev/env/android/main.cljs index 312de37e64..6b07f8d437 100644 --- a/env/dev/env/android/main.cljs +++ b/env/dev/env/android/main.cljs @@ -11,7 +11,7 @@ (def root-el (r/as-element [reloader])) (defn callback [] (swap! cnt inc) - (status-im.components.status/init-jail) + (status-im.native-module.core/init-jail) (re-frame.core/dispatch [:load-commands!])) (figwheel/watch-and-reload @@ -19,4 +19,4 @@ :heads-up-display false :jsload-callback callback) -(rr/enable-re-frisk-remote! {:host "10.0.3.2:4567" :on-init core/init :pre-send (fn [db] (update db :chats #(into {} %)))}) \ No newline at end of file +(rr/enable-re-frisk-remote! {:host "localhost:4567" :on-init core/init :pre-send (fn [db] (update db :chats #(into {} %)))}) diff --git a/env/dev/env/ios/main.cljs b/env/dev/env/ios/main.cljs index 8196606cfc..26f3f4cd59 100644 --- a/env/dev/env/ios/main.cljs +++ b/env/dev/env/ios/main.cljs @@ -12,8 +12,8 @@ (def root-el (r/as-element [reloader])) (figwheel/watch-and-reload - :websocket-url "ws://localhost:3449/figwheel-ws" + :websocket-url "ws://10.0.1.15:3449/figwheel-ws" :heads-up-display false :jsload-callback #(swap! cnt inc)) -(rr/enable-re-frisk-remote! {:host "localhost:4567" :on-init core/init :pre-send (fn [db] (update db :chats #(into {} %)))}) \ No newline at end of file +(rr/enable-re-frisk-remote! {:host "10.0.1.15:4567" :on-init core/init :pre-send (fn [db] (update db :chats #(into {} %)))}) \ No newline at end of file diff --git a/ios/StatusIm.xcodeproj/project.pbxproj b/ios/StatusIm.xcodeproj/project.pbxproj index b2ab9d4c21..5a3b1474f8 100644 --- a/ios/StatusIm.xcodeproj/project.pbxproj +++ b/ios/StatusIm.xcodeproj/project.pbxproj @@ -1833,7 +1833,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "#!/bin/bash\n\n# This script automatically sets the version and short version string of\n# an Xcode project from the Git repository containing the project.\n#\n# To use this script in Xcode, add the script's path to a \"Run Script\" build\n# phase for your application target.\n\nset -o errexit\nset -o nounset\n\n# First, check for git in $PATH\nhash git 2>/dev/null || { echo >&2 \"Git required, not installed. Aborting build number update script.\"; exit 0; }\n\n# Alternatively, we could use Xcode's copy of the Git binary,\n# but old Xcodes don't have this.\n#GIT=$(xcrun -find git)\n\n# Run Script build phases that operate on product files of the target that defines them should use the value of this build setting [TARGET_BUILD_DIR]. But Run Script build phases that operate on product files of other targets should use “BUILT_PRODUCTS_DIR” instead.\nINFO_PLIST=\"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}\"\n\n# Build version (closest-tag-or-branch \"-\" commits-since-tag \"-\" short-hash dirty-flag)\nBUILD_VERSION=$(git describe --tags --always --dirty=+)\n\n# Use the latest tag for short version (expected tag format \"vn[.n[.n]]\")\n# or if there are no tags, we make up version 0.0.\nLATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null) || LATEST_TAG=\"HEAD\"\nif [ $LATEST_TAG = \"HEAD\" ]\nthen COMMIT_COUNT=$(git rev-list --count HEAD)\n LATEST_TAG=\"0.0.$COMMIT_COUNT\"\n COMMIT_COUNT_SINCE_TAG=0\nelse\n COMMIT_COUNT_SINCE_TAG=$(git rev-list --count ${LATEST_TAG}..)\n LATEST_TAG=${LATEST_TAG##v} # Remove the \"v\" from the front of the tag\nfi\nif [ $COMMIT_COUNT_SINCE_TAG = 0 ]; then\n SHORT_VERSION=\"$LATEST_TAG\"\nelse\n # increment final digit of tag and append \"d\" + commit-count-since-tag\n # e.g. commit after 1.0 is 1.1d1, commit after 1.0.0 is 1.0.1d1\n # this is the bit that requires /bin/bash\n OLD_IFS=$IFS\n IFS=\".\"\n VERSION_PARTS=($LATEST_TAG)\n LAST_PART=$((${#VERSION_PARTS[@]}-1))\n VERSION_PARTS[$LAST_PART]=$((${VERSION_PARTS[${LAST_PART}]}+1))\n SHORT_VERSION=\"${VERSION_PARTS[*]}d${COMMIT_COUNT_SINCE_TAG}\"\n IFS=$OLD_IFS\nfi\n \n# Bundle version (commits-on-master[-until-branch \".\" commits-on-branch])\n# Assumes that two release branches will not diverge from the same commit on master.\nif [ $(git rev-parse --abbrev-ref HEAD) = \"master\" ]; then\n MASTER_COMMIT_COUNT=$(git rev-list --count HEAD)\n BRANCH_COMMIT_COUNT=0\n BUNDLE_VERSION=\"$MASTER_COMMIT_COUNT\"\nelse\n MASTER_COMMIT_COUNT=$(git rev-list --count $(git rev-list master.. | tail -n 1)^)\n BRANCH_COMMIT_COUNT=$(git rev-list --count master..)\n if [ $BRANCH_COMMIT_COUNT = 0 ]\n then BUNDLE_VERSION=\"$MASTER_COMMIT_COUNT\"\n else BUNDLE_VERSION=\"${MASTER_COMMIT_COUNT}.${BRANCH_COMMIT_COUNT}\"\n fi\nfi\n \n# For debugging:\necho \"BUILD VERSION: $BUILD_VERSION\"\necho \"LATEST_TAG: $LATEST_TAG\"\necho \"COMMIT_COUNT_SINCE_TAG: $COMMIT_COUNT_SINCE_TAG\"\necho \"SHORT VERSION: $SHORT_VERSION\"\necho \"MASTER_COMMIT_COUNT: $MASTER_COMMIT_COUNT\"\necho \"BRANCH_COMMIT_COUNT: $BRANCH_COMMIT_COUNT\"\necho \"BUNDLE_VERSION: $BUNDLE_VERSION\"\n \n/usr/libexec/PlistBuddy -c \"Add :CFBundleBuildVersion string $BUILD_VERSION\" \"$INFO_PLIST\" 2>/dev/null || /usr/libexec/PlistBuddy -c \"Set :CFBundleBuildVersion $BUILD_VERSION\" \"$INFO_PLIST\"\n/usr/libexec/PlistBuddy -c \"Set :CFBundleShortVersionString $SHORT_VERSION\" \"$INFO_PLIST\"\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $BUNDLE_VERSION\" \"$INFO_PLIST\""; + shellScript = "#!/bin/bash\n\n# This script automatically sets the version and short version string of\n# an Xcode project from the Git repository containing the project.\n#\n# To use this script in Xcode, add the script's path to a \"Run Script\" build\n# phase for your application target.\n\nset -o errexit\nset -o nounset\n\n# First, check for git in $PATH\nhash git 2>/dev/null || { echo >&2 \"Git required, not installed. Aborting build number update script.\"; exit 0; }\n\n# Alternatively, we could use Xcode's copy of the Git binary,\n# but old Xcodes don't have this.\n#GIT=$(xcrun -find git)\n\n# Run Script build phases that operate on product files of the target that defines them should use the value of this build setting [TARGET_BUILD_DIR]. But Run Script build phases that operate on product files of other targets should use ?BUILT_PRODUCTS_DIR? instead.\nINFO_PLIST=\"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}\"\n\n# Build version (closest-tag-or-branch \"-\" commits-since-tag \"-\" short-hash dirty-flag)\nBUILD_VERSION=$(git describe --tags --always --dirty=+)\n\n# Use the latest tag for short version (expected tag format \"vn[.n[.n]]\")\n# or if there are no tags, we make up version 0.0.\nLATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null) || LATEST_TAG=\"HEAD\"\nif [ $LATEST_TAG = \"HEAD\" ]\nthen COMMIT_COUNT=$(git rev-list --count HEAD)\n LATEST_TAG=\"0.0.$COMMIT_COUNT\"\n COMMIT_COUNT_SINCE_TAG=0\nelse\n COMMIT_COUNT_SINCE_TAG=$(git rev-list --count ${LATEST_TAG}..)\n LATEST_TAG=${LATEST_TAG##v} # Remove the \"v\" from the front of the tag\nfi\nif [ $COMMIT_COUNT_SINCE_TAG = 0 ]; then\n SHORT_VERSION=\"$LATEST_TAG\"\nelse\n # increment final digit of tag and append \"d\" + commit-count-since-tag\n # e.g. commit after 1.0 is 1.1d1, commit after 1.0.0 is 1.0.1d1\n # this is the bit that requires /bin/bash\n OLD_IFS=$IFS\n IFS=\".\"\n VERSION_PARTS=($LATEST_TAG)\n LAST_PART=$((${#VERSION_PARTS[@]}-1))\n VERSION_PARTS[$LAST_PART]=$((${VERSION_PARTS[${LAST_PART}]}+1))\n SHORT_VERSION=\"${VERSION_PARTS[*]}d${COMMIT_COUNT_SINCE_TAG}\"\n IFS=$OLD_IFS\nfi\n \n# Bundle version (commits-on-master[-until-branch \".\" commits-on-branch])\n# Assumes that two release branches will not diverge from the same commit on master.\nif [ $(git rev-parse --abbrev-ref HEAD) = \"master\" ]; then\n MASTER_COMMIT_COUNT=$(git rev-list --count HEAD)\n BRANCH_COMMIT_COUNT=0\n BUNDLE_VERSION=\"$MASTER_COMMIT_COUNT\"\nelse\n MASTER_COMMIT_COUNT=$(git rev-list --count $(git rev-list master.. | tail -n 1)^)\n BRANCH_COMMIT_COUNT=$(git rev-list --count master..)\n if [ $BRANCH_COMMIT_COUNT = 0 ]\n then BUNDLE_VERSION=\"$MASTER_COMMIT_COUNT\"\n else BUNDLE_VERSION=\"${MASTER_COMMIT_COUNT}.${BRANCH_COMMIT_COUNT}\"\n fi\nfi\n \n# For debugging:\necho \"BUILD VERSION: $BUILD_VERSION\"\necho \"LATEST_TAG: $LATEST_TAG\"\necho \"COMMIT_COUNT_SINCE_TAG: $COMMIT_COUNT_SINCE_TAG\"\necho \"SHORT VERSION: $SHORT_VERSION\"\necho \"MASTER_COMMIT_COUNT: $MASTER_COMMIT_COUNT\"\necho \"BRANCH_COMMIT_COUNT: $BRANCH_COMMIT_COUNT\"\necho \"BUNDLE_VERSION: $BUNDLE_VERSION\"\n \n/usr/libexec/PlistBuddy -c \"Add :CFBundleBuildVersion string $BUILD_VERSION\" \"$INFO_PLIST\" 2>/dev/null || /usr/libexec/PlistBuddy -c \"Set :CFBundleBuildVersion $BUILD_VERSION\" \"$INFO_PLIST\"\n/usr/libexec/PlistBuddy -c \"Set :CFBundleShortVersionString $SHORT_VERSION\" \"$INFO_PLIST\"\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $BUNDLE_VERSION\" \"$INFO_PLIST\""; }; E883D1F9B22B8292CC879292 /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 6188b37979..be62d25545 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -8,7 +8,7 @@ status-im.data-store.core [status-im.ui.screens.views :as views] [status-im.components.react :as react] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.utils.error-handler :as error-handler] [status-im.utils.utils :as utils] [status-im.utils.config :as config] @@ -78,7 +78,7 @@ (defn init [] (error-handler/register-exception-handler!) - (status/call-module status/init-jail) + (status/init-jail) (.registerComponent react/app-registry "StatusIm" #(reagent/reactify-component app-root)) (status/set-soft-input-mode status/adjust-resize) (init-back-button-handler!) diff --git a/src/status_im/bots/handlers.cljs b/src/status_im/bots/handlers.cljs index cc47f1f0e5..22a08af658 100644 --- a/src/status_im/bots/handlers.cljs +++ b/src/status_im/bots/handlers.cljs @@ -1,6 +1,6 @@ (ns status-im.bots.handlers (:require [re-frame.core :as re-frame] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.utils.handlers :as u])) (defn chats-with-bot [chats bot] @@ -74,4 +74,4 @@ (u/register-handler :clear-bot-db (fn [{:keys [current-chat-id] :as app-db} [_ {:keys [bot]}]] (let [bot (or bot current-chat-id)] - (assoc-in app-db [:bot-db bot] nil)))) \ No newline at end of file + (assoc-in app-db [:bot-db bot] nil)))) diff --git a/src/status_im/chat/events/commands.cljs b/src/status_im/chat/events/commands.cljs index 7f68cf3550..f42a9b2112 100644 --- a/src/status_im/chat/events/commands.cljs +++ b/src/status_im/chat/events/commands.cljs @@ -5,7 +5,7 @@ [taoensso.timbre :as log] [status-im.data-store.messages :as msg-store] [status-im.utils.handlers :refer [register-handler-fx]] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.i18n :as i18n] [status-im.utils.platform :as platform])) diff --git a/src/status_im/chat/events/input.cljs b/src/status_im/chat/events/input.cljs index 9f0be6bc13..669a5223ac 100644 --- a/src/status_im/chat/events/input.cljs +++ b/src/status_im/chat/events/input.cljs @@ -7,7 +7,7 @@ [status-im.chat.models.input :as input-model] [status-im.chat.models.suggestions :as suggestions] [status-im.components.react :as react-comp] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.utils.datetime :as time] [status-im.utils.handlers :refer [register-handler-db register-handler-fx]] [status-im.utils.random :as random] diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index cc3d1555d5..20560fc465 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -24,7 +24,7 @@ [status-im.handlers.server :as server] [status-im.utils.phone-number :refer [format-phone-number valid-mobile-number?]] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.utils.types :refer [json->clj]] [status-im.chat.utils :refer [console? not-console? safe-trim]] [status-im.utils.gfycat.core :refer [generate-gfy]] @@ -628,4 +628,4 @@ :show-profile (fn [{db :db} [_ identity]] {:db (assoc db :contacts/identity identity) - :dispatch [:navigate-forget :profile]})) \ No newline at end of file + :dispatch [:navigate-forget :profile]})) diff --git a/src/status_im/chat/handlers/send_message.cljs b/src/status_im/chat/handlers/send_message.cljs index 605a61b9e9..9959acc81f 100644 --- a/src/status_im/chat/handlers/send_message.cljs +++ b/src/status_im/chat/handlers/send_message.cljs @@ -2,7 +2,7 @@ (:require [status-im.utils.handlers :refer [register-handler] :as u] [clojure.string :as s] [status-im.data-store.messages :as messages] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.utils.random :as random] [status-im.utils.datetime :as time] [re-frame.core :refer [enrich after dispatch path]] diff --git a/src/status_im/chat/handlers/webview_bridge.cljs b/src/status_im/chat/handlers/webview_bridge.cljs index 606f30b2d2..ddb7bc1d14 100644 --- a/src/status_im/chat/handlers/webview_bridge.cljs +++ b/src/status_im/chat/handlers/webview_bridge.cljs @@ -7,7 +7,7 @@ [taoensso.timbre :as log] [status-im.models.commands :as commands] [status-im.commands.utils :as cu] - [status-im.components.status :as s] + [status-im.native-module.core :as s] [status-im.components.nfc :as nfc] [status-im.constants :as c] [cljs.reader :refer [read-string]] diff --git a/src/status_im/chat/models/input.cljs b/src/status_im/chat/models/input.cljs index bb500df57c..b0d691b1a6 100644 --- a/src/status_im/chat/models/input.cljs +++ b/src/status_im/chat/models/input.cljs @@ -1,7 +1,7 @@ (ns status-im.chat.models.input (:require [clojure.string :as str] [status-im.components.react :as rc] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.chat.constants :as const] [status-im.chat.views.input.validation-messages :refer [validation-message]] [status-im.i18n :as i18n] diff --git a/src/status_im/chat/views/input/web_view.cljs b/src/status_im/chat/views/input/web_view.cljs index ff5fa29823..c7a75eec29 100644 --- a/src/status_im/chat/views/input/web_view.cljs +++ b/src/status_im/chat/views/input/web_view.cljs @@ -4,7 +4,7 @@ [re-frame.core :refer [dispatch]] [status-im.components.webview-bridge :refer [webview-bridge]] [status-im.components.react :refer [view text] :as components] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.i18n :refer [label]] [status-im.utils.js-resources :as js-res] [clojure.string :as str] diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index a76ee66b78..e196079b6f 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -5,7 +5,7 @@ [clojure.string :as s] [status-im.data-store.commands :as commands] [status-im.data-store.contacts :as contacts] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.utils.types :refer [json->clj]] [status-im.commands.utils :refer [reg-handler]] [status-im.constants :refer [console-chat-id wallet-chat-id]] diff --git a/src/status_im/debug/handlers.cljs b/src/status_im/debug/handlers.cljs index ec4558a431..cefe27516b 100644 --- a/src/status_im/debug/handlers.cljs +++ b/src/status_im/debug/handlers.cljs @@ -2,7 +2,7 @@ (:require [re-frame.core :refer [after dispatch]] [status-im.utils.handlers :refer [register-handler] :as u] [status-im.components.react :refer [http-bridge]] - [status-im.components.status :refer [cljs->json]] + [status-im.utils.types :refer [clj->json]] [status-im.data-store.messages :as messages] [status-im.data-store.accounts :as accounts] [taoensso.timbre :as log] @@ -14,7 +14,7 @@ (.respond http-bridge 200 "application/json" - (cljs->json data))) + (clj->json data))) (register-handler :init-debug-mode (u/side-effect! diff --git a/src/status_im/ios/core.cljs b/src/status_im/ios/core.cljs index 803ae6b0ec..c2fee30082 100644 --- a/src/status_im/ios/core.cljs +++ b/src/status_im/ios/core.cljs @@ -8,7 +8,7 @@ status-im.data-store.core [status-im.ui.screens.views :as views] [status-im.components.react :as react] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.utils.error-handler :as error-handler] [status-im.utils.utils :as utils] [status-im.utils.config :as config] @@ -53,6 +53,6 @@ (defn init [] (error-handler/register-exception-handler!) - (status/call-module status/init-jail) + (status/init-jail) (.registerComponent react/app-registry "StatusIm" #(reagent/reactify-component app-root)) (dispatch-sync [:initialize-app])) diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs new file mode 100644 index 0000000000..1432fa83f6 --- /dev/null +++ b/src/status_im/native_module/core.cljs @@ -0,0 +1,93 @@ +(ns status-im.native-module.core + (:require [status-im.native-module.module :as module-interface] + [status-im.native-module.impl.module :as native-module] + [status-im.native-module.impl.non-status-go-module :as non-status-go-module] + [taoensso.timbre :as log] + [status-im.utils.config :as config])) + +(def rns-module + (if config/stub-status-go? + (non-status-go-module/ReactNativeStatus.) + (native-module/ReactNativeStatus.))) + + +(def adjust-resize 16) +(def adjust-pan 32) + +#_(defn- wrap-and-print-callback [name callback] + (fn [& args] + (println :callback name (str args)) + (log/debug :callback name args) + (apply callback args))) + +(defn init-jail [] + (module-interface/-init-jail rns-module)) + + +(defn move-to-internal-storage [callback] + (module-interface/-move-to-internal-storage rns-module callback)) + + +(defn start-node [callback] + (module-interface/-start-node rns-module callback)) + + +(defn stop-rpc-server [] + (module-interface/-stop-rpc-server rns-module)) + + +(defn start-rpc-server [] + (module-interface/-start-rpc-server rns-module)) + + +(defn restart-rpc [] + (module-interface/-restart-rpc rns-module)) + + +(defn create-account [password callback] + (module-interface/-create-account rns-module password callback)) + + +(defn recover-account [passphrase password callback] + (module-interface/-recover-account rns-module passphrase password callback)) + + +(defn login [address password callback] + (module-interface/-login rns-module address password callback)) + + +(defn complete-transactions [hashes password callback] + (module-interface/-complete-transactions rns-module hashes password callback)) + + +(defn discard-transaction [id] + (module-interface/-discard-transaction rns-module id)) + + +(defn parse-jail [chat-id file callback] + (module-interface/-parse-jail rns-module chat-id file callback)) + + +(defn call-jail [params] + (module-interface/-call-jail rns-module params)) + + +(defn call-function! [params] + (module-interface/-call-function! rns-module params)) + + +(defn set-soft-input-mode [mode] + (module-interface/-set-soft-input-mode rns-module mode)) + + +(defn clear-web-data [] + (module-interface/-clear-web-data rns-module)) + +(defn call-web3 [host payload callback] + (module-interface/-call-web3 rns-module host payload callback)) + +(defn module-initialized! [] + (module-interface/-module-initialized! rns-module)) + +(defn should-move-to-internal-storage? [callback] + (module-interface/-should-move-to-internal-storage? rns-module callback)) diff --git a/src/status_im/components/status.cljs b/src/status_im/native_module/impl/module.cljs similarity index 73% rename from src/status_im/components/status.cljs rename to src/status_im/native_module/impl/module.cljs index 20e0e9ae4c..1f847437c7 100644 --- a/src/status_im/components/status.cljs +++ b/src/status_im/native_module/impl/module.cljs @@ -1,4 +1,4 @@ -(ns status-im.components.status +(ns status-im.native-module.impl.module (:require-macros [cljs.core.async.macros :refer [go-loop go]]) (:require [status-im.components.react :as r] @@ -9,10 +9,9 @@ [status-im.utils.js-resources :as js-res] [status-im.utils.platform :as p] [status-im.utils.scheduler :as scheduler] - [status-im.react-native.js-dependencies :as rn-dependencies])) - -(defn cljs->json [data] - (.stringify js/JSON (clj->js data))) + [status-im.utils.types :as types] + [status-im.react-native.js-dependencies :as rn-dependencies] + [status-im.native-module.module :as module])) ;; if StatusModule is not initialized better to store ;; calls and make them only when StatusModule is ready @@ -52,8 +51,11 @@ (.-Status (.-NativeModules rn-dependencies/react-native)))) (defn init-jail [] - (let [init-js (str js-res/status-js "I18n.locale = '" rn-dependencies/i18n.locale "';")] - (.initJail status init-js #(log/debug "jail initialized")))) + (when status + (call-module + (fn [] + (let [init-js (str js-res/status-js "I18n.locale = '" rn-dependencies/i18n.locale "';")] + (.initJail status init-js #(log/debug "jail initialized"))))))) (defonce listener-initialized (atom false)) @@ -124,7 +126,7 @@ [hashes password callback] (log/debug :complete-transactions (boolean status) hashes) (when status - (call-module #(.completeTransactions status (cljs->json hashes) password callback)))) + (call-module #(.completeTransactions status (types/clj->json hashes) password callback)))) (defn discard-transaction [id] @@ -154,7 +156,7 @@ (doseq [{:keys [type message]} messages] (log/debug (str "VM console(" type ") - " message))) (callback r')))] - (.callJail status jail-id (cljs->json path) (cljs->json params') cb)))))) + (.callJail status jail-id (types/clj->json path) (types/clj->json params') cb)))))) (defn call-function! [{:keys [chat-id function callback] :as opts}] @@ -175,9 +177,50 @@ (call-module #(.clearCookies status)) (call-module #(.clearStorageAPIs status)))) -(def adjust-resize 16) -(def adjust-pan 32) - (defn call-web3 [host payload callback] (when status (call-module #(.sendWeb3Request status host payload callback)))) + +(defrecord ReactNativeStatus [] + module/IReactNativeStatus + ;; status-go calls + (-init-jail [this] + (init-jail)) + (-start-node [this callback] + (start-node callback)) + (-stop-rpc-server [this] + (stop-rpc-server)) + (-start-rpc-server [this] + (start-rpc-server)) + (-restart-rpc [this] + (restart-rpc)) + (-create-account [this password callback] + (create-account password callback)) + (-recover-account [this passphrase password callback] + (recover-account passphrase password callback)) + (-login [this address password callback] + (login address password callback)) + (-complete-transactions [this hashes password callback] + (complete-transactions hashes password callback)) + (-discard-transaction [this id] + (discard-transaction id)) + (-parse-jail [this chat-id file callback] + (parse-jail chat-id file callback)) + (-call-jail [this params] + (call-jail params)) + (-call-function! [this params] + (call-function! params)) + (-call-web3 [this host payload callback] + (call-web3 host payload callback)) + + ;; other calls + (-move-to-internal-storage [this callback] + (move-to-internal-storage callback)) + (-set-soft-input-mode [this mode] + (set-soft-input-mode mode)) + (-clear-web-data [this] + (clear-web-data)) + (-module-initialized! [this] + (module-initialized!)) + (-should-move-to-internal-storage? [this callback] + (should-move-to-internal-storage? callback))) diff --git a/src/status_im/native_module/impl/non_status_go_module.cljs b/src/status_im/native_module/impl/non_status_go_module.cljs new file mode 100644 index 0000000000..4ad90cb691 --- /dev/null +++ b/src/status_im/native_module/impl/non_status_go_module.cljs @@ -0,0 +1,62 @@ +(ns status-im.native-module.impl.non-status-go-module + (:require [status-im.native-module.module :as module] + [status-im.native-module.impl.module :as impl] + [status-im.constants :as constants] + [re-frame.core :as re-frame] + [goog.string :as gstring] + [goog.string.format])) + +(def wrong-password "111") + +(defrecord ReactNativeStatus [] + module/IReactNativeStatus + ;; status-go calls + (-init-jail [this]) + (-start-node [this callback] + (re-frame/dispatch [:signal-event "{\"type\":\"node.started\",\"event\":{}}"]) + (re-frame/dispatch [:signal-event "{\"type\":\"node.ready\",\"event\":{}}"])) + (-stop-rpc-server [this]) + (-start-rpc-server [this]) + (-restart-rpc [this]) + (-create-account [this password callback] + (let [address (str "c9f5c0e2bea0aabb6b0b618e9f45ab0958" (gstring/format "%06d" (rand-int 100000)))] + (callback (str "{\"address\":\"" address "\",\"pubkey\":\"0x046a313ba760e8853356b42a8732db1e2c339602977a3ac3d57ec2056449439b2c9f28e2e0dd243ac319f5da198b4a96f980d0ab6d4c7220ca7c5e1af2bd1ee8c7\",\"mnemonic\":\"robust rib ramp adult cannon amateur refuse burden review feel scout sell\",\"error\":\"\"}")))) + (-recover-account [this passphrase password callback]) + (-login [this address password callback] + (if (not= password wrong-password) + (callback "{\"error\":\"\"}") + (callback "{\"error\":\"cannot retrieve a valid key for a given account: could not decrypt key with given passphrase\"}"))) + (-complete-transactions [this hashes password callback]) + (-discard-transaction [this id]) + (-parse-jail [this chat-id file callback] + (when (= chat-id constants/console-chat-id) + (callback "{\"result\": {\"commands\":{\"debug\":{\"color\":\"#7099e6\",\"description\":\"Starts/stops a debug mode\",\"has-handler\":false,\"name\":\"debug\",\"params\":[{\"name\":\"mode\",\"type\":\"text\"}],\"registered-only\":true,\"title\":\"Debug mode\"},\"faucet\":{\"color\":\"#7099e6\",\"description\":\"Get some ETH\",\"has-handler\":false,\"name\":\"faucet\",\"params\":[{\"name\":\"url\",\"placeholder\":\"Faucet URL\",\"type\":\"text\"}],\"registered-only\":true,\"title\":\"Faucet\"},\"phone\":{\"color\":\"#5bb2a2\",\"description\":\"Find friends using your number\",\"has-handler\":false,\"icon\":\"phone_white\",\"name\":\"phone\",\"params\":[{\"name\":\"phone\",\"placeholder\":\"Phone number\",\"type\":\"phone\"}],\"registered-only\":true,\"sequential-params\":true,\"title\":\"Send Phone Number\"}},\"functions\":{},\"responses\":{\"confirmation-code\":{\"color\":\"#7099e6\",\"description\":\"Confirmation code\",\"has-handler\":false,\"name\":\"confirmation-code\",\"params\":[{\"name\":\"code\",\"type\":\"number\"}],\"sequential-params\":true},\"grant-permissions\":{\"color\":\"#7099e6\",\"description\":\"Grant permissions\",\"execute-immediately?\":true,\"has-handler\":false,\"icon\":\"lock_white\",\"name\":\"grant-permissions\",\"params\":[]},\"password\":{\"color\":\"#7099e6\",\"description\":\"Password\",\"has-handler\":false,\"icon\":\"lock_white\",\"name\":\"password\",\"params\":[{\"hidden\":true,\"name\":\"password\",\"placeholder\":\"Type your password\",\"type\":\"password\"},{\"hidden\":true,\"name\":\"password-confirmation\",\"placeholder\":\"Confirm\",\"type\":\"password\"}],\"sequential-params\":true},\"phone\":{\"color\":\"#5bb2a2\",\"description\":\"Find friends using your number\",\"has-handler\":false,\"icon\":\"phone_white\",\"name\":\"phone\",\"params\":[{\"name\":\"phone\",\"placeholder\":\"Phone number\",\"type\":\"phone\"}],\"registered-only\":true,\"sequential-params\":true,\"title\":\"Send Phone Number\"}},\"subscriptions\":{}}}"))) + (-call-jail [this {:keys [callback path] :as params}] + (cond + (= path [:responses "password" :preview]) + (callback {:result {:context {}, + :messages [], + :returned {:markup ["text" + {:style + {:color "black", + :fontSize 8, + :letterSpacing 1, + :marginBottom 2, + :marginHorizontal 0, + :marginTop 10}} + "●●●●●●●●●●"]}}}) + :else (callback {:result nil}))) + (-call-function! [this params]) + (-call-web3 [this host payload callback]) + + ;; other calls + (-move-to-internal-storage [this callback] + (impl/move-to-internal-storage callback)) + (-set-soft-input-mode [this mode] + (impl/set-soft-input-mode mode)) + (-clear-web-data [this] + (impl/clear-web-data)) + (-module-initialized! [this] + (impl/module-initialized!)) + (-should-move-to-internal-storage? [this callback] + (impl/should-move-to-internal-storage? callback))) diff --git a/src/status_im/native_module/module.cljs b/src/status_im/native_module/module.cljs new file mode 100644 index 0000000000..b1a4943fad --- /dev/null +++ b/src/status_im/native_module/module.cljs @@ -0,0 +1,23 @@ +(ns status-im.native-module.module) + +(defprotocol IReactNativeStatus + (-init-jail [this]) + (-move-to-internal-storage [this callback]) + (-start-node [this callback]) + (-stop-rpc-server [this]) + (-start-rpc-server [this]) + (-restart-rpc [this]) + (-create-account [this password callback]) + (-recover-account [this passphrase password callback]) + (-login [this address password callback]) + (-complete-transactions [this hashes password callback]) + (-discard-transaction [this id]) + (-parse-jail [this chat-id file callback]) + (-call-jail [this params]) + (-call-function! [this params]) + (-set-soft-input-mode [this mode]) + (-clear-web-data [this]) + (-call-web3 [this host payload callback]) + (-module-initialized! [this]) + (-should-move-to-internal-storage? [this callback])) + diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index 0a7ed1e27e..d4a005e228 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -16,7 +16,7 @@ [status-im.utils.datetime :as dt] [taoensso.timbre :as log :refer-macros [debug]] [status-im.constants :as c] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [clojure.string :refer [join]] [status-im.utils.scheduler :as s] [status-im.utils.web3-provider :as w3] @@ -402,4 +402,4 @@ (let [now (time/now-ms) messages (processed-messages/get-filtered (str "ttl > " now))] (cache/init! messages) - (processed-messages/delete (str "ttl <=" now)))))) \ No newline at end of file + (processed-messages/delete (str "ttl <=" now)))))) diff --git a/src/status_im/transactions/handlers.cljs b/src/status_im/transactions/handlers.cljs index 462eb4cda4..d4a7764866 100644 --- a/src/status_im/transactions/handlers.cljs +++ b/src/status_im/transactions/handlers.cljs @@ -6,7 +6,7 @@ [status-im.utils.handlers :as u] [status-im.utils.types :as t] [status-im.utils.hex :refer [valid-hex? normalize-hex]] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [clojure.string :as s] [taoensso.timbre :as log])) diff --git a/src/status_im/ui/screens/accounts/events.cljs b/src/status_im/ui/screens/accounts/events.cljs index a25f1289f9..e2e6b5122b 100644 --- a/src/status_im/ui/screens/accounts/events.cljs +++ b/src/status_im/ui/screens/accounts/events.cljs @@ -7,7 +7,7 @@ [re-frame.core :refer [reg-cofx reg-fx dispatch inject-cofx]] [taoensso.timbre :as log] [status-im.protocol.core :as protocol] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.utils.types :refer [json->clj]] [status-im.utils.identicon :refer [identicon]] [status-im.utils.random :as random] @@ -56,8 +56,7 @@ (log/debug "account-created") (when-not (str/blank? public-key) (dispatch [:show-mnemonic mnemonic phrase]) - (dispatch [:add-account account]) - (dispatch [:login-account address password true])))) + (dispatch [:add-account account password])))) (reg-fx ::create-account @@ -97,10 +96,11 @@ (register-handler-fx :add-account - (fn [{{:keys [network] :as db} :db} [_ {:keys [address] :as account}]] + (fn [{{:keys [network] :as db} :db} [_ {:keys [address] :as account} password]] (let [account' (assoc account :network network)] - {:db (assoc-in db [:accounts/accounts address] account') - ::save-account account'}))) + {:db (assoc-in db [:accounts/accounts address] account') + ::save-account account' + :dispatch-later [{:ms 400 :dispatch [:login-account address password true]}]}))) (register-handler-fx :create-account diff --git a/src/status_im/ui/screens/accounts/login/events.cljs b/src/status_im/ui/screens/accounts/login/events.cljs index 9d5ed4e871..6387c1b2c9 100644 --- a/src/status_im/ui/screens/accounts/login/events.cljs +++ b/src/status_im/ui/screens/accounts/login/events.cljs @@ -7,7 +7,7 @@ [taoensso.timbre :as log] [status-im.utils.types :refer [json->clj]] [status-im.data-store.core :as data-store] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.constants :refer [console-chat-id]])) ;;;; FX diff --git a/src/status_im/ui/screens/accounts/recover/events.cljs b/src/status_im/ui/screens/accounts/recover/events.cljs index 77074412d5..a4ed7e0675 100644 --- a/src/status_im/ui/screens/accounts/recover/events.cljs +++ b/src/status_im/ui/screens/accounts/recover/events.cljs @@ -3,7 +3,7 @@ status-im.ui.screens.accounts.recover.navigation [re-frame.core :refer [reg-fx inject-cofx dispatch]] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.utils.types :refer [json->clj]] [status-im.utils.identicon :refer [identicon]] [taoensso.timbre :as log] diff --git a/src/status_im/ui/screens/events.cljs b/src/status_im/ui/screens/events.cljs index d4399dff56..79b140be8f 100644 --- a/src/status_im/ui/screens/events.cljs +++ b/src/status_im/ui/screens/events.cljs @@ -17,7 +17,7 @@ status-im.ui.screens.qr-scanner.events status-im.ui.screens.wallet.events [re-frame.core :refer [dispatch reg-fx]] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.components.permissions :as permissions] [status-im.constants :refer [console-chat-id]] [status-im.data-store.core :as data-store] diff --git a/src/status_im/ui/screens/wallet/events.cljs b/src/status_im/ui/screens/wallet/events.cljs index 8d62100b02..cadef25b11 100644 --- a/src/status_im/ui/screens/wallet/events.cljs +++ b/src/status_im/ui/screens/wallet/events.cljs @@ -5,7 +5,8 @@ [status-im.utils.transactions :as transactions] [status-im.utils.utils :as utils] [status-im.ui.screens.wallet.db :as wallet.db] - [status-im.components.status :as status] + + [status-im.native-module.core :as status] [status-im.ui.screens.wallet.navigation] [taoensso.timbre :as log])) diff --git a/src/status_im/utils/config.cljs b/src/status_im/utils/config.cljs index 7f68a8611b..3c4a0b5804 100644 --- a/src/status_im/utils/config.cljs +++ b/src/status_im/utils/config.cljs @@ -12,3 +12,5 @@ (def testfairy-enabled? (enabled? (get-config :TESTFAIRY_ENABLED))) (def wallet-wip-enabled? (enabled? (get-config :WALLET_WIP_ENABLED 0))) (def notifications-wip-enabled? (enabled? (get-config :NOTIFICATIONS_WIP_ENABLED 0))) +(def stub-status-go? (enabled? (get-config :STUB_STATUS_GO 0))) + diff --git a/src/status_im/utils/web3_provider.cljs b/src/status_im/utils/web3_provider.cljs index c4e43c0611..73b78cc2cf 100644 --- a/src/status_im/utils/web3_provider.cljs +++ b/src/status_im/utils/web3_provider.cljs @@ -1,6 +1,6 @@ (ns status-im.utils.web3-provider (:require [taoensso.timbre :as log] - [status-im.components.status :as status] + [status-im.native-module.core :as status] [status-im.js-dependencies :as dependencies])) (defn get-provider [rpc-url]