From bf27c553980e77dafb10786e00e9493a7d264fae Mon Sep 17 00:00:00 2001 From: alwx Date: Thu, 2 Feb 2017 09:07:44 +0300 Subject: [PATCH] Development tools (#719) --- .gitignore | 3 +- .re-natal | 3 +- android/app/build.gradle | 1 + .../im/status/ethereum/MainApplication.java | 2 + android/settings.gradle | 2 + env/dev/env/android/main.cljs | 2 +- ios/StatusIm.xcodeproj/project.pbxproj | 30 +++++++ package.json | 2 + postinstall.sh | 9 +- resources/console.js | 45 ++++++++++ src/status_im/accounts/login/handlers.cljs | 1 + src/status_im/android/core.cljs | 6 +- src/status_im/chat/handlers.cljs | 9 +- src/status_im/chat/handlers/console.cljs | 12 ++- src/status_im/components/react.cljs | 7 +- src/status_im/contacts/handlers.cljs | 14 +++- src/status_im/data_store/chats.cljs | 4 + src/status_im/data_store/realm/chats.cljs | 8 +- .../realm/schemas/account/core.cljs | 8 +- .../realm/schemas/account/v3/chat.cljs | 40 +++++++++ .../realm/schemas/account/v3/contact.cljs | 28 +++++++ .../realm/schemas/account/v3/core.cljs | 32 ++++++++ .../data_store/realm/schemas/base/core.cljs | 8 +- .../realm/schemas/base/v2/account.cljs | 25 ++++++ .../realm/schemas/base/v2/core.cljs | 13 +++ src/status_im/debug/handlers.cljs | 82 +++++++++++++++++++ src/status_im/handlers.cljs | 2 + src/status_im/ios/core.cljs | 6 +- src/status_im/protocol/handlers.cljs | 50 +++++------ src/status_im/protocol/listeners.cljs | 1 + 30 files changed, 411 insertions(+), 44 deletions(-) create mode 100644 src/status_im/data_store/realm/schemas/account/v3/chat.cljs create mode 100644 src/status_im/data_store/realm/schemas/account/v3/contact.cljs create mode 100644 src/status_im/data_store/realm/schemas/account/v3/core.cljs create mode 100644 src/status_im/data_store/realm/schemas/base/v2/account.cljs create mode 100644 src/status_im/data_store/realm/schemas/base/v2/core.cljs create mode 100644 src/status_im/debug/handlers.cljs diff --git a/.gitignore b/.gitignore index ebd1ed73ad..cc3ade1664 100644 --- a/.gitignore +++ b/.gitignore @@ -72,8 +72,9 @@ doo-index.html # Re-natal re-natal -# status-go +# Status Statusgo.framework +status-dev-cli #ios ios/Pods diff --git a/.re-natal b/.re-natal index e50e024d1d..7809b729df 100644 --- a/.re-natal +++ b/.re-natal @@ -38,7 +38,8 @@ "react-native-emoji-picker", "react-native-autolink", "instabug-reactnative", - "nfc-react-native" + "nfc-react-native", + "react-native-http-bridge" ], "imageDirs": [ "images" diff --git a/android/app/build.gradle b/android/app/build.gradle index aef5094b10..344fab16a1 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -158,6 +158,7 @@ android { } dependencies { + compile project(':react-native-http-bridge') compile project(':nfc-react-native') compile project(':instabug-reactnative') compile project(':react-native-splash-screen') diff --git a/android/app/src/main/java/im/status/ethereum/MainApplication.java b/android/app/src/main/java/im/status/ethereum/MainApplication.java index d9dd651f94..b9003aba5b 100644 --- a/android/app/src/main/java/im/status/ethereum/MainApplication.java +++ b/android/app/src/main/java/im/status/ethereum/MainApplication.java @@ -3,6 +3,7 @@ package im.status.ethereum; import android.app.Application; import com.facebook.react.ReactApplication; +import me.alwx.HttpServer.HttpServerReactPackage; import es.tiarg.nfcreactnative.NfcReactNativePackage; import com.instabug.reactlibrary.RNInstabugReactnativePackage; import com.cboy.rn.splashscreen.SplashScreenReactPackage; @@ -42,6 +43,7 @@ public class MainApplication extends Application implements ReactApplication { protected List getPackages() { return Arrays.asList( new MainReactPackage(), + new HttpServerReactPackage(), new NfcReactNativePackage(), new RNInstabugReactnativePackage("b239f82a9cb00464e4c72cc703e6821e",MainApplication.this,"shake"), new SplashScreenReactPackage(), diff --git a/android/settings.gradle b/android/settings.gradle index 9ccb85d226..a8b7bf715c 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,6 +1,8 @@ rootProject.name = 'StatusIm' include ':app' +include ':react-native-http-bridge' +project(':react-native-http-bridge').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-http-bridge/android') include ':nfc-react-native' project(':nfc-react-native').projectDir = new File(rootProject.projectDir, '../node_modules/nfc-react-native/android') include ':instabug-reactnative' diff --git a/env/dev/env/android/main.cljs b/env/dev/env/android/main.cljs index 6813b594fe..a26f34785c 100644 --- a/env/dev/env/android/main.cljs +++ b/env/dev/env/android/main.cljs @@ -14,7 +14,7 @@ (re-frame.core/dispatch [:load-commands!])) (figwheel/watch-and-reload - :websocket-url "ws://localhost:3449/figwheel-ws" + :websocket-url "ws://10.0.3.2:3449/figwheel-ws" :heads-up-display false :jsload-callback callback) diff --git a/ios/StatusIm.xcodeproj/project.pbxproj b/ios/StatusIm.xcodeproj/project.pbxproj index 06442fed52..b698625471 100644 --- a/ios/StatusIm.xcodeproj/project.pbxproj +++ b/ios/StatusIm.xcodeproj/project.pbxproj @@ -59,6 +59,7 @@ B24FC7FD1DE7195700D694FF /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B24FC7FC1DE7195700D694FF /* Social.framework */; }; B24FC7FF1DE7195F00D694FF /* MessageUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B24FC7FE1DE7195F00D694FF /* MessageUI.framework */; }; B2A5F45C1DEC36BB00174F4D /* libRCTAnimation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B2A5F4381DEC36B200174F4D /* libRCTAnimation.a */; }; + B2DEA0D01E49E33300FA28D6 /* libRCTHttpServer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B2DEA0B11E49E32000FA28D6 /* libRCTHttpServer.a */; }; B2F2D1BC1D9D531B00B7B453 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B2F2D1BB1D9D531B00B7B453 /* Images.xcassets */; }; BA68A2377A20496EA737000D /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E586E1B0E544F64AA9F5BD1 /* libz.tbd */; }; C3EE9AEA6F77464588FBAA64 /* FontAwesome.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 7B5870D9ED504F32B6A09C35 /* FontAwesome.ttf */; }; @@ -343,6 +344,13 @@ remoteGlobalIDString = 2D2A28201D9B03D100D4039D; remoteInfo = "RCTAnimation-tvOS"; }; + B2DEA0B01E49E32000FA28D6 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = B2DEA0A41E49E32000FA28D6 /* RCTHttpServer.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = B29EC9CC1E48BED600704A36; + remoteInfo = RCTHttpServer; + }; CE4E319D1D8693090033ED64 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 5E5A7625B76441D984EA8C0D /* RCTImageResizer.xcodeproj */; @@ -439,6 +447,7 @@ B24FC7FC1DE7195700D694FF /* Social.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Social.framework; path = System/Library/Frameworks/Social.framework; sourceTree = SDKROOT; }; B24FC7FE1DE7195F00D694FF /* MessageUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MessageUI.framework; path = System/Library/Frameworks/MessageUI.framework; sourceTree = SDKROOT; }; B2A5F42F1DEC36B200174F4D /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = ""; }; + B2DEA0A41E49E32000FA28D6 /* RCTHttpServer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTHttpServer.xcodeproj; path = "../node_modules/react-native-http-bridge/ios/RCTHttpServer.xcodeproj"; sourceTree = ""; }; B2F2D1BB1D9D531B00B7B453 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = StatusIm/Images.xcassets; sourceTree = ""; }; B3B19223008342D096AA356E /* Octicons.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = Octicons.ttf; path = "../node_modules/react-native-vector-icons/Fonts/Octicons.ttf"; sourceTree = ""; }; C2A4E93F6B154AEFA3485B45 /* libTcpSockets.a */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = archive.ar; path = libTcpSockets.a; sourceTree = ""; }; @@ -465,6 +474,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + B2DEA0D01E49E33300FA28D6 /* libRCTHttpServer.a in Frameworks */, 9EE89E271E03FCB7007D3C25 /* libSplashScreen.a in Frameworks */, B2A5F45C1DEC36BB00174F4D /* libRCTAnimation.a in Frameworks */, B24FC7FF1DE7195F00D694FF /* MessageUI.framework in Frameworks */, @@ -766,6 +776,7 @@ 832341AE1AAA6A7D00B99B32 /* Libraries */ = { isa = PBXGroup; children = ( + B2DEA0A41E49E32000FA28D6 /* RCTHttpServer.xcodeproj */, 9EC0135C1E06FB1900155B5C /* RCTWKWebView.xcodeproj */, B2A5F42F1DEC36B200174F4D /* RCTAnimation.xcodeproj */, B24FC7F51DE7190C00D694FF /* RNShare.xcodeproj */, @@ -900,6 +911,14 @@ name = Products; sourceTree = ""; }; + B2DEA0A51E49E32000FA28D6 /* Products */ = { + isa = PBXGroup; + children = ( + B2DEA0B11E49E32000FA28D6 /* libRCTHttpServer.a */, + ); + name = Products; + sourceTree = ""; + }; CE4E31941D8693090033ED64 /* Products */ = { isa = PBXGroup; children = ( @@ -1015,6 +1034,10 @@ ProductGroup = 00C302B61ABCB90400DB3ED1 /* Products */; ProjectRef = 00C302B51ABCB90400DB3ED1 /* RCTGeolocation.xcodeproj */; }, + { + ProductGroup = B2DEA0A51E49E32000FA28D6 /* Products */; + ProjectRef = B2DEA0A41E49E32000FA28D6 /* RCTHttpServer.xcodeproj */; + }, { ProductGroup = 00C302BC1ABCB91800DB3ED1 /* Products */; ProjectRef = 00C302BB1ABCB91800DB3ED1 /* RCTImage.xcodeproj */; @@ -1383,6 +1406,13 @@ remoteRef = B2A5F4391DEC36B200174F4D /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + B2DEA0B11E49E32000FA28D6 /* libRCTHttpServer.a */ = { + isa = PBXReferenceProxy; + fileType = archive.ar; + path = libRCTHttpServer.a; + remoteRef = B2DEA0B01E49E32000FA28D6 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; CE4E319E1D8693090033ED64 /* libRCTImageResizer.a */ = { isa = PBXReferenceProxy; fileType = archive.ar; diff --git a/package.json b/package.json index 92b1facc40..d5e37c330a 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "react-native-emoji-picker": "git+https://github.com/alwx/react-native-emoji-picker.git", "react-native-fs": "^1.5.1", "react-native-http": "github:tradle/react-native-http#834492d", + "react-native-http-bridge": "^0.2.2", "react-native-i18n": "0.0.8", "react-native-image-crop-picker": "^0.9.4", "react-native-image-resizer": "github:danieldunderfelt/react-native-image-resizer", @@ -74,6 +75,7 @@ "react-native-webview-bridge": "github:status-im/react-native-webview-bridge#0.33.5", "readable-stream": "^1.0.33", "realm": "^0.14.3", + "status-dev-cli": "^1.1.3", "stream-browserify": "^1.0.0", "timers-browserify": "^1.4.2", "tty-browserify": "0.0.0", diff --git a/postinstall.sh b/postinstall.sh index 5e2ff36422..1781a8040c 100755 --- a/postinstall.sh +++ b/postinstall.sh @@ -10,5 +10,12 @@ npm install --save react-native-tcp@2.0.4; if ! [ -f re-natal ]; then ln -s ./node_modules/re-natal/index.js re-natal; else - echo "exists" + echo "re-natal exists" fi + +# symlink for status-dev-cli +if ! [ -f status-dev-cli ]; then + ln -s ./node_modules/status-dev-cli/index.js status-dev-cli; +else + echo "status-dev-cli exists" +fi \ No newline at end of file diff --git a/resources/console.js b/resources/console.js index ec237c993f..b5f90be3e7 100644 --- a/resources/console.js +++ b/resources/console.js @@ -1767,6 +1767,51 @@ status.command({ } }); +function debugSuggestions(params) { + var suggestions = ["On", "Off"].map(function(entry) { + return status.components.touchable( + {onPress: [status.events.SET_VALUE, entry]}, + status.components.view( + suggestionContainerStyle, + [status.components.view( + suggestionSubContainerStyle, + [ + status.components.text( + {style: valueStyle}, + entry + ) + ] + )] + ) + ); + }); + + var view = status.components.scrollView( + suggestionsContainerStyle(faucets.length), + suggestions + ); + + return {markup: view}; +} + +status.command({ + name: "debug", + title: "Debug", + description: "Starts/stops a debug server", + color: "#7099e6", + registeredOnly: true, + params: [{ + name: "mode", + suggestions: debugSuggestions, + type: status.types.TEXT + }], + preview: function (params) { + return status.components.text( + {}, + "Debug mode: " + params.mode + ); + } +}); function browseSuggestions(params) { if (params.url && params.url !== "undefined" && params.url != "") { diff --git a/src/status_im/accounts/login/handlers.cljs b/src/status_im/accounts/login/handlers.cljs index 32a86ecee7..469c31cb0b 100644 --- a/src/status_im/accounts/login/handlers.cljs +++ b/src/status_im/accounts/login/handlers.cljs @@ -21,6 +21,7 @@ (defn initialize-account [address new-account?] (dispatch [:set :login {}]) + (dispatch [:debug-server-stop]) (dispatch [:set-current-account address]) (dispatch [:initialize-account address]) (if new-account? diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 81dbb8dc1f..14a6ef994c 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -9,7 +9,8 @@ back-android view modal - splash-screen]] + splash-screen + http-bridge]] [status-im.components.main-tabs :refer [main-tabs]] [status-im.contacts.search-results :refer [contacts-search-results]] [status-im.contacts.views.contact-list :refer [contact-list]] @@ -83,6 +84,9 @@ #(when-not (= 0 @keyboard-height) (dispatch [:set :keyboard-height 0]))) (.hide splash-screen)) + :component-will-unmount + (fn [] + (.stop http-bridge)) :render (fn [] (when @view-id diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 1cff5d5ba7..45501da487 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -497,7 +497,10 @@ (defn delete-chat! [_ [_ chat-id]] - (chats/delete chat-id)) + (let [{:keys [debug?]} (chats/get-by-id chat-id)] + (if debug? + (chats/delete chat-id) + (chats/set-inactive chat-id)))) (defn remove-pending-messages! [_ [_ chat-id]] @@ -519,9 +522,9 @@ :private private-key} :message {:from current-public-key :message-id (random/id)}})) - (dispatch [::remove-chat current-chat-id])))) + (dispatch [:remove-chat current-chat-id])))) -(register-handler ::remove-chat +(register-handler :remove-chat (-> remove-chat ;((after leaving-message!)) ((after delete-messages!)) diff --git a/src/status_im/chat/handlers/console.cljs b/src/status_im/chat/handlers/console.cljs index c62e1f8967..3f5fab32e0 100644 --- a/src/status_im/chat/handlers/console.cljs +++ b/src/status_im/chat/handlers/console.cljs @@ -22,12 +22,20 @@ :faucet (fn [params id] - (dispatch [:open-faucet (params "url") id]))}) + (dispatch [:open-faucet (params "url") id])) + + :debug + (fn [params id] + (let [debug-on? (= (params "mode") "On")] + (dispatch [:account-update {:debug? debug-on?}]) + (if debug-on? + (dispatch [:debug-server-start]) + (dispatch [:debug-server-stop]))))}) (def commands-names (set (keys console-commands))) (def commands-with-delivery-status - (disj commands-names :password :faucet)) + (disj commands-names :password :faucet :debug)) (register-handler :invoke-console-command-handler! (u/side-effect! diff --git a/src/status_im/components/react.cljs b/src/status_im/components/react.cljs index ac60feb7be..2feb470712 100644 --- a/src/status_im/components/react.cljs +++ b/src/status_im/components/react.cljs @@ -144,4 +144,9 @@ (defn autolink [opts] (r/as-element - [autolink-class (add-font-style :style opts)])) \ No newline at end of file + [autolink-class (add-font-style :style opts)])) + +;; HTTP Bridge + +(def http-bridge + (js/require "react-native-http-bridge")) diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index 8e0ffce51b..d989ff9390 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -280,13 +280,23 @@ (dispatch [:update-contact! {:whisper-identity from :last-online timestamp}])))))) -(register-handler :remove-contact +(register-handler :hide-contact (after stop-watching-contact) (u/side-effect! (fn [_ [_ {:keys [whisper-identity] :as contact}]] (dispatch [:update-contact! (assoc contact :pending true)]) (dispatch [:account-update-keys])))) +(register-handler :remove-contact + (fn [db [_ whisper-identity pred]] + (if-let [contact (contacts/get-by-id whisper-identity)] + (if (pred contact) + (do + (contacts/delete contact) + (update db :contacts dissoc whisper-identity)) + db) + db))) + (register-handler :open-contact-menu (u/side-effect! @@ -295,6 +305,6 @@ :options [(label :t/remove-contact)] :callback (fn [index] (case index - 0 (dispatch [:remove-contact contact]) + 0 (dispatch [:hide-contact contact]) :default)) :cancel-text (label :t/cancel)})))) diff --git a/src/status_im/data_store/chats.cljs b/src/status_im/data_store/chats.cljs index 58f73645b3..4ed378a66b 100644 --- a/src/status_im/data_store/chats.cljs +++ b/src/status_im/data_store/chats.cljs @@ -28,6 +28,10 @@ [chat-id] (data-store/delete chat-id)) +(defn set-inactive + [chat-id] + (data-store/set-inactive chat-id)) + (defn get-contacts [chat-id] (data-store/get-contacts chat-id)) diff --git a/src/status_im/data_store/realm/chats.cljs b/src/status_im/data_store/realm/chats.cljs index ec24c5b70e..66d12ecf52 100644 --- a/src/status_im/data_store/realm/chats.cljs +++ b/src/status_im/data_store/realm/chats.cljs @@ -1,6 +1,7 @@ (ns status-im.data-store.realm.chats (:require [status-im.data-store.realm.core :as realm] - [status-im.utils.random :refer [timestamp]]) + [status-im.utils.random :refer [timestamp]] + [taoensso.timbre :as log]) (:refer-clojure :exclude [exists?])) (defn get-all @@ -49,6 +50,11 @@ (realm/exists? @realm/account-realm :chat {:chat-id chat-id})) (defn delete + [chat-id] + (when-let [chat (realm/get-by-field @realm/account-realm :chat :chat-id chat-id)] + (realm/delete @realm/account-realm chat))) + +(defn set-inactive [chat-id] (when-let [chat (get-by-id chat-id)] (realm/write @realm/account-realm diff --git a/src/status_im/data_store/realm/schemas/account/core.cljs b/src/status_im/data_store/realm/schemas/account/core.cljs index d1bf440c1c..66f4e50faa 100644 --- a/src/status_im/data_store/realm/schemas/account/core.cljs +++ b/src/status_im/data_store/realm/schemas/account/core.cljs @@ -1,6 +1,7 @@ (ns status-im.data-store.realm.schemas.account.core (:require [status-im.data-store.realm.schemas.account.v1.core :as v1] - [status-im.data-store.realm.schemas.account.v2.core :as v2])) + [status-im.data-store.realm.schemas.account.v2.core :as v2] + [status-im.data-store.realm.schemas.account.v3.core :as v3])) ; put schemas ordered by version (def schemas [{:schema v1/schema @@ -8,4 +9,7 @@ :migration v1/migration} {:schema v2/schema :schemaVersion 2 - :migration v2/migration}]) + :migration v2/migration} + {:schema v3/schema + :schemaVersion 3 + :migration v3/migration}]) diff --git a/src/status_im/data_store/realm/schemas/account/v3/chat.cljs b/src/status_im/data_store/realm/schemas/account/v3/chat.cljs new file mode 100644 index 0000000000..780b2e164b --- /dev/null +++ b/src/status_im/data_store/realm/schemas/account/v3/chat.cljs @@ -0,0 +1,40 @@ +(ns status-im.data-store.realm.schemas.account.v3.chat + (:require [taoensso.timbre :as log] + [status-im.components.styles :refer [default-chat-color]])) + +(def schema {:name :chat + :primaryKey :chat-id + :properties {:chat-id :string + :name :string + :color {:type :string + :default default-chat-color} + :group-chat {:type :bool + :indexed true} + :group-admin {:type :string + :optional true} + :is-active :bool + :timestamp :int + :contacts {:type :list + :objectType :chat-contact} + :removed-at {:type :int + :optional true} + :removed-from-at {:type :int + :optional true} + :added-to-at {:type :int + :optional true} + :updated-at {:type :int + :optional true} + :last-message-id :string + :message-overhead {:type :int + :default 0} + :public-key {:type :string + :optional true} + :private-key {:type :string + :optional true} + :contact-info {:type :string + :optional true} + :debug? {:type :bool + :default false}}}) + +(defn migration [old-realm new-realm] + (log/debug "migrating chat schema v3")) diff --git a/src/status_im/data_store/realm/schemas/account/v3/contact.cljs b/src/status_im/data_store/realm/schemas/account/v3/contact.cljs new file mode 100644 index 0000000000..d74d5a5010 --- /dev/null +++ b/src/status_im/data_store/realm/schemas/account/v3/contact.cljs @@ -0,0 +1,28 @@ +(ns status-im.data-store.realm.schemas.account.v3.contact + (:require [taoensso.timbre :as log])) + +(def schema {:name :contact + :primaryKey :whisper-identity + :properties {:address {:type "string" :optional true} + :whisper-identity "string" + :name {:type "string" :optional true} + :photo-path {:type "string" :optional true} + :last-updated {:type "int" :default 0} + :last-online {:type "int" :default 0} + :pending? {:type "bool" :default false} + :status {:type "string" :optional true} + :public-key {:type :string + :optional true} + :private-key {:type :string + :optional true} + :dapp? {:type :bool + :default false} + :dapp-url {:type :string + :optional true} + :dapp-hash {:type :int + :optional true} + :debug? {:type :bool + :default false}}}) + +(defn migration [old-realm new-realm] + (log/debug "migrating contact schema v3")) diff --git a/src/status_im/data_store/realm/schemas/account/v3/core.cljs b/src/status_im/data_store/realm/schemas/account/v3/core.cljs new file mode 100644 index 0000000000..3eebb58877 --- /dev/null +++ b/src/status_im/data_store/realm/schemas/account/v3/core.cljs @@ -0,0 +1,32 @@ +(ns status-im.data-store.realm.schemas.account.v3.core + (:require [status-im.data-store.realm.schemas.account.v3.chat :as chat] + [status-im.data-store.realm.schemas.account.v1.chat-contact :as chat-contact] + [status-im.data-store.realm.schemas.account.v1.command :as command] + [status-im.data-store.realm.schemas.account.v3.contact :as contact] + [status-im.data-store.realm.schemas.account.v1.discover :as discover] + [status-im.data-store.realm.schemas.account.v1.kv-store :as kv-store] + [status-im.data-store.realm.schemas.account.v1.message :as message] + [status-im.data-store.realm.schemas.account.v1.pending-message :as pending-message] + [status-im.data-store.realm.schemas.account.v1.processed-message :as processed-message] + [status-im.data-store.realm.schemas.account.v1.request :as request] + [status-im.data-store.realm.schemas.account.v1.tag :as tag] + [status-im.data-store.realm.schemas.account.v1.user-status :as user-status] + [taoensso.timbre :as log])) + +(def schema [chat/schema + chat-contact/schema + command/schema + contact/schema + discover/schema + kv-store/schema + message/schema + pending-message/schema + processed-message/schema + request/schema + tag/schema + user-status/schema]) + +(defn migration [old-realm new-realm] + (log/debug "migrating v3 account database: " old-realm new-realm) + (chat/migration old-realm new-realm) + (contact/migration old-realm new-realm)) diff --git a/src/status_im/data_store/realm/schemas/base/core.cljs b/src/status_im/data_store/realm/schemas/base/core.cljs index 34bd4bc171..b96a0788e9 100644 --- a/src/status_im/data_store/realm/schemas/base/core.cljs +++ b/src/status_im/data_store/realm/schemas/base/core.cljs @@ -1,7 +1,11 @@ (ns status-im.data-store.realm.schemas.base.core - (:require [status-im.data-store.realm.schemas.base.v1.core :as v1])) + (:require [status-im.data-store.realm.schemas.base.v1.core :as v1] + [status-im.data-store.realm.schemas.base.v2.core :as v2])) ; put schemas ordered by version (def schemas [{:schema v1/schema :schemaVersion 1 - :migration v1/migration}]) + :migration v1/migration} + {:schema v2/schema + :schemaVersion 2 + :migration v2/migration}]) diff --git a/src/status_im/data_store/realm/schemas/base/v2/account.cljs b/src/status_im/data_store/realm/schemas/base/v2/account.cljs new file mode 100644 index 0000000000..4353751abb --- /dev/null +++ b/src/status_im/data_store/realm/schemas/base/v2/account.cljs @@ -0,0 +1,25 @@ +(ns status-im.data-store.realm.schemas.base.v2.account + (:require [taoensso.timbre :as log])) + +(def schema {:name :account + :primaryKey :address + :properties {:address :string + :public-key :string + :updates-public-key {:type :string + :optional true} + :updates-private-key {:type :string + :optional true} + :name {:type :string :optional true} + :phone {:type :string :optional true} + :email {:type :string :optional true} + :status {:type :string :optional true} + :debug? {:type :bool :default false} + :photo-path :string + :last-updated {:type :int :default 0} + :signed-up? {:type :bool + :default false} + :network :string}}) + +(defn migration [_ _] + (log/debug "migrating account schema")) + diff --git a/src/status_im/data_store/realm/schemas/base/v2/core.cljs b/src/status_im/data_store/realm/schemas/base/v2/core.cljs new file mode 100644 index 0000000000..3a9c6bcf1d --- /dev/null +++ b/src/status_im/data_store/realm/schemas/base/v2/core.cljs @@ -0,0 +1,13 @@ +(ns status-im.data-store.realm.schemas.base.v2.core + (:require [status-im.data-store.realm.schemas.base.v2.account :as account] + [status-im.data-store.realm.schemas.base.v1.kv-store :as kv-store] + [taoensso.timbre :as log])) + +(def schema [account/schema + kv-store/schema]) + +(defn migration [old-realm new-realm] + (log/debug "migrating v2 base database: " old-realm new-realm) + (account/migration old-realm new-realm) + (kv-store/migration old-realm new-realm)) + diff --git a/src/status_im/debug/handlers.cljs b/src/status_im/debug/handlers.cljs new file mode 100644 index 0000000000..31041346d9 --- /dev/null +++ b/src/status_im/debug/handlers.cljs @@ -0,0 +1,82 @@ +(ns status-im.debug.handlers + (: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.data-store.accounts :as accounts] + [taoensso.timbre :as log])) + +(def debug-server-port 5561) + +(register-handler :init-debug-mode + (u/side-effect! + (fn [_ [_ address]] + (let [{:keys [debug?]} (accounts/get-by-address address)] + (when debug? + (dispatch [:debug-server-start])))))) + +(register-handler :debug-server-start + (u/side-effect! + (fn [_] + (.start http-bridge + debug-server-port + (fn [req] + (try + (let [{:keys [postData url]} (js->clj req :keywordize-keys true) + postData (if (string? postData) + (-> (.parse js/JSON postData) + (js->clj :keywordize-keys true)) + postData)] + (dispatch [:debug-request {:url url :postData postData}])) + (catch js/Error e + (log/debug "Error: " e)))))))) + +(register-handler :debug-server-stop + (u/side-effect! + (fn [_] + (.stop http-bridge)))) + +(register-handler :debug-request + (u/side-effect! + (fn [{:keys [web3]} [_ {url :url + {:keys [encoded]} :postData :as d}]] + (try + (let [json (->> (.toAscii web3 encoded) + (.parse js/JSON)) + obj (js->clj json :keywordize-keys true)] + (case url + "/add-dapp" (dispatch [:debug-add-dapp obj]) + "/remove-dapp" (dispatch [:debug-remove-dapp obj]) + "/dapp-changed" (dispatch [:debug-dapp-changed obj]) + :default)) + (catch js/Error e + (log/debug "Error: " e)))))) + +(register-handler :debug-add-dapp + (u/side-effect! + (fn [{:keys [contacts]} [_ {:keys [name whisper-identity dapp-url] :as dapp-data}]] + (when (and name + whisper-identity + dapp-url + (or (not (get contacts whisper-identity)) + (get-in contacts [whisper-identity :debug?]))) + (let [dapp (merge dapp-data {:dapp? true + :debug? true})] + (dispatch [:add-chat whisper-identity {:name name + :debug? true}]) + (dispatch [:add-contacts [dapp]])))))) + +(register-handler :debug-remove-dapp + (u/side-effect! + (fn [{:keys [chats]} [_ {:keys [whisper-identity]}]] + (when (get-in chats [whisper-identity :debug?]) + (dispatch [:remove-chat whisper-identity])) + (dispatch [:remove-contact whisper-identity #(and (:dapp? %) (:debug? %))])))) + +(register-handler :debug-dapp-changed + (u/side-effect! + (fn [{:keys [webview-bridge current-chat-id chats]} [_ {:keys [whisper-identity]}]] + (when (and (= current-chat-id whisper-identity) + (get-in chats [whisper-identity :debug?]) + webview-bridge) + (.reload webview-bridge))))) + diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index c4583c4ef7..4017d009b5 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -22,6 +22,7 @@ status-im.protocol.handlers status-im.transactions.handlers status-im.network.handlers + status-im.debug.handlers [status-im.utils.types :as t] [status-im.i18n :refer [label]] [status-im.constants :refer [console-chat-id]] @@ -76,6 +77,7 @@ (dispatch [:load-contacts]) (dispatch [:init-chat]) (dispatch [:init-discoveries]) + (dispatch [:init-debug-mode address]) (dispatch [:send-account-update-if-needed]) (dispatch [:start-requesting-discoveries]) (dispatch [:remove-old-discoveries!])))) diff --git a/src/status_im/ios/core.cljs b/src/status_im/ios/core.cljs index 01888221d6..3860bbd02e 100644 --- a/src/status_im/ios/core.cljs +++ b/src/status_im/ios/core.cljs @@ -8,7 +8,8 @@ app-registry keyboard orientation - splash-screen]] + splash-screen + http-bridge]] [status-im.components.main-tabs :refer [main-tabs]] [status-im.contacts.search-results :refer [contacts-search-results]] [status-im.contacts.views.contact-list :refer [contact-list]] @@ -71,6 +72,9 @@ #(when-not (= 0 @keyboard-height) (dispatch [:set :keyboard-height 0]))) (.hide splash-screen)) + :component-will-unmount + (fn [] + (.stop http-bridge)) :render (fn [] (when @view-id diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index 5d0cc27e35..18549325fc 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -105,32 +105,32 @@ (cache/add! processed-message) (processed-messages/save processed-message)) (case type - :message (dispatch [:received-protocol-message! message]) - :group-message (dispatch [:received-protocol-message! message]) - :ack (if (#{:message :group-message} (:type payload)) - (dispatch [:message-delivered message]) - (dispatch [:pending-message-remove message])) - :seen (dispatch [:message-seen message]) - :clock-value-request (dispatch [:message-clock-value-request message]) - :clock-value (dispatch [:message-clock-value message]) - :group-invitation (dispatch [:group-chat-invite-received message]) - :update-group (dispatch [:update-group-message message]) - :add-group-identity (dispatch [:participant-invited-to-group message]) + :message (dispatch [:received-protocol-message! message]) + :group-message (dispatch [:received-protocol-message! message]) + :ack (if (#{:message :group-message} (:type payload)) + (dispatch [:message-delivered message]) + (dispatch [:pending-message-remove message])) + :seen (dispatch [:message-seen message]) + :clock-value-request (dispatch [:message-clock-value-request message]) + :clock-value (dispatch [:message-clock-value message]) + :group-invitation (dispatch [:group-chat-invite-received message]) + :update-group (dispatch [:update-group-message message]) + :add-group-identity (dispatch [:participant-invited-to-group message]) :remove-group-identity (dispatch [:participant-removed-from-group message]) - :leave-group (dispatch [:participant-left-group message]) - :contact-request (dispatch [:contact-request-received message]) - :discover (dispatch [:status-received message]) - :discoveries-request (dispatch [:discoveries-request-received message]) - :discoveries-response (dispatch [:discoveries-response-received message]) - :profile (dispatch [:contact-update-received message]) - :update-keys (dispatch [:update-keys-received message]) - :online (dispatch [:contact-online-received message]) - :pending (dispatch [:pending-message-upsert message]) - :sent (let [{:keys [to id group-id]} message - message' {:from to - :payload {:message-id id - :group-id group-id}}] - (dispatch [:message-sent message'])) + :leave-group (dispatch [:participant-left-group message]) + :contact-request (dispatch [:contact-request-received message]) + :discover (dispatch [:status-received message]) + :discoveries-request (dispatch [:discoveries-request-received message]) + :discoveries-response (dispatch [:discoveries-response-received message]) + :profile (dispatch [:contact-update-received message]) + :update-keys (dispatch [:update-keys-received message]) + :online (dispatch [:contact-online-received message]) + :pending (dispatch [:pending-message-upsert message]) + :sent (let [{:keys [to id group-id]} message + message' {:from to + :payload {:message-id id + :group-id group-id}}] + (dispatch [:message-sent message'])) (debug "Unknown message type" type))))))) (defn system-message diff --git a/src/status_im/protocol/listeners.cljs b/src/status_im/protocol/listeners.cljs index 2f0b48dee0..2b7df7a164 100644 --- a/src/status_im/protocol/listeners.cljs +++ b/src/status_im/protocol/listeners.cljs @@ -51,3 +51,4 @@ message' (assoc message :payload payload'')] (callback (if ack? :ack type) message') (ack/check-ack! web3 from payload'' identity))))))))) +