add reset with mnemonic on frozen/blocked cards

Signed-off-by: Michele Balistreri <michele@bitgamma.com>
This commit is contained in:
Michele Balistreri 2021-05-20 11:13:04 +03:00
parent a71468f425
commit 4217f558a8
No known key found for this signature in database
GPG Key ID: E9567DA33A4F791A
6 changed files with 46 additions and 30 deletions

View File

@ -7,31 +7,39 @@
[status-im.multiaccounts.model :as multiaccounts.model] [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]
[status-im.signing.core :as signing.core]
[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} backup-type]
(log/debug "[keycard] start backup") (log/debug "[keycard] start backup")
(fx/merge cofx (fx/merge cofx
{:db (-> db {:db (-> db
(assoc-in [:keycard :creating-backup?] true))} (assoc-in [:keycard :creating-backup?] backup-type))}
(if (multiaccounts.model/logged-in? cofx) (if (multiaccounts.model/logged-in? cofx)
(navigation/navigate-to-cofx :seed-phrase nil) (navigation/navigate-to-cofx :seed-phrase nil)
(navigation/navigate-to-cofx :key-storage-stack {:screen :seed-phrase})))) (navigation/navigate-to-cofx :key-storage-stack {:screen :seed-phrase}))))
(fx/defn recovery-card-pressed
{:events [:keycard-settings.ui/recovery-card-pressed]}
[{:keys [db] :as cofx} show-warning]
(fx/merge cofx
{:db (-> db
;setting pin-retry-counter is a workaround for the way the PIN view decides if it should accept PUK or PIN
(assoc-in [:keycard :application-info :pin-retry-counter] 3)
(assoc-in [:keycard :factory-reset-card?] true)
(dissoc :popover/popover))}
(signing.core/discard)
(if show-warning
(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 :recovery-card])
:on-cancel #()})
(backup-card-pressed :recovery-card))))
(fx/defn start-keycard-backup (fx/defn start-keycard-backup
{:events [::start-keycard-backup]} {:events [::start-keycard-backup]}
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]

View File

@ -209,12 +209,14 @@
{:name :keycard-login-pin}]}}]}))) {:name :keycard-login-pin}]}}]})))
(fx/defn on-backup-success (fx/defn on-backup-success
[{:keys [db] :as cofx}] [{:keys [db] :as cofx} backup-type]
(fx/merge cofx (fx/merge cofx
{:utils/show-popup {:title (i18n/label :t/keycard-backup-success-title) {:utils/show-popup {:title (i18n/label (if (= backup-type :recovery-card)
:content (i18n/label :t/keycard-backup-success-body)}} :t/keycard-access-reset :t/keycard-backup-success-title))
:content (i18n/label (if (= backup-type :recovery-card)
:t/keycard-can-use-with-new-passcode :t/keycard-backup-success-body))}}
(if (multiaccounts.model/logged-in? cofx) (if (multiaccounts.model/logged-in? cofx)
(navigation/navigate-to-cofx :keycard-settings nil) (navigation/navigate-to-cofx :profile-stack {:screen :keycard-settings})
(return-to-keycard-login)))) (return-to-keycard-login))))
(fx/defn on-generate-and-load-key-success (fx/defn on-generate-and-load-key-success
@ -249,7 +251,7 @@
(update-in [:keycard :secrets] dissoc :mnemonic))} (update-in [:keycard :secrets] dissoc :mnemonic))}
(common/remove-listener-to-hardware-back-button) (common/remove-listener-to-hardware-back-button)
(common/hide-connection-sheet) (common/hide-connection-sheet)
(if backup? (on-backup-success) (create-keycard-multiaccount))))) (if backup? (on-backup-success backup?) (create-keycard-multiaccount)))))
(fx/defn on-generate-and-load-key-error (fx/defn on-generate-and-load-key-error
{:events [:keycard.callback/on-generate-and-load-key-error]} {:events [:keycard.callback/on-generate-and-load-key-error]}

View File

@ -36,6 +36,10 @@
[quo/button [quo/button
{:on-press #(re-frame/dispatch [::login/reset-pin])} {:on-press #(re-frame/dispatch [::login/reset-pin])}
(i18n/label :t/keycard-is-frozen-reset)]] (i18n/label :t/keycard-is-frozen-reset)]]
[react/view {:style {:margin-top 24}}
[quo/button
{:on-press #(re-frame/dispatch [:keycard-settings.ui/recovery-card-pressed false])}
(i18n/label :t/keycard-is-frozen-factory-reset)]]
(when show-dismiss-button? (when show-dismiss-button?
[react/view {:margin-top 24} [react/view {:margin-top 24}
[quo/button [quo/button

View File

@ -107,7 +107,7 @@
:size :small :size :small
:title (i18n/label :t/keycard-backup) :title (i18n/label :t/keycard-backup)
:accessibility-label "create-backup-keycard" :accessibility-label "create-backup-keycard"
:on-press #(re-frame/dispatch [:keycard-settings.ui/backup-card-pressed])}] :on-press #(re-frame/dispatch [:keycard-settings.ui/backup-card-pressed :backup-card])}]
;; TODO(rasom): uncomment this when unpairing will be enabled ;; TODO(rasom): uncomment this when unpairing will be enabled
;; https://github.com/status-im/status-react/issues/9227 ;; https://github.com/status-im/status-react/issues/9227
#_[quo/list-item {:icon :main-icons/close #_[quo/list-item {:icon :main-icons/close

View File

@ -1,6 +1,7 @@
(ns status-im.ui.screens.keycard.views (ns status-im.ui.screens.keycard.views
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[reagent.core :as reagent] [reagent.core :as reagent]
[clojure.string :as string]
[status-im.i18n.i18n :as i18n] [status-im.i18n.i18n :as i18n]
[status-im.multiaccounts.core :as multiaccounts] [status-im.multiaccounts.core :as multiaccounts]
[status-im.react-native.resources :as resources] [status-im.react-native.resources :as resources]
@ -240,11 +241,11 @@
[react/nested-text [react/nested-text
{:style {:color colors/gray {:style {:color colors/gray
:text-align :center}} :text-align :center}}
(i18n/label :t/keycard-is-blocked-instructions) (i18n/label :t/keycard-is-blocked-instructions)]
[{} " "] [react/view {:style {:margin-top 24}}
[{:style {:color colors/blue} [quo/button
:on-press #(.openURL ^js react/linking "https://status.im/faq/#keycard")} {:on-press #(re-frame/dispatch [:keycard-settings.ui/recovery-card-pressed false])}
(i18n/label :t/learn-more)]]]]) (i18n/label :t/keycard-is-frozen-factory-reset)]]]])
(defview login-pin [{:keys [back-button-handler (defview login-pin [{:keys [back-button-handler
hide-login-actions? hide-login-actions?
@ -320,14 +321,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/touchable-highlight {:on-press #(re-frame/dispatch [:keycard-settings.ui/recovery-card-pressed (boolean login-multiaccount)])}
[react/view {:flex-direction :row [react/view {:flex-direction :row
:align-items :center :align-items :center
:justify-content :center} :justify-content :center}
[react/text {:style {:text-align :center [react/text {:style {:text-align :center
:margin-bottom (if small-screen? 8 12) :margin-bottom (if small-screen? 8 12)
:color colors/blue}} :color colors/blue}}
(i18n/label :t/keycard-recover)]]] (string/lower-case (i18n/label (if login-multiaccount :t/keycard-recover :t/keycard-is-frozen-factory-reset)))]]]
(cond (cond
(= :after-unblocking status) (= :after-unblocking status)
[access-is-reset [access-is-reset

View File

@ -750,12 +750,13 @@
"keycard-redeem-tx-desc": "Tap the card to sign and receive assets", "keycard-redeem-tx-desc": "Tap the card to sign and receive assets",
"keycard-unauthorized-operation": "You're unauthorized to perform this operation.\n Please tap valid card and try again.", "keycard-unauthorized-operation": "You're unauthorized to perform this operation.\n Please tap valid card and try again.",
"keycard-is-frozen-title": "Keycard is frozen", "keycard-is-frozen-title": "Keycard is frozen",
"keycard-is-frozen-details": "To protect your assets, your card is frozen. Reset card access to unlock keys and send transactions. Create a new passcode and enter your PUK to access your account(s) on this card", "keycard-is-frozen-details": "To protect your assets, your card is frozen. Reset your card to unfreeze it and be able to send transactions. You can do this with your PUK or your mnemonic.",
"keycard-is-frozen-reset": "Reset card access", "keycard-is-frozen-reset": "Reset with PUK",
"keycard-is-frozen-factory-reset": "Reset with mnemonic",
"your-card-is-frozen": "Your Keycard is frozen. Reset card access", "your-card-is-frozen": "Your Keycard is frozen. Reset card access",
"keycard-is-blocked-title": "Keycard is blocked", "keycard-is-blocked-title": "Keycard is blocked",
"keycard-is-blocked-details": "You can no longer use this card to access or sign for this account. There have been too many failed passcode and PUK attempts.", "keycard-is-blocked-details": "You can no longer use this card to access or sign for this account. There have been too many failed passcode and PUK attempts.",
"keycard-is-blocked-instructions": "To access your account reinstall Status and use a new Keycard, use a different wallet or reset Keycard manually.", "keycard-is-blocked-instructions": "To access your account you will need to factory reset your card. Tap the button below to start the procedure, you will need your mnemonic.",
"language": "Language", "language": "Language",
"learn-more": "Learn more", "learn-more": "Learn more",
"learn-more-about-keycard": "Learn more about Keycard", "learn-more-about-keycard": "Learn more about Keycard",