From 072ab5c48752c87de371ed25cc6aaeab4a9982af Mon Sep 17 00:00:00 2001 From: Dmitry Novotochinov Date: Tue, 9 Apr 2019 15:13:44 +0300 Subject: [PATCH] ensure card has applet installed before starting setup Signed-off-by: Dmitry Novotochinov --- src/status_im/hardwallet/core.cljs | 43 ++++++++----------- .../ui/screens/hardwallet/success/styles.cljs | 2 +- translations/en.json | 1 + 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/status_im/hardwallet/core.cljs b/src/status_im/hardwallet/core.cljs index a5d7abb2f2..83f0c1caed 100644 --- a/src/status_im/hardwallet/core.cljs +++ b/src/status_im/hardwallet/core.cljs @@ -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]))] - (fx/merge cofx - {:db (assoc-in db [:hardwallet :card-state] card-state)} - (when setup-running? + 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 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 diff --git a/src/status_im/ui/screens/hardwallet/success/styles.cljs b/src/status_im/ui/screens/hardwallet/success/styles.cljs index f56de1db41..2841b5f2f8 100644 --- a/src/status_im/ui/screens/hardwallet/success/styles.cljs +++ b/src/status_im/ui/screens/hardwallet/success/styles.cljs @@ -59,7 +59,7 @@ :margin-bottom 40}) (def bottom-action-text - {:typography :main + {:typography :main-medium :color colors/blue :text-transform :uppercase}) diff --git a/translations/en.json b/translations/en.json index 5ebc4949f3..a62dd0d826 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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.",