From 72df44da6cebfa411c9f78dfb3d522b6211fc20a Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Mon, 17 May 2021 11:10:08 +0300 Subject: [PATCH] allow creation of recovery cards from logged-out state Signed-off-by: Michele Balistreri --- src/status_im/keycard/backup_key.cljs | 24 +++++++++++++++++-- src/status_im/keycard/recovery.cljs | 18 +++++++++++++- .../multiaccounts/key_storage/core.cljs | 2 +- src/status_im/ui/screens/keycard/views.cljs | 8 +++++++ translations/en.json | 3 +++ 5 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/status_im/keycard/backup_key.cljs b/src/status_im/keycard/backup_key.cljs index 233976e41a..cd27e1e616 100644 --- a/src/status_im/keycard/backup_key.cljs +++ b/src/status_im/keycard/backup_key.cljs @@ -1,10 +1,26 @@ (ns status-im.keycard.backup-key (:require [status-im.utils.fx :as fx] + [re-frame.core :as re-frame] + [status-im.utils.utils :as utils] + [status-im.i18n.i18n :as i18n] [status-im.ethereum.mnemonic :as mnemonic] + [status-im.multiaccounts.model :as multiaccounts.model] [status-im.multiaccounts.recover.core :as multiaccounts.recover] [status-im.navigation :as navigation] [taoensso.timbre :as log])) +(fx/defn recovery-card-pressed + {:events [:keycard-settings.ui/recovery-card-pressed]} + [{:keys [db] :as cofx} checked?] + (fx/merge cofx + {:db (assoc-in db [:keycard :factory-reset-card?] true)} + (utils/show-confirmation {:title (i18n/label :t/keycard-recover-title) + :content (i18n/label :t/keycard-recover-text) + :confirm-button-text (i18n/label :t/yes) + :cancel-button-text (i18n/label :t/no) + :on-accept #(re-frame/dispatch [:keycard-settings.ui/backup-card-pressed]) + :on-cancel #()}))) + (fx/defn backup-card-pressed {:events [:keycard-settings.ui/backup-card-pressed]} [{:keys [db] :as cofx}] @@ -12,7 +28,9 @@ (fx/merge cofx {:db (-> db (assoc-in [:keycard :creating-backup?] true))} - (navigation/navigate-to-cofx :seed-phrase nil))) + (if (multiaccounts.model/logged-in? cofx) + (navigation/navigate-to-cofx :seed-phrase nil) + (navigation/navigate-to-cofx :key-storage-stack {:screen :seed-phrase})))) (fx/defn start-keycard-backup {:events [::start-keycard-backup]} @@ -37,4 +55,6 @@ (assoc-in [:keycard :flow] :recovery) (update :multiaccounts/key-storage dissoc :seed-phrase)) :dismiss-keyboard nil} - (navigation/navigate-to-cofx :keycard-onboarding-intro nil))) \ No newline at end of file + (if (multiaccounts.model/logged-in? cofx) + (navigation/navigate-to-cofx :keycard-onboarding-intro nil) + (navigation/navigate-to-cofx :intro-stack {:screen :keycard-onboarding-intro})))) diff --git a/src/status_im/keycard/recovery.cljs b/src/status_im/keycard/recovery.cljs index fed743e5bb..9db512bb33 100644 --- a/src/status_im/keycard/recovery.cljs +++ b/src/status_im/keycard/recovery.cljs @@ -2,6 +2,7 @@ (:require [status-im.navigation :as navigation] [status-im.utils.datetime :as utils.datetime] [status-im.multiaccounts.create.core :as multiaccounts.create] + [status-im.multiaccounts.model :as multiaccounts.model] [status-im.utils.fx :as fx] [re-frame.core :as re-frame] [status-im.i18n.i18n :as i18n] @@ -197,12 +198,27 @@ (navigation/navigate-to-cofx (if platform/android? :notifications-settings :welcome) nil)))))) +(fx/defn return-to-keycard-login + [{:keys [db] :as cofx}] + (fx/merge cofx + {:db (-> db + (update-in [:keycard :pin] assoc :enter-step :login + :status nil + :login []) + (update :keycard dissoc :application-info))} + (navigation/navigate-reset {:index 0 + :routes [{:name :intro-stack + :state {:routes [{:name :multiaccounts}, + {:name :keycard-login-pin}]}}]}))) + (fx/defn on-backup-success [{:keys [db] :as cofx}] (fx/merge cofx {:utils/show-popup {:title (i18n/label :t/keycard-backup-success-title) :content (i18n/label :t/keycard-backup-success-body)}} - (navigation/navigate-to-cofx :keycard-settings nil))) + (if (multiaccounts.model/logged-in? cofx) + (navigation/navigate-to-cofx :keycard-settings nil) + (return-to-keycard-login)))) (fx/defn on-generate-and-load-key-success {:events [:keycard.callback/on-generate-and-load-key-success] diff --git a/src/status_im/multiaccounts/key_storage/core.cljs b/src/status_im/multiaccounts/key_storage/core.cljs index 6eedc316aa..d210501d28 100644 --- a/src/status_im/multiaccounts/key_storage/core.cljs +++ b/src/status_im/multiaccounts/key_storage/core.cljs @@ -36,7 +36,7 @@ cofx {:db (-> db (dissoc :recovered-account?) - (update :keycard dissoc :from-key-storage-and-migration? :creating-backup?))} + (update :keycard dissoc :from-key-storage-and-migration? :creating-backup? :factory-reset-card?))} (navigation/navigate-back))) (fx/defn enter-seed-pressed diff --git a/src/status_im/ui/screens/keycard/views.cljs b/src/status_im/ui/screens/keycard/views.cljs index 5e128df436..beb6b67aaa 100644 --- a/src/status_im/ui/screens/keycard/views.cljs +++ b/src/status_im/ui/screens/keycard/views.cljs @@ -320,6 +320,14 @@ :number-of-lines 1 :ellipsize-mode :middle} name]]] + [react/touchable-highlight {:on-press #(re-frame/dispatch [:keycard-settings.ui/recovery-card-pressed])} + [react/view {:flex-direction :row + :align-items :center + :justify-content :center} + [react/text {:style {:text-align :center + :margin-bottom (if small-screen? 8 12) + :color colors/blue}} + (i18n/label :t/keycard-recover)]]] (cond (= :after-unblocking status) [access-is-reset diff --git a/translations/en.json b/translations/en.json index 07b30e2993..83604d1c17 100644 --- a/translations/en.json +++ b/translations/en.json @@ -1229,6 +1229,9 @@ "keycard-error-description": "Connect the card again to continue", "keycard-success-title": "Success", "keycard-success-description": "You may remove the card now", + "keycard-recover": "lost or frozen card?", + "keycard-recover-title": "Create a new card for this account?", + "keycard-recover-text": "If you have your mnemonic phrase you can create a new Keycard associated with this account. You can use either a new Keycard or perform factory reset on a frozen one.", "keycard-backup": "Create a backup Keycard", "keycard-backup-success-title": "Backup successful", "keycard-backup-success-body": "Backup card created successfully. You can now use it with your account just like the primary card.",