From 9759add62a54bb2c5199805bc89af08cb3e93d8e Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Thu, 29 Jul 2021 15:29:52 +0200 Subject: [PATCH] trigger migration to Keycard from logged in state Signed-off-by: Michele Balistreri --- src/status_im/init/core.cljs | 3 ++- .../multiaccounts/key_storage/core.cljs | 18 ++++++++++++++++++ src/status_im/multiaccounts/login/core.cljs | 9 ++++++--- .../privacy_and_security_settings/views.cljs | 7 +++++++ translations/en.json | 1 + 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/status_im/init/core.cljs b/src/status_im/init/core.cljs index 76aefe82e4..b94c9473ad 100644 --- a/src/status_im/init/core.cljs +++ b/src/status_im/init/core.cljs @@ -14,7 +14,7 @@ (fx/defn initialize-app-db "Initialize db to initial state" - [{{:keys [keycard supported-biometric-auth app-active-since] + [{{:keys [keycard supported-biometric-auth app-active-since goto-key-storage?] :network/keys [type] :keycard/keys [banner-hidden]} :db now :now}] {:db (assoc app-db @@ -23,6 +23,7 @@ :keycard (dissoc keycard :secrets) :supported-biometric-auth supported-biometric-auth :app-active-since (or app-active-since now) + :goto-key-storage? goto-key-storage? :multiaccounts/loading true)}) (fx/defn initialize-views diff --git a/src/status_im/multiaccounts/key_storage/core.cljs b/src/status_im/multiaccounts/key_storage/core.cljs index d4a42424ea..3b43db81fd 100644 --- a/src/status_im/multiaccounts/key_storage/core.cljs +++ b/src/status_im/multiaccounts/key_storage/core.cljs @@ -5,6 +5,7 @@ [status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.recover.core :as multiaccounts.recover] [status-im.multiaccounts.model :as multiaccounts.model] + [status-im.multiaccounts.logout.core :as multiaccounts.logout] [status-im.native-module.core :as native-module] [status-im.navigation :as navigation] [status-im.popover.core :as popover] @@ -240,6 +241,23 @@ We don't need to take the exact steps, just set the required state and redirect (popover/hide-popover) (navigation/navigate-to-cofx :multiaccounts nil))) +(fx/defn confirm-logout-and-goto-key-storage + {:events [::confirm-logout-and-goto-key-storage]} + [{:keys [db] :as cofx}] + (fx/merge cofx + {:db (assoc db :goto-key-storage? true)} + (multiaccounts.logout/logout))) + +(fx/defn logout-and-goto-key-storage + {:events [::logout-and-goto-key-storage]} + [_] + {:ui/show-confirmation + {:title (i18n/label :t/logout-title) + :content (i18n/label :t/logout-key-management) + :confirm-button-text (i18n/label :t/logout) + :on-accept #(re-frame/dispatch [::confirm-logout-and-goto-key-storage]) + :on-cancel nil}}) + (comment ;; check import mnemonic output (native-module/multiaccount-import-mnemonic "rocket mixed rebel affair umbrella legal resemble scene virus park deposit cargo" nil diff --git a/src/status_im/multiaccounts/login/core.cljs b/src/status_im/multiaccounts/login/core.cljs index f712f3731e..74c23ac1b4 100644 --- a/src/status_im/multiaccounts/login/core.cljs +++ b/src/status_im/multiaccounts/login/core.cljs @@ -465,7 +465,8 @@ (let [key-uid (get-in db [:multiaccounts/login :key-uid]) keycard-account? (boolean (get-in db [:multiaccounts/multiaccounts key-uid - :keycard-pairing]))] + :keycard-pairing])) + goto-key-storage? (:goto-key-storage? db)] (if password (fx/merge cofx @@ -476,14 +477,16 @@ login) (fx/merge cofx + {:db (dissoc db :goto-key-storage?)} (when keycard-account? {:db (-> db - (assoc-in [:keycard :pin :enter-step] :login) (assoc-in [:keycard :pin :status] nil) (assoc-in [:keycard :pin :login] []))}) #(if keycard-account? {:init-root-with-component-fx [:multiaccounts-keycard :multiaccounts]} - {:init-root-fx :multiaccounts}))))) + {:init-root-fx :multiaccounts}) + #(when goto-key-storage? + (navigation/navigate-to-cofx % :actions-not-logged-in nil)))))) (fx/defn get-credentials [{:keys [db] :as cofx} key-uid] diff --git a/src/status_im/ui/screens/privacy_and_security_settings/views.cljs b/src/status_im/ui/screens/privacy_and_security_settings/views.cljs index 4b857436e3..1c84e83859 100644 --- a/src/status_im/ui/screens/privacy_and_security_settings/views.cljs +++ b/src/status_im/ui/screens/privacy_and_security_settings/views.cljs @@ -3,6 +3,7 @@ [status-im.i18n.i18n :as i18n] [quo.core :as quo] [status-im.multiaccounts.reset-password.core :as reset-password] + [status-im.multiaccounts.key-storage.core :as key-storage] [status-im.ui.components.common.common :as components.common] [status-im.ui.components.react :as react] [status-im.utils.config :as config] @@ -95,6 +96,12 @@ :on-press #(re-frame/dispatch [:multiaccounts.ui/webview-permission-requests-switched ((complement boolean) webview-allow-permission-requests?)])}]) + (when (not keycard?) + [quo/list-item {:size :small + :title (i18n/label :t/manage-keys-and-storage) + :chevron true + :on-press #(re-frame/dispatch [::key-storage/logout-and-goto-key-storage]) + :accessibility-label :key-managment}]) [separator] [quo/list-item {:size :small diff --git a/translations/en.json b/translations/en.json index a35bff8a98..81e764a996 100644 --- a/translations/en.json +++ b/translations/en.json @@ -796,6 +796,7 @@ "logout-app-content": "The account will be logged out. When you unlock it again, the selected network will be used", "logout-are-you-sure": "Are you sure you want\nto log out?", "logout-title": "Log out?", + "logout-key-management": "You need to log out to access key management.", "looking-for-cards": "Looking for cards...", "lost-connection": "Lost connection", "mailserver-address": "Status node address",