ensure card has applet installed before starting setup

Signed-off-by: Dmitry Novotochinov <dmitry.novot@gmail.com>
This commit is contained in:
Dmitry Novotochinov 2019-04-09 15:13:44 +03:00
parent c49a2269c5
commit 072ab5c487
No known key found for this signature in database
GPG Key ID: 43D1DAF5AD39C927
3 changed files with 21 additions and 25 deletions

View File

@ -81,9 +81,9 @@
(fx/defn show-no-keycard-applet-alert [_]
{:utils/show-confirmation {:title (i18n/label :t/no-keycard-applet-on-card)
:content (i18n/label :t/keycard-applet-will-be-installed)
:content (i18n/label :t/keycard-applet-install-instructions)
:cancel-button-text ""
:confirm-button-text :t/next}})
:confirm-button-text :t/okay}})
(fx/defn show-keycard-has-account-alert
[{:keys [db] :as cofx}]
@ -92,10 +92,7 @@
:utils/show-confirmation {:title nil
:content (i18n/label :t/keycard-has-account-on-it)
:cancel-button-text ""
:confirm-button-text :t/okay}}
(if (empty? (:accounts/accounts db))
(navigation/navigate-to-cofx :intro nil)
(navigation/navigate-to-cofx :accounts nil))))
:confirm-button-text :t/okay}}))
(defn- card-state->setup-step [state]
(case state
@ -140,15 +137,20 @@
[{:keys [db] :as cofx}]
(let [app-info (get-in db [:hardwallet :application-info])
card-state (get-card-state app-info)
setup-running? (boolean (get-in db [:hardwallet :setup-step]))]
setup-running? (boolean (get-in db [:hardwallet :setup-step]))
db' (assoc-in db [:hardwallet :card-state] card-state)]
(if setup-running?
(fx/merge cofx
{:db (assoc-in db [:hardwallet :card-state] card-state)}
(when setup-running?
{:db db'}
(set-setup-step card-state)
(if (= :pre-init card-state)
(navigation/navigate-to-cofx :hardwallet-setup nil)
(navigation/navigate-to-cofx :hardwallet-authentication-method nil))
(when (= card-state :blank)
(show-no-keycard-applet-alert))
(if (= card-state :account)
(show-keycard-has-account-alert)
(set-setup-step card-state))))))
(when (= card-state :account)
(show-keycard-has-account-alert)))
{:db db'})))
(fx/defn navigate-to-keycard-settings
[{:keys [db] :as cofx}]
@ -299,6 +301,7 @@
accounts-screen? (= :accounts (:view-id db))
auto-login? (and accounts-screen?
(not= on-success :hardwallet/auto-login))
setup-starting? (= :begin (get-in db [:hardwallet :setup-step]))
enter-step (if (zero? pin-retry-counter)
:puk
(get-in db [:hardwallet :pin :enter-step]))]
@ -312,8 +315,7 @@
(login-with-keycard true))
(when-not connect-screen?
(clear-on-card-read))
(when (and (nil? card-state)
instance-uid)
(when setup-starting?
(check-card-state))
(if (zero? puk-retry-counter)
{:utils/show-popup {:title (i18n/label :t/error)
@ -830,9 +832,8 @@
(fx/defn on-card-connected
[{:keys [db] :as cofx} _]
(log/debug "[hardwallet] card connected")
(let [setup-step (get-in db [:hardwallet :setup-step])
setup-running? (boolean setup-step)
pin-enter-step (get-in db [:hardwallet :pin :enter-step])
(let [pin-enter-step (get-in db [:hardwallet :pin :enter-step])
setup-running? (boolean (get-in db [:hardwallet :setup-step]))
login? (= :login pin-enter-step)
instance-uid (get-in db [:hardwallet :application-info :instance-uid])
accounts-screen? (= :accounts (:view-id db))
@ -883,15 +884,9 @@
pin (vector->string (get-in db [:hardwallet :pin :original]))]
(case card-state
:blank
{:hardwallet/install-applet-and-init-card pin}
:pre-init
{:hardwallet/init-card pin}
:init
{:hardwallet/install-applet-and-init-card pin}
(do
(log/debug (str "Cannot start keycard installation from state: " card-state))
(fx/merge cofx

View File

@ -59,7 +59,7 @@
:margin-bottom 40})
(def bottom-action-text
{:typography :main
{:typography :main-medium
:color colors/blue
:text-transform :uppercase})

View File

@ -819,6 +819,7 @@
"card-setup-prepare-text": "The whole process will take a few minutes.",
"card-is-paired": "Card is paired",
"no-keycard-applet-on-card": "No Keycard applet on card",
"keycard-applet-install-instructions": "To install the applet please follow the instructions on https://github.com/status-im/keycard-cli#keycard-applet-installation",
"keycard-applet-will-be-installed": "Keycard applet will automatically be installed",
"begin-set-up": "Begin setup",
"maintain-card-to-phone-contact": "Maintain card-to-phone contact during process.",