diff --git a/src/status_im/accounts/handlers.cljs b/src/status_im/accounts/handlers.cljs index 40330e5c48..6421cefc20 100644 --- a/src/status_im/accounts/handlers.cljs +++ b/src/status_im/accounts/handlers.cljs @@ -58,6 +58,7 @@ (register-handler :create-account (u/side-effect! (fn [_ [_ password]] + (dispatch [:set :creating-account? true]) (s/execute-later #(dispatch [:account-generation-message]) 400) (status/create-account password diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index d5876e0bca..9fc2105c4f 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -41,10 +41,15 @@ ;; todo: it might be better always return false from ;; this listener and handle application's closing ;; in handlers - (let [stack (subscribe [:get :navigation-stack])] - (when (< 1 (count @stack)) - (dispatch [:navigate-back]) - true)))] + (let [stack (subscribe [:get :navigation-stack]) + creating? (subscribe [:get :creating-account?])] + (cond + @creating? true + + (< 1 (count @stack)) + (do (dispatch [:navigate-back]) true) + + :else false)))] (.addEventListener back-android "hardwareBackPress" new-listener))) (defn orientation->keyword [o] diff --git a/src/status_im/chat/constants.cljs b/src/status_im/chat/constants.cljs index 73b1327401..e1776682c7 100644 --- a/src/status_im/chat/constants.cljs +++ b/src/status_im/chat/constants.cljs @@ -16,3 +16,8 @@ (+ input-height suggestions-header-height)) (def emoji-container-height 250) + +(def crazy-math-message-id "crazy-math-message") +(def passphrase-message-id "passphraze-message") +(def intro-status-message-id "intro-status") +(def intro-message1-id "intro-message1") \ No newline at end of file diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index 04a3e7542b..53bd6e3def 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -254,13 +254,13 @@ (register-handler :account-generation-message (u/side-effect! (fn [_] - (when-not (messages/get-by-id sign-up-service/passphraze-message-id) + (when-not (messages/get-by-id chat-consts/passphrase-message-id) (sign-up-service/account-generation-message))))) (register-handler :show-mnemonic (u/side-effect! (fn [_ [_ mnemonic]] - (let [crazy-math-message? (messages/get-by-id sign-up-service/crazy-math-message)] + (let [crazy-math-message? (messages/get-by-id chat-consts/crazy-math-message-id)] (sign-up-service/passphrase-messages mnemonic crazy-math-message?))))) (register-handler :sign-up diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index e9769c54ae..05abe10e54 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -28,10 +28,12 @@ [status-im.chat.views.bottom-info :refer [bottom-info-view]] [status-im.chat.views.toolbar-content :refer [toolbar-content-view]] [status-im.chat.views.suggestions :refer [suggestion-container]] + [status-im.chat.constants :as const] [status-im.i18n :refer [label label-pluralize]] [status-im.components.animation :as anim] [status-im.components.sync-state.offline :refer [offline-view]] - [status-im.constants :refer [content-type-status]])) + [status-im.constants :refer [content-type-status]] + [taoensso.timbre :as log])) (defn contacts-by-identity [contacts] (->> contacts @@ -109,10 +111,11 @@ (defview chat-toolbar [] [show-actions? [:chat-ui-props :show-actions?] - accounts [:get :accounts]] + accounts [:get :accounts] + creating? [:get :creating-account?]] [view [status-bar] - [toolbar {:hide-nav? (or (empty? accounts) show-actions?) + [toolbar {:hide-nav? (or (empty? accounts) show-actions? creating?) :custom-content [toolbar-content-view] :custom-action [toolbar-action] :style (get-in platform-specific [:component-styles :toolbar])}] @@ -121,7 +124,7 @@ (defn get-intro-status-message [all-messages] (let [{:keys [timestamp content-type]} (last all-messages)] (when (not= content-type content-type-status) - {:message-id "intro-status" + {:message-id const/intro-status-message-id :content-type content-type-status :timestamp (or timestamp (time/now-ms))}))) @@ -170,11 +173,11 @@ (anim/start (anim/spring val {:toValue @offset})))) (defview messages-container [messages] - [offset [:messages-offset] - messages-offset (anim/create-value 0) - context {:offset offset - :val messages-offset} - on-update (messages-container-animation-logic context)] + [offset [:messages-offset] + messages-offset (anim/create-value 0) + context {:offset offset + :val messages-offset} + on-update (messages-container-animation-logic context)] {:component-did-mount on-update :component-did-update on-update} [animated-view @@ -182,13 +185,13 @@ messages]) (defview chat [] - [group-chat [:chat :group-chat] - show-actions? [:chat-ui-props :show-actions?] + [group-chat [:chat :group-chat] + show-actions? [:chat-ui-props :show-actions?] show-bottom-info? [:chat-ui-props :show-bottom-info?] - show-emoji? [:chat-ui-props :show-emoji?] - command? [:command?] - layout-height [:get :layout-height]] - {:component-did-mount #(dispatch [:check-autorun]) + show-emoji? [:chat-ui-props :show-emoji?] + command? [:command?] + layout-height [:get :layout-height]] + {:component-did-mount #(dispatch [:check-autorun]) :component-will-unmount #(dispatch [:set-chat-ui-props :show-emoji? false])} [view {:style st/chat-view :onLayout (fn [event] diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index 6045934545..dca4c6f8e2 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -10,6 +10,7 @@ content-type-command content-type-command-request content-type-status]] + [status-im.chat.constants :as const] [status-im.i18n :refer [label]] [clojure.string :as s])) @@ -110,11 +111,10 @@ :from console-chat-id :to "me"}])) -(def crazy-math-message "crazy-math-message") ;; -- Saving password ---------------------------------------- (defn account-generation-message [] (dispatch [:received-message - {:message-id crazy-math-message + {:message-id const/crazy-math-message-id :content (label :t/account-generation-message) :content-type text-content-type :outgoing false @@ -122,11 +122,9 @@ :from console-chat-id :to "me"}])) -(def passphraze-message-id "passphraze-message") - (defn passphrase-messages [mnemonic crazy-math-message?] (dispatch [:received-message - {:message-id passphraze-message-id + {:message-id const/passphrase-message-id :content (if crazy-math-message? (label :t/phew-here-is-your-passphrase) (label :t/here-is-your-passphrase)) @@ -146,7 +144,7 @@ (start-signup)) (def intro-status - {:message-id "intro-status" + {:message-id const/intro-status-message-id :content (label :t/intro-status) :from console-chat-id :chat-id console-chat-id @@ -159,7 +157,7 @@ (dispatch [:received-message-when-commands-loaded console-chat-id {:chat-id console-chat-id - :message-id "intro-message1" + :message-id const/intro-message1-id :content (command-content :password (label :t/intro-message1)) diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs index 310f2e3707..e9176c6838 100644 --- a/src/status_im/chat/subs.cljs +++ b/src/status_im/chat/subs.cljs @@ -7,8 +7,10 @@ [status-im.chat.constants :as c] [status-im.chat.views.plain-message :as plain-message] [status-im.chat.views.command :as command] - [status-im.constants :refer [content-type-status]] - [status-im.utils.platform :refer [platform-specific ios?]])) + [status-im.constants :refer [content-type-status + console-chat-id]] + [status-im.utils.platform :refer [platform-specific ios?]] + [taoensso.timbre :as log])) (register-sub :chat-properties (fn [db [_ properties]] diff --git a/src/status_im/chat/views/toolbar_content.cljs b/src/status_im/chat/views/toolbar_content.cljs index 9e333c6784..999f896d79 100644 --- a/src/status_im/chat/views/toolbar_content.cljs +++ b/src/status_im/chat/views/toolbar_content.cljs @@ -55,7 +55,7 @@ [last-activity {:sync-state sync-state}] (if public? [view {:flex-direction :row} - [text {:font :default + [text {:font :default :style (get-in platform-specific [:component-styles :toolbar-last-activity])} (label :t/public-group-status)]] [view {:flex-direction :row} @@ -77,10 +77,12 @@ show-actions? (subscribe [:chat-ui-props :show-actions?]) accounts (subscribe [:get :accounts]) contact (subscribe [:get-in [:contacts @chat-id]]) - sync-state (subscribe [:get :sync-state])] + sync-state (subscribe [:get :sync-state]) + creating? (subscribe [:get :creating-account?])] (fn [] [view (st/chat-name-view (or (empty? @accounts) - @show-actions?)) + @show-actions? + @creating?)) (let [chat-name (if (str/blank? @name) (generate-gfy) (or (get-contact-translated @chat-id :name @name) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 4017d009b5..7378d69b35 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -80,7 +80,8 @@ (dispatch [:init-debug-mode address]) (dispatch [:send-account-update-if-needed]) (dispatch [:start-requesting-discoveries]) - (dispatch [:remove-old-discoveries!])))) + (dispatch [:remove-old-discoveries!]) + (dispatch [:set :creating-account? false])))) (register-handler :reset-app (u/side-effect! diff --git a/src/status_im/navigation/handlers.cljs b/src/status_im/navigation/handlers.cljs index 1c44c09f1b..c342202a76 100644 --- a/src/status_im/navigation/handlers.cljs +++ b/src/status_im/navigation/handlers.cljs @@ -1,6 +1,7 @@ (ns status-im.navigation.handlers - (:require [re-frame.core :refer [dispatch debug enrich after]] - [status-im.utils.handlers :refer [register-handler]])) + (:require [re-frame.core :refer [dispatch subscribe debug enrich after]] + [status-im.utils.handlers :refer [register-handler]] + [status-im.constants :refer [console-chat-id]])) (defn push-view [db view-id] (-> db @@ -50,6 +51,11 @@ (fn [db [_ view-id]] (replace-view db view-id))) +(defn- can-navigate-back? [db] + (and (not (db :creating-account?)) + ;; ... + )) + (register-handler :navigate-back (enrich -preload-data!) (fn [{:keys [navigation-stack view-id modal] :as db} _] @@ -59,13 +65,15 @@ (>= 1 (count navigation-stack)) db :else - (let [[previous-view-id :as navigation-stack'] (pop navigation-stack) - first-in-stack (first navigation-stack)] - (if (= view-id first-in-stack) - (-> db - (assoc :view-id previous-view-id) - (assoc :navigation-stack navigation-stack')) - (assoc db :view-id first-in-stack)))))) + (if (can-navigate-back? db) + (let [[previous-view-id :as navigation-stack'] (pop navigation-stack) + first-in-stack (first navigation-stack)] + (if (= view-id first-in-stack) + (-> db + (assoc :view-id previous-view-id) + (assoc :navigation-stack navigation-stack')) + (assoc db :view-id first-in-stack))) + db)))) (register-handler :navigate-to-tab (enrich preload-data!)