allow creation of recovery cards from logged-out state

Signed-off-by: Michele Balistreri <michele@bitgamma.com>
This commit is contained in:
Michele Balistreri 2021-05-17 11:10:08 +03:00
parent 273b0064e2
commit 72df44da6c
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
5 changed files with 51 additions and 4 deletions

View File

@ -1,10 +1,26 @@
(ns status-im.keycard.backup-key (ns status-im.keycard.backup-key
(:require [status-im.utils.fx :as fx] (: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.ethereum.mnemonic :as mnemonic]
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.multiaccounts.recover.core :as multiaccounts.recover] [status-im.multiaccounts.recover.core :as multiaccounts.recover]
[status-im.navigation :as navigation] [status-im.navigation :as navigation]
[taoensso.timbre :as log])) [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 (fx/defn backup-card-pressed
{:events [:keycard-settings.ui/backup-card-pressed]} {:events [:keycard-settings.ui/backup-card-pressed]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
@ -12,7 +28,9 @@
(fx/merge cofx (fx/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :creating-backup?] true))} (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 (fx/defn start-keycard-backup
{:events [::start-keycard-backup]} {:events [::start-keycard-backup]}
@ -37,4 +55,6 @@
(assoc-in [:keycard :flow] :recovery) (assoc-in [:keycard :flow] :recovery)
(update :multiaccounts/key-storage dissoc :seed-phrase)) (update :multiaccounts/key-storage dissoc :seed-phrase))
:dismiss-keyboard nil} :dismiss-keyboard nil}
(navigation/navigate-to-cofx :keycard-onboarding-intro nil))) (if (multiaccounts.model/logged-in? cofx)
(navigation/navigate-to-cofx :keycard-onboarding-intro nil)
(navigation/navigate-to-cofx :intro-stack {:screen :keycard-onboarding-intro}))))

View File

@ -2,6 +2,7 @@
(:require [status-im.navigation :as navigation] (:require [status-im.navigation :as navigation]
[status-im.utils.datetime :as utils.datetime] [status-im.utils.datetime :as utils.datetime]
[status-im.multiaccounts.create.core :as multiaccounts.create] [status-im.multiaccounts.create.core :as multiaccounts.create]
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.utils.fx :as fx] [status-im.utils.fx :as fx]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
@ -197,12 +198,27 @@
(navigation/navigate-to-cofx (if platform/android? (navigation/navigate-to-cofx (if platform/android?
:notifications-settings :welcome) nil)))))) :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 (fx/defn on-backup-success
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
(fx/merge cofx (fx/merge cofx
{:utils/show-popup {:title (i18n/label :t/keycard-backup-success-title) {:utils/show-popup {:title (i18n/label :t/keycard-backup-success-title)
:content (i18n/label :t/keycard-backup-success-body)}} :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 (fx/defn on-generate-and-load-key-success
{:events [:keycard.callback/on-generate-and-load-key-success] {:events [:keycard.callback/on-generate-and-load-key-success]

View File

@ -36,7 +36,7 @@
cofx cofx
{:db (-> db {:db (-> db
(dissoc :recovered-account?) (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))) (navigation/navigate-back)))
(fx/defn enter-seed-pressed (fx/defn enter-seed-pressed

View File

@ -320,6 +320,14 @@
:number-of-lines 1 :number-of-lines 1
:ellipsize-mode :middle} :ellipsize-mode :middle}
name]]] 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 (cond
(= :after-unblocking status) (= :after-unblocking status)
[access-is-reset [access-is-reset

View File

@ -1229,6 +1229,9 @@
"keycard-error-description": "Connect the card again to continue", "keycard-error-description": "Connect the card again to continue",
"keycard-success-title": "Success", "keycard-success-title": "Success",
"keycard-success-description": "You may remove the card now", "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": "Create a backup Keycard",
"keycard-backup-success-title": "Backup successful", "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.", "keycard-backup-success-body": "Backup card created successfully. You can now use it with your account just like the primary card.",