From b6977dc0b77d89220d8c3f4e38c671841edd87b5 Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Sat, 17 Sep 2016 15:35:01 +0300 Subject: [PATCH] Cleanup after protocol's refactoring --- project.clj | 9 ++---- run-osx.sh | 2 +- src/status_im/accounts/handlers.cljs | 8 +---- src/status_im/accounts/login/handlers.cljs | 2 +- src/status_im/accounts/recover/handlers.cljs | 8 ++--- src/status_im/accounts/recover/screen.cljs | 2 +- src/status_im/accounts/screen.cljs | 4 +-- src/status_im/android/core.cljs | 5 ++-- src/status_im/chat/handlers.cljs | 10 +++---- src/status_im/chat/handlers/animation.cljs | 1 - .../chat/handlers/receive_message.cljs | 3 +- .../chat/handlers/unviewed_messages.cljs | 3 +- .../chat/handlers/webview_bridge.cljs | 2 +- src/status_im/chat/screen.cljs | 14 --------- src/status_im/chat/sign_up.cljs | 8 ----- src/status_im/chat/styles/screen.cljs | 5 ++-- src/status_im/chat/subs.cljs | 1 - src/status_im/chat/views/actions.cljs | 5 ++-- src/status_im/chat/views/bottom_info.cljs | 3 +- src/status_im/chat/views/message.cljs | 6 ++-- .../components/carousel/carousel.cljs | 2 +- src/status_im/components/status.cljs | 2 +- src/status_im/components/text_field/view.cljs | 2 +- src/status_im/db.cljs | 2 -- src/status_im/discovery/handlers.cljs | 1 - src/status_im/discovery/model.cljs | 6 ++-- src/status_im/handlers.cljs | 23 ++------------- .../handlers/content_suggestions.cljs | 25 ---------------- src/status_im/handlers/server.cljs | 2 +- src/status_im/ios/core.cljs | 5 ++-- src/status_im/models/chats.cljs | 1 - src/status_im/models/contacts.cljs | 3 +- src/status_im/models/messages.cljs | 1 - src/status_im/models/pending_messages.cljs | 1 - src/status_im/models/protocol.cljs | 20 ------------- src/status_im/persistence/realm/core.cljs | 4 +-- src/status_im/persistence/realm/schemas.cljs | 4 ++- .../persistence/simple_kv_store.cljs | 29 ------------------- src/status_im/protocol/handlers.cljs | 13 +-------- src/status_im/protocol/protocol_handler.cljs | 7 ----- src/status_im/protocol/web3/delivery.cljs | 6 ++-- src/status_im/subs.cljs | 9 +++++- src/status_im/utils/random.cljs | 8 +++++ 43 files changed, 62 insertions(+), 215 deletions(-) delete mode 100644 src/status_im/handlers/content_suggestions.cljs delete mode 100644 src/status_im/models/protocol.cljs delete mode 100644 src/status_im/persistence/simple_kv_store.cljs delete mode 100644 src/status_im/protocol/protocol_handler.cljs create mode 100644 src/status_im/utils/random.cljs diff --git a/project.clj b/project.clj index ec08249e0b..478bbf4d91 100644 --- a/project.clj +++ b/project.clj @@ -3,13 +3,11 @@ :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.9.0-alpha11"] - [org.clojure/clojurescript "1.9.227"] + :dependencies [[org.clojure/clojure "1.9.0-alpha12"] + [org.clojure/clojurescript "1.9.229"] [reagent "0.5.1" :exclusions [cljsjs/react]] [re-frame "0.7.0"] [prismatic/schema "1.0.4"] - ^{:voom {:repo "git@github.com:status-im/status-lib.git" :branch "group-chat-statuses"}} - [status-im/protocol "0.2.3-20160914_155558-gfed628a"] [natal-shell "0.3.0"] [com.andrewmcveigh/cljs-time "0.4.0"] [tailrecursion/cljs-priority-map "1.2.0"] @@ -19,8 +17,7 @@ [cljsjs/chance "0.7.3-0"] [cljsjs/eccjs "0.3.1-0"]] :plugins [[lein-cljsbuild "1.1.1"] - [lein-figwheel "0.5.0-2"] - [lein-voom "0.1.0-20160311_203101-g259fbfc"]] + [lein-figwheel "0.5.0-2"]] :clean-targets ["target/" "index.ios.js" "index.android.js"] :aliases {"prod-build" ^{:doc "Recompile code with prod profile."} ["do" "clean" diff --git a/run-osx.sh b/run-osx.sh index 47346feb5a..4097f2d4ea 100755 --- a/run-osx.sh +++ b/run-osx.sh @@ -54,7 +54,7 @@ open -a /Applications/Genymotion.app/Contents/MacOS/player.app --args --vm-name fi # Install deps, prepare for genymotion and figwheel -lein voom build-deps && re-natal deps && re-natal use-android-device "${device_type}" && re-natal use-figwheel +lein deps && re-natal deps && re-natal use-android-device "${device_type}" && re-natal use-figwheel # open figwheel in new tab tab "lein figwheel ${cljs_build}" diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 9a6fec2fa8..cc6fa53933 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -1,16 +1,13 @@ (ns status-im.accounts.handlers (:require [status-im.models.accounts :as accounts-model] [re-frame.core :refer [register-handler after dispatch dispatch-sync debug]] - [status-im.utils.logging :as log] + [taoensso.timbre :as log] [status-im.protocol.core :as protocol] [status-im.components.status :as status] [status-im.utils.types :refer [json->clj]] - [status-im.persistence.simple-kv-store :as kv] - [status-im.protocol.state.storage :as storage] [status-im.utils.identicon :refer [identicon]] [status-im.db :refer [default-view]] [status-im.utils.random :as random] - [status-im.persistence.realm.core :as realm] [status-im.i18n :refer [label]] [status-im.constants :refer [content-type-command-request]] status-im.accounts.login.handlers @@ -29,9 +26,6 @@ (update db :accounts assoc address account)) ((after save-account)))) -(defn save-password [password] - (storage/put kv/kv-store :password password)) - (defn account-created [result password] (let [data (json->clj result) public-key (:pubkey data) diff --git a/src/status_im/accounts/login/handlers.cljs b/src/status_im/accounts/login/handlers.cljs index 38cf1ae0ff..889d5cf896 100644 --- a/src/status_im/accounts/login/handlers.cljs +++ b/src/status_im/accounts/login/handlers.cljs @@ -1,7 +1,7 @@ (ns status-im.accounts.login.handlers (:require [re-frame.core :refer [after dispatch]] [status-im.utils.handlers :refer [register-handler] :as u] - [status-im.utils.logging :as log] + [taoensso.timbre :as log] [status-im.utils.types :refer [json->clj]] [status-im.db :refer [default-view]] [status-im.persistence.realm.core :as realm] diff --git a/src/status_im/accounts/recover/handlers.cljs b/src/status_im/accounts/recover/handlers.cljs index e97a168d46..837c140902 100644 --- a/src/status_im/accounts/recover/handlers.cljs +++ b/src/status_im/accounts/recover/handlers.cljs @@ -3,13 +3,9 @@ [status-im.components.status :as status] [status-im.utils.types :refer [json->clj]] [status-im.utils.identicon :refer [identicon]] - [status-im.utils.logging :as log] + [taoensso.timbre :as log] [clojure.string :as str])) -(defn on-account-changed - [error address new-account?] - (dispatch [:navigate-to-clean :accounts])) - (defn account-recovered [result password] (let [_ (log/debug result) data (json->clj result) @@ -32,4 +28,4 @@ (status/recover-account passphrase password (fn [result] (account-recovered result password))) db) -(register-handler :recover-account recover-account) \ No newline at end of file +(register-handler :recover-account recover-account) diff --git a/src/status_im/accounts/recover/screen.cljs b/src/status_im/accounts/recover/screen.cljs index b2b90397df..398265c131 100644 --- a/src/status_im/accounts/recover/screen.cljs +++ b/src/status_im/accounts/recover/screen.cljs @@ -24,7 +24,7 @@ [status-im.accounts.recover.validations :as v] [cljs.spec :as s] [clojure.string :as str] - [status-im.utils.logging :as log])) + [taoensso.timbre :as log])) (defn toolbar-title [] [view toolbar-title-container diff --git a/src/status_im/accounts/screen.cljs b/src/status_im/accounts/screen.cljs index 690e1ee034..c2111578eb 100644 --- a/src/status_im/accounts/screen.cljs +++ b/src/status_im/accounts/screen.cljs @@ -25,10 +25,8 @@ white-form-text-input]] [status-im.utils.listview :as lw] [status-im.accounts.views.account :refer [account-view]] - [status-im.chat.sign-up :as sign-up-service] [status-im.i18n :refer [label]] - [status-im.accounts.styles :as st] - [status-im.utils.logging :as log])) + [status-im.accounts.styles :as st])) (defn toolbar-title [] (let [style (merge toolbar-title-text {:color color-white})] diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index 51f9f61314..8bd056dbdd 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -27,9 +27,8 @@ [status-im.profile.screen :refer [profile my-profile]] [status-im.profile.photo-capture.screen :refer [profile-photo-capture]] [status-im.utils.utils :refer [toast]] - [status-im.utils.encryption] status-im.persistence.realm.core - [status-im.utils.logging :as log] + [taoensso.timbre :as log] [status-im.components.status :as status])) (defn init-back-button-handler! [] @@ -47,7 +46,7 @@ (keyword (.toLowerCase o))) (defn app-root [] - (let [signed-up (subscribe [:get :signed-up]) + (let [signed-up (subscribe [:signed-up?]) view-id (subscribe [:get :view-id]) account-id (subscribe [:get :current-account-id]) keyboard-height (subscribe [:get :keyboard-height])] diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 34fd3b4e1e..4eb69f9b27 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -5,7 +5,6 @@ [clojure.string :as str] [status-im.components.styles :refer [default-chat-color]] [status-im.chat.suggestions :as suggestions] - [status-im.protocol.api :as api] [status-im.protocol.core :as protocol] [status-im.models.chats :as chats] [status-im.models.messages :as messages] @@ -20,7 +19,6 @@ [status-im.utils.handlers :refer [register-handler] :as u] [status-im.persistence.realm.core :as r] [status-im.handlers.server :as server] - [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.utils.phone-number :refer [format-phone-number valid-mobile-number?]] [status-im.components.status :as status] @@ -34,8 +32,7 @@ status-im.chat.handlers.receive-message [cljs.core.async :as a] status-im.chat.handlers.webview-bridge - status-im.chat.handlers.wallet-chat - [status-im.utils.logging :as log])) + status-im.chat.handlers.wallet-chat)) (register-handler :set-chat-ui-props (fn [db [_ ui-element value]] @@ -219,8 +216,9 @@ (server/sign-up-confirm confirmation-code sign-up-service/on-send-code-response)))) (register-handler :set-signed-up - (fn [db [_ signed-up]] - (sign-up-service/set-signed-up db signed-up))) + (u/side-effect! + (fn [_ [_ signed-up]] + (dispatch [:account-update {:signed-up? signed-up}])))) (defn load-messages! ([db] (load-messages! db nil)) diff --git a/src/status_im/chat/handlers/animation.cljs b/src/status_im/chat/handlers/animation.cljs index a5c23a91c5..487407a6ab 100644 --- a/src/status_im/chat/handlers/animation.cljs +++ b/src/status_im/chat/handlers/animation.cljs @@ -1,7 +1,6 @@ (ns status-im.chat.handlers.animation (:require [re-frame.core :refer [after dispatch debug path]] [status-im.utils.handlers :refer [register-handler]] - [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.chat.constants :refer [input-height request-info-height suggestions-header-height minimum-command-suggestions-height diff --git a/src/status_im/chat/handlers/receive_message.cljs b/src/status_im/chat/handlers/receive_message.cljs index 0a4b606c63..388ec1d4d7 100644 --- a/src/status_im/chat/handlers/receive_message.cljs +++ b/src/status_im/chat/handlers/receive_message.cljs @@ -6,8 +6,7 @@ [status-im.commands.utils :refer [generate-hiccup]] [status-im.constants :refer [content-type-command-request]] [cljs.reader :refer [read-string]] - [status-im.models.chats :as c] - [status-im.utils.logging :as log])) + [status-im.models.chats :as c])) (defn check-preview [{:keys [content] :as message}] (if-let [preview (:preview content)] diff --git a/src/status_im/chat/handlers/unviewed_messages.cljs b/src/status_im/chat/handlers/unviewed_messages.cljs index c24ae9502f..d25beb18fe 100644 --- a/src/status_im/chat/handlers/unviewed_messages.cljs +++ b/src/status_im/chat/handlers/unviewed_messages.cljs @@ -1,8 +1,7 @@ (ns status-im.chat.handlers.unviewed-messages (:require [re-frame.core :refer [after enrich path dispatch]] [status-im.utils.handlers :refer [register-handler]] - [status-im.persistence.realm.core :as realm] - [status-im.utils.logging :as log])) + [status-im.persistence.realm.core :as realm])) (defn delivered-messages [] (-> (realm/get-by-fields :account :message :and {:outgoing false diff --git a/src/status_im/chat/handlers/webview_bridge.cljs b/src/status_im/chat/handlers/webview_bridge.cljs index afeec2c8a4..e13667e36a 100644 --- a/src/status_im/chat/handlers/webview_bridge.cljs +++ b/src/status_im/chat/handlers/webview_bridge.cljs @@ -3,7 +3,7 @@ [status-im.utils.handlers :refer [register-handler]] [status-im.utils.handlers :as u] [status-im.utils.types :as t] - [status-im.utils.logging :as log])) + [taoensso.timbre :as log])) (register-handler :set-webview-bridge (fn [db [_ bridge]] diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index 101a084eee..7f1fc61068 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -1,7 +1,6 @@ (ns status-im.chat.screen (:require-macros [status-im.utils.views :refer [defview]]) (:require [re-frame.core :refer [subscribe dispatch]] - [clojure.string :as s] [status-im.components.react :refer [view animated-view text @@ -74,19 +73,6 @@ (assoc :last-message (= (js/parseInt idx) (dec messages-count))))] (list-item [chat-message message])))) -(defn on-action-selected [position] - (case position - 0 (dispatch [:navigate-to :add-participants]) - 1 (dispatch [:navigate-to :remove-participants]) - 2 (dispatch [:leave-group-chat]))) - -(defn overlay [{:keys [on-click-outside]} items] - [view st/actions-overlay - [touchable-highlight {:on-press on-click-outside - :style st/overlay-highlight} - [view nil]] - items]) - (defn online-text [contact chat-id] (if contact (let [last-online (get contact :last-online) diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index 6c4b519247..2c69491086 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -1,9 +1,5 @@ (ns status-im.chat.sign-up - ;status-im.handlers.sign-up (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] - [status-im.persistence.simple-kv-store :as kv] - [status-im.protocol.state.storage :as s] - [status-im.models.chats :as c] [status-im.components.styles :refer [default-chat-color]] [status-im.utils.utils :refer [on-error http-post toast]] [status-im.utils.random :as random] @@ -24,10 +20,6 @@ :content-type text-content-type :outgoing true}) -(defn set-signed-up [db signed-up] - (s/put kv/kv-store :signed-up signed-up) - (assoc db :signed-up signed-up)) - ; todo fn name is not too smart, but... (defn command-content [command content] diff --git a/src/status_im/chat/styles/screen.cljs b/src/status_im/chat/styles/screen.cljs index 8e3d9ff888..0e03df2681 100644 --- a/src/status_im/chat/styles/screen.cljs +++ b/src/status_im/chat/styles/screen.cljs @@ -9,8 +9,7 @@ separator-color text1-color text2-color - toolbar-background1]] - [status-im.utils.logging :as log])) + toolbar-background1]])) (def chat-view {:flex 1 @@ -193,4 +192,4 @@ {:color "black"}) (def bottom-info-row-text2 - {:color "#888888"}) \ No newline at end of file + {:color "#888888"}) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 77867865b3..99529f9f6a 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -6,7 +6,6 @@ [status-im.models.chats :as chats] [status-im.constants :refer [response-suggesstion-resize-duration]] [status-im.chat.constants :as c] - [status-im.handlers.content-suggestions :refer [get-content-suggestions]] [status-im.chat.views.plain-message :as plain-message] [status-im.chat.views.command :as command])) diff --git a/src/status_im/chat/views/actions.cljs b/src/status_im/chat/views/actions.cljs index d9539fd0d3..1ea7274e2e 100644 --- a/src/status_im/chat/views/actions.cljs +++ b/src/status_im/chat/views/actions.cljs @@ -12,8 +12,7 @@ [status-im.components.chat-icon.screen :refer [chat-icon-view-menu-item]] [status-im.chat.styles.screen :as st] [status-im.i18n :refer [label label-pluralize]] - [status-im.utils.platform :refer [platform-specific]] - [status-im.utils.logging :as log])) + [status-im.utils.platform :refer [platform-specific]])) (defview menu-item-icon-profile [] [chat-id [:chat :chat-id] @@ -139,4 +138,4 @@ (defn actions-view [] [overlay {:on-click-outside #(dispatch [:set-chat-ui-props :show-actions? false])} - [actions-list-view]]) \ No newline at end of file + [actions-list-view]]) diff --git a/src/status_im/chat/views/bottom_info.cljs b/src/status_im/chat/views/bottom_info.cljs index 9e1748b226..82eb93cf68 100644 --- a/src/status_im/chat/views/bottom_info.cljs +++ b/src/status_im/chat/views/bottom_info.cljs @@ -17,7 +17,6 @@ [status-im.utils.utils :refer [truncate-str]] [status-im.utils.identicon :refer [identicon]] [status-im.utils.listview :as lw] - [status-im.utils.logging :as log] [clojure.string :as str])) (defn- container-animation-logic [{:keys [to-value val]}] @@ -91,4 +90,4 @@ (lw/to-datasource)) :enableEmptySections true :renderRow (render-row @contacts) - :contentContainerStyle st/bottom-info-list-container}]]]))}))) \ No newline at end of file + :contentContainerStyle st/bottom-info-list-container}]]]))}))) diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 29fd2421ba..9cd76d1b6a 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -21,8 +21,6 @@ content-type-status content-type-command content-type-command-request]] - [status-im.utils.logging :as log] - [status-im.protocol.api :as api] [status-im.utils.identicon :refer [identicon]] [status-im.chat.utils :as cu])) @@ -263,14 +261,14 @@ (into [view] children))) (defn chat-message [{:keys [outgoing message-id chat-id user-statuses from]}] - (let [my-identity (api/my-identity) + (let [my-identity (subscribe [:get :current-public-key]) status (subscribe [:get-in [:message-user-statuses message-id my-identity]])] (r/create-class {:component-did-mount (fn [] (when (and (not outgoing) (not= :seen (keyword @status)) - (not= :seen (keyword (get-in user-statuses [my-identity :status])))) + (not= :seen (keyword (get-in user-statuses [@my-identity :status])))) (dispatch [:send-seen! {:chat-id chat-id :from from :message-id message-id}]))) diff --git a/src/status_im/components/carousel/carousel.cljs b/src/status_im/components/carousel/carousel.cljs index a8e13fcc0b..006a85e080 100644 --- a/src/status_im/components/carousel/carousel.cljs +++ b/src/status_im/components/carousel/carousel.cljs @@ -4,7 +4,7 @@ touchable-without-feedback text]] [status-im.components.carousel.styles :as st] - [status-im.utils.logging :as log] + [taoensso.timbre :as log] [status-im.components.react :as r])) diff --git a/src/status_im/components/status.cljs b/src/status_im/components/status.cljs index 3449b36bd5..d0a5e5418f 100644 --- a/src/status_im/components/status.cljs +++ b/src/status_im/components/status.cljs @@ -3,7 +3,7 @@ (:require [status-im.components.react :as r] [status-im.utils.types :as t] [re-frame.core :refer [dispatch]] - [status-im.utils.logging :as log])) + [taoensso.timbre :as log])) (def status-js (slurp "resources/status.js")) diff --git a/src/status_im/components/text_field/view.cljs b/src/status_im/components/text_field/view.cljs index 8b99815392..0c9ec83269 100644 --- a/src/status_im/components/text_field/view.cljs +++ b/src/status_im/components/text_field/view.cljs @@ -12,7 +12,7 @@ [status-im.components.text-field.styles :as st] [status-im.i18n :refer [label]] [status-im.components.animation :as anim] - [status-im.utils.logging :as log])) + [taoensso.timbre :as log])) (def config {:label-top 16 diff --git a/src/status_im/db.cljs b/src/status_im/db.cljs index 309a4f5aa9..cce344e978 100644 --- a/src/status_im/db.cljs +++ b/src/status_im/db.cljs @@ -39,7 +39,6 @@ :chat-ui-props {:show-actions? false :show-bottom-info? false} :selected-participants #{} - :signed-up false :view-id default-view :navigation-stack (list default-view) :current-tag nil @@ -50,7 +49,6 @@ :tabs-bar-value (anim/create-value 0)} :loading-allowed true}) -(def protocol-initialized-path [:protocol-initialized]) (defn chat-staged-commands-path [chat-id] [:chats chat-id :staged-commands]) (defn chat-command-path [chat-id] diff --git a/src/status_im/discovery/handlers.cljs b/src/status_im/discovery/handlers.cljs index ecba308a39..ebad874858 100644 --- a/src/status_im/discovery/handlers.cljs +++ b/src/status_im/discovery/handlers.cljs @@ -2,7 +2,6 @@ (:require [re-frame.core :refer [after dispatch enrich]] [status-im.utils.utils :refer [first-index]] [status-im.utils.handlers :refer [register-handler]] - [status-im.protocol.api :as api] [status-im.protocol.core :as protocol] [status-im.navigation.handlers :as nav] [status-im.discovery.model :as discoveries] diff --git a/src/status_im/discovery/model.cljs b/src/status_im/discovery/model.cljs index 16ba2cbb1e..6a09d9d5ca 100644 --- a/src/status_im/discovery/model.cljs +++ b/src/status_im/discovery/model.cljs @@ -1,8 +1,6 @@ (ns status-im.discovery.model - ;status-im.models.discoveries - (:require [status-im.utils.logging :as log] - [status-im.persistence.realm.core :as r] - [status-im.constants :as c])) + (:require [taoensso.timbre :as log] + [status-im.persistence.realm.core :as r])) (defn get-tag [tag] (log/debug "Getting tag: " tag) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 1a13a0bcf4..f18e08dd73 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -4,9 +4,7 @@ [schema.core :as s :include-macros true] [status-im.db :refer [app-db schema]] [status-im.persistence.realm.core :as realm] - [status-im.persistence.simple-kv-store :as kv] - [status-im.protocol.state.storage :as storage] - [status-im.utils.logging :as log] + [taoensso.timbre :as log] [status-im.utils.crypt :refer [gen-random-bytes]] [status-im.components.status :as status] [status-im.utils.handlers :refer [register-handler] :as u] @@ -23,24 +21,9 @@ status-im.qr-scanner.handlers status-im.accounts.handlers status-im.protocol.handlers - [status-im.utils.datetime :as time] status-im.transactions.handlers [status-im.utils.types :as t])) -;; -- Middleware ------------------------------------------------------------ -;; -;; See https://github.com/Day8/re-frame/wiki/Using-Handler-Middleware -;; -(defn check-and-throw - "throw an exception if db doesn't match the schema." - [a-schema db] - (if-let [problems (s/check a-schema db)] - (throw (js/Error. (str "schema check failed: " problems))))) - -(def validate-schema-mw - (after (partial check-and-throw schema))) - - ;; -- Common -------------------------------------------------------------- (defn set-el [db [_ k v]] @@ -66,9 +49,7 @@ (fn [db _] (assoc db :chats {} - :current-chat-id "console" - :signed-up (storage/get kv/kv-store :signed-up) - :password (storage/get kv/kv-store :password)))) + :current-chat-id "console"))) (register-handler :initialize-account (u/side-effect! diff --git a/src/status_im/handlers/content_suggestions.cljs b/src/status_im/handlers/content_suggestions.cljs deleted file mode 100644 index c3928b3303..0000000000 --- a/src/status_im/handlers/content_suggestions.cljs +++ /dev/null @@ -1,25 +0,0 @@ -(ns status-im.handlers.content-suggestions - (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] - [status-im.db :as db] - [status-im.utils.logging :as log] - [clojure.string :as s])) - -;; TODO stub data? -(def suggestions - {:phone [{:header "Phone number formats"} - {:value "89171111111" - :description "Number format 1"} - {:value "+79171111111" - :description "Number format 2"} - {:value "9171111111" - :description "Number format 3"}]}) - -(defn get-content-suggestions [command text] - (or (when command - (when-let [command-suggestions ((keyword (:name command)) suggestions)] - (filterv (fn [s] - (or (:header s) - (and (.startsWith (:value s) (or text "")) - (not= (:value s) text)))) - command-suggestions))) - [])) diff --git a/src/status_im/handlers/server.cljs b/src/status_im/handlers/server.cljs index 8c18d4437e..2eaee570fe 100644 --- a/src/status_im/handlers/server.cljs +++ b/src/status_im/handlers/server.cljs @@ -1,7 +1,7 @@ (ns status-im.handlers.server (:require [re-frame.core :refer [subscribe dispatch dispatch-sync]] [status-im.utils.utils :refer [on-error http-post]] - [status-im.utils.logging :as log])) + [taoensso.timbre :as log])) (defn sign-up [db phone-number handler] diff --git a/src/status_im/ios/core.cljs b/src/status_im/ios/core.cljs index 78b4bdd809..03b722179f 100644 --- a/src/status_im/ios/core.cljs +++ b/src/status_im/ios/core.cljs @@ -23,15 +23,14 @@ [status-im.profile.screen :refer [profile my-profile]] [status-im.profile.photo-capture.screen :refer [profile-photo-capture]] [status-im.utils.utils :refer [toast]] - [status-im.utils.encryption] status-im.persistence.realm.core - [status-im.utils.logging :as log])) + [taoensso.timbre :as log])) (defn orientation->keyword [o] (keyword (.toLowerCase o))) (defn app-root [] - (let [signed-up (subscribe [:get :signed-up]) + (let [signed-up (subscribe [:signed-up?]) _ (log/debug "signed up: " @signed-up) view-id (subscribe [:get :view-id]) account-id (subscribe [:get :current-account-id]) diff --git a/src/status_im/models/chats.cljs b/src/status_im/models/chats.cljs index 6e0155494f..50d059d929 100644 --- a/src/status_im/models/chats.cljs +++ b/src/status_im/models/chats.cljs @@ -4,7 +4,6 @@ [status-im.persistence.realm.core :as r] [status-im.utils.random :as random :refer [timestamp]] [clojure.string :refer [join blank?]] - [status-im.utils.logging :as log] [status-im.constants :refer [content-type-status]] [status-im.models.messages :refer [save-message]] [status-im.persistence.realm-queries :refer [include-query]])) diff --git a/src/status_im/models/contacts.cljs b/src/status_im/models/contacts.cljs index c67320b363..5c6c3bab85 100644 --- a/src/status_im/models/contacts.cljs +++ b/src/status_im/models/contacts.cljs @@ -2,8 +2,7 @@ (:require [status-im.persistence.realm.core :as r] [status-im.utils.identicon :refer [identicon]] [status-im.persistence.realm-queries :refer [include-query - exclude-query]] - [status-im.utils.logging :as log])) + exclude-query]])) (defn get-contacts [] (-> (r/get-all :account :contact) diff --git a/src/status_im/models/messages.cljs b/src/status_im/models/messages.cljs index 601c4af89d..c169ebce8a 100644 --- a/src/status_im/models/messages.cljs +++ b/src/status_im/models/messages.cljs @@ -3,7 +3,6 @@ [re-frame.core :refer [dispatch]] [cljs.reader :refer [read-string]] [status-im.utils.random :refer [timestamp]] - [status-im.utils.logging :as log] [clojure.string :refer [join split]] [clojure.walk :refer [stringify-keys keywordize-keys]] [status-im.constants :as c] diff --git a/src/status_im/models/pending_messages.cljs b/src/status_im/models/pending_messages.cljs index 874d6537d9..093df19a35 100644 --- a/src/status_im/models/pending_messages.cljs +++ b/src/status_im/models/pending_messages.cljs @@ -8,7 +8,6 @@ [status-im.constants :as c] [status-im.utils.types :refer [clj->json json->clj]] [status-im.commands.utils :refer [generate-hiccup]] - [status-im.utils.logging :as log] [cljs.reader :as reader] [clojure.string :as str])) diff --git a/src/status_im/models/protocol.cljs b/src/status_im/models/protocol.cljs deleted file mode 100644 index 9cd9797421..0000000000 --- a/src/status_im/models/protocol.cljs +++ /dev/null @@ -1,20 +0,0 @@ -(ns status-im.models.protocol - (:require [cljs.reader :refer [read-string]] - [status-im.protocol.state.storage :as s] - [status-im.utils.types :refer [to-edn-string]] - [re-frame.db :refer [app-db]] - [status-im.db :as db] - [status-im.persistence.simple-kv-store :as kv])) - -(defn set-initialized [db initialized?] - (assoc-in db db/protocol-initialized-path initialized?)) - -(defn update-identity [db {:keys [address] :as identity}] - (let [identity-string (to-edn-string identity)] - (s/put kv/kv-store :identity identity-string) - (assoc-in db [:accounts address] identity))) - -(defn stored-identity [db] - (let [identity (s/get kv/kv-store :identity)] - (when identity - (read-string identity)))) diff --git a/src/status_im/persistence/realm/core.cljs b/src/status_im/persistence/realm/core.cljs index 9e0b2bfca3..1dad90e75c 100644 --- a/src/status_im/persistence/realm/core.cljs +++ b/src/status_im/persistence/realm/core.cljs @@ -4,7 +4,7 @@ [status-im.utils.types :refer [to-string]] [status-im.utils.utils :as u] [status-im.utils.fs :as fs] - [status-im.utils.logging :as log] + [taoensso.timbre :as log] [status-im.persistence.realm.schemas :refer [base account]] [clojure.string :as str]) (:refer-clojure :exclude [exists?])) @@ -182,4 +182,4 @@ (js->clj :keywordize-keys true))) (defn get-one-by-field [schema schema-name field value] - (single-cljs (get-by-field schema schema-name field value))) \ No newline at end of file + (single-cljs (get-by-field schema schema-name field value))) diff --git a/src/status_im/persistence/realm/schemas.cljs b/src/status_im/persistence/realm/schemas.cljs index 47f084b18a..a0ee8eefc2 100644 --- a/src/status_im/persistence/realm/schemas.cljs +++ b/src/status_im/persistence/realm/schemas.cljs @@ -14,7 +14,9 @@ :email {:type "string" :optional true} :status {:type "string" :optional true} :photo-path "string" - :last-updated {:type "int" :default 0}}} + :last-updated {:type "int" :default 0} + :signed-up? {:type :bool + :default false}}} {:name :kv-store :primaryKey :key :properties {:key "string" diff --git a/src/status_im/persistence/simple_kv_store.cljs b/src/status_im/persistence/simple_kv_store.cljs deleted file mode 100644 index 01ef851565..0000000000 --- a/src/status_im/persistence/simple_kv_store.cljs +++ /dev/null @@ -1,29 +0,0 @@ -(ns status-im.persistence.simple-kv-store - (:require [status-im.protocol.state.storage :as st] - [status-im.persistence.realm.core :as r] - [status-im.utils.types :refer [to-edn-string]])) - -(defrecord SimpleKvStore [schema] - st/Storage - (put [_ key value] - (r/write schema - (fn [] - (r/create schema :kv-store - {:key key - :value (to-edn-string value)} true)))) - (get [_ key] - (some-> (r/get-by-field schema :kv-store :key key) - (r/single-cljs) - (r/decode-value))) - (contains-key? [_ key] - (r/exists? schema :kv-store {:key key})) - (delete [_ key] - (r/write schema - (fn [] - (->> (r/get-by-field schema :kv-store :key key) - (r/single) - (r/delete schema)))))) - -(def kv-store (->SimpleKvStore :account)) - -(def base-kv-store (->SimpleKvStore :base)) diff --git a/src/status_im/protocol/handlers.cljs b/src/status_im/protocol/handlers.cljs index ebb7fde5e0..bc4891ebdf 100644 --- a/src/status_im/protocol/handlers.cljs +++ b/src/status_im/protocol/handlers.cljs @@ -1,21 +1,16 @@ -; todo everything inside this namespace must be revievew in common with future -; changes in protocol lib (ns status-im.protocol.handlers (:require [status-im.utils.handlers :as u] - [status-im.utils.logging :as log] [re-frame.core :refer [dispatch after]] [status-im.utils.handlers :refer [register-handler]] [status-im.models.contacts :as contacts] [status-im.models.messages :as messages] [status-im.models.pending-messages :as pending-messages] [status-im.models.chats :as chats] - [status-im.models.protocol :refer [update-identity - set-initialized]] [status-im.protocol.core :as protocol] [status-im.constants :refer [text-content-type]] [status-im.i18n :refer [label]] [status-im.utils.random :as random] - [taoensso.timbre :refer-macros [debug]])) + [taoensso.timbre :as log :refer-macros [debug]])) (register-handler :initialize-protocol (fn [db [_ current-account-id]] @@ -73,12 +68,6 @@ (dispatch [:message-sent message'])) (debug "Unknown message type" type))))) -(register-handler :protocol-initialized - (fn [db [_ identity]] - (-> db - (update-identity identity) - (set-initialized true)))) - (defn system-message [message-id content] {:from "system" :message-id message-id diff --git a/src/status_im/protocol/protocol_handler.cljs b/src/status_im/protocol/protocol_handler.cljs deleted file mode 100644 index 319b0c719b..0000000000 --- a/src/status_im/protocol/protocol_handler.cljs +++ /dev/null @@ -1,7 +0,0 @@ -(ns status-im.protocol.protocol-handler - (:require [status-im.utils.logging :as log] - [status-im.constants :refer [ethereum-rpc-url]] - [re-frame.core :refer [dispatch]] - [status-im.models.protocol :refer [stored-identity]] - [status-im.persistence.simple-kv-store :as kv] - [status-im.models.chats :refer [active-group-chats]])) diff --git a/src/status_im/protocol/web3/delivery.cljs b/src/status_im/protocol/web3/delivery.cljs index 1cf3fd1fd5..25d33faeee 100644 --- a/src/status_im/protocol/web3/delivery.cljs +++ b/src/status_im/protocol/web3/delivery.cljs @@ -5,7 +5,7 @@ [status-im.protocol.web3.utils :as u] [status-im.protocol.encryption :as e] [cljs.spec :as s] - [taoensso.timbre :refer-macros [debug] :as timbre] + [taoensso.timbre :refer-macros [debug] :as log] [status-im.protocol.validation :refer-macros [valid?]] [clojure.set :as set])) @@ -107,7 +107,7 @@ (defn delivery-callback [web3 {:keys [id requires-ack? to]}] (fn [error _] - (when error (timbre/error :shh-post-error error)) + (when error (log/error :shh-post-error error)) (when-not error (debug :delivery-callback) (message-was-sent! web3 id to) @@ -173,7 +173,7 @@ callback (delivery-callback web3 data)] (t/post-message! web3 message' callback)) (catch :default err - (timbre/error :post-message-error err)) + (log/error :post-message-error err)) (finally (attempt-was-made! web3 id to))))))) (when-not @stop? diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index 5f4a8edd39..ff330656e0 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -1,6 +1,6 @@ (ns status-im.subs (:require-macros [reagent.ratom :refer [reaction]]) - (:require [re-frame.core :refer [register-sub]] + (:require [re-frame.core :refer [register-sub subscribe]] status-im.chat.subs status-im.group-settings.subs status-im.discovery.subs @@ -25,3 +25,10 @@ (register-sub :animations (fn [db [_ k]] (reaction (get-in @db [:animations k])))) + +(register-sub :signed-up? + (fn [] + (let [account-id (subscribe [:get :current-account-id]) + accounts (subscribe [:get :accounts])] + (reaction (when (and @accounts @account-id) + (get-in @accounts [@account-id :signed-up?])))))) diff --git a/src/status_im/utils/random.cljs b/src/status_im/utils/random.cljs new file mode 100644 index 0000000000..367998cf20 --- /dev/null +++ b/src/status_im/utils/random.cljs @@ -0,0 +1,8 @@ +(ns status-im.utils.random + (:require [cljsjs.chance])) + +(defn timestamp [] + (.getTime (js/Date.))) + +(defn id [] + (str (timestamp) "-" (.guid js/chance)))