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

View File

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

View File

@ -819,6 +819,7 @@
"card-setup-prepare-text": "The whole process will take a few minutes.", "card-setup-prepare-text": "The whole process will take a few minutes.",
"card-is-paired": "Card is paired", "card-is-paired": "Card is paired",
"no-keycard-applet-on-card": "No Keycard applet on card", "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", "keycard-applet-will-be-installed": "Keycard applet will automatically be installed",
"begin-set-up": "Begin setup", "begin-set-up": "Begin setup",
"maintain-card-to-phone-contact": "Maintain card-to-phone contact during process.", "maintain-card-to-phone-contact": "Maintain card-to-phone contact during process.",