From 2a6cb978ba73a57999b0b517b40f75ff3eec6584 Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Tue, 17 Aug 2021 15:58:17 +0300 Subject: [PATCH] always start PIN/PUK/Pairing change with PIN prompt Signed-off-by: Michele Balistreri --- src/status_im/keycard/change_pin.cljs | 39 ++++++------- src/status_im/keycard/delete_key.cljs | 24 ++++---- src/status_im/keycard/unpair.cljs | 18 +++--- .../ui/screens/keycard/pin/views.cljs | 56 +++++++++---------- 4 files changed, 62 insertions(+), 75 deletions(-) diff --git a/src/status_im/keycard/change_pin.cljs b/src/status_im/keycard/change_pin.cljs index eb2cf03399..63e4d0342b 100644 --- a/src/status_im/keycard/change_pin.cljs +++ b/src/status_im/keycard/change_pin.cljs @@ -5,32 +5,27 @@ [status-im.utils.fx :as fx] [taoensso.timbre :as log] [status-im.keycard.common :as common] - [status-im.utils.security :as security] - [status-im.keycard.login :as keycard.login])) + [status-im.utils.security :as security])) (fx/defn change-credentials-pressed {:events [:keycard-settings.ui/change-credentials-pressed]} [{:keys [db] :as cofx} changing] - (let [pin-retry-counter (get-in db [:keycard :application-info :pin-retry-counter]) - enter-step (if (zero? pin-retry-counter) :puk :current)] - (if (= enter-step :puk) - (keycard.login/reset-pin cofx) - (fx/merge cofx - {:db - (assoc-in db [:keycard :pin] {:enter-step enter-step - :current [] - :puk [] - :original [] - :confirmation [] - :puk-original [] - :puk-confirmation [] - :status nil - :error-label nil - :on-verified (case changing - :pin :keycard/proceed-to-change-pin - :puk :keycard/proceed-to-change-puk - :pairing :keycard/proceed-to-change-pairing)})} - (common/navigate-to-enter-pin-screen))))) + (fx/merge cofx + {:db + (assoc-in db [:keycard :pin] {:enter-step :current + :current [] + :puk [] + :original [] + :confirmation [] + :puk-original [] + :puk-confirmation [] + :status nil + :error-label nil + :on-verified (case changing + :pin :keycard/proceed-to-change-pin + :puk :keycard/proceed-to-change-puk + :pairing :keycard/proceed-to-change-pairing)})} + (common/navigate-to-enter-pin-screen))) (fx/defn proceed-to-change-pin {:events [:keycard/proceed-to-change-pin]} diff --git a/src/status_im/keycard/delete_key.cljs b/src/status_im/keycard/delete_key.cljs index 547c3277a1..5cc4789395 100644 --- a/src/status_im/keycard/delete_key.cljs +++ b/src/status_im/keycard/delete_key.cljs @@ -31,16 +31,14 @@ (fx/defn proceed-to-reset-card {:events [:keycard/proceed-to-reset-card]} [{:keys [db] :as cofx} keep-keys-on-keycard?] - (let [pin-retry-counter (get-in db [:keycard :application-info :pin-retry-counter]) - enter-step (if (zero? pin-retry-counter) :puk :current)] - (fx/merge cofx - {:db (assoc-in db [:keycard :pin] {:enter-step enter-step - :current [] - :puk [] - :status nil - :error-label nil - :on-verified (if keep-keys-on-keycard? - :keycard/unpair-and-delete - :keycard/remove-key-with-unpair)})} - (common/set-on-card-connected :keycard/navigate-to-enter-pin-screen) - (common/navigate-to-enter-pin-screen)))) + (fx/merge cofx + {:db (assoc-in db [:keycard :pin] {:enter-step :current + :current [] + :puk [] + :status nil + :error-label nil + :on-verified (if keep-keys-on-keycard? + :keycard/unpair-and-delete + :keycard/remove-key-with-unpair)})} + (common/set-on-card-connected :keycard/navigate-to-enter-pin-screen) + (common/navigate-to-enter-pin-screen))) diff --git a/src/status_im/keycard/unpair.cljs b/src/status_im/keycard/unpair.cljs index f287fb03bd..ce6dd30b63 100644 --- a/src/status_im/keycard/unpair.cljs +++ b/src/status_im/keycard/unpair.cljs @@ -21,16 +21,14 @@ (fx/defn unpair-card-confirmed {:events [:keycard-settings.ui/unpair-card-confirmed]} [{:keys [db] :as cofx}] - (let [pin-retry-counter (get-in db [:keycard :application-info :pin-retry-counter]) - enter-step (if (zero? pin-retry-counter) :puk :current)] - (fx/merge cofx - {:db (assoc-in db [:keycard :pin] {:enter-step enter-step - :current [] - :puk [] - :status nil - :error-label nil - :on-verified :keycard/unpair})} - (common/navigate-to-enter-pin-screen)))) + (fx/merge cofx + {:db (assoc-in db [:keycard :pin] {:enter-step :current + :current [] + :puk [] + :status nil + :error-label nil + :on-verified :keycard/unpair})} + (common/navigate-to-enter-pin-screen))) (fx/defn unpair {:events [:keycard/unpair]} diff --git a/src/status_im/ui/screens/keycard/pin/views.cljs b/src/status_im/ui/screens/keycard/pin/views.cljs index 92a0fd5fcd..b4625a870e 100644 --- a/src/status_im/ui/screens/keycard/pin/views.cljs +++ b/src/status_im/ui/screens/keycard/pin/views.cljs @@ -242,33 +242,29 @@ ;; properly rewritten so that different instances of pin-view do not ;; mess with state unrelated to them. step (or step :current)] - (if (zero? pin-retry-counter) - [pin-view {:pin pin - :retry-counter (when (< puk-retry-counter puk-retries) puk-retry-counter) - :title-label :t/enter-puk-code - :description-label :t/enter-puk-code-description - :step step - :status status - :error-label error-label}] - [pin-view {:pin pin - :retry-counter (when (< pin-retry-counter pin-retries) pin-retry-counter) - :title-label (case step - :current :t/current-pin - :login :t/current-pin - :import-multiaccount :t/current-pin - :original :t/create-a-pin - :confirmation :t/repeat-pin - :puk-original :t/create-a-puk - :puk-confirmation :t/repeat-puk - :t/current-pin) - :description-label (case step - :current :t/current-pin-description - :sign :t/current-pin-description - :import-multiaccount :t/current-pin-description - :login :t/login-pin-description - :puk-original :t/new-puk-description - :puk-confirmation :t/new-puk-description - :t/new-pin-description) - :step step - :status status - :error-label error-label}])))) + [pin-view {:pin pin + :retry-counter (if (= step :puk) + (when (< puk-retry-counter puk-retries) puk-retry-counter) + (when (< pin-retry-counter pin-retries) pin-retry-counter)) + :title-label (case step + :current :t/current-pin + :login :t/current-pin + :import-multiaccount :t/current-pin + :original :t/create-a-pin + :confirmation :t/repeat-pin + :puk :t/enter-puk-code + :puk-original :t/create-a-puk + :puk-confirmation :t/repeat-puk + :t/current-pin) + :description-label (case step + :current :t/current-pin-description + :sign :t/current-pin-description + :import-multiaccount :t/current-pin-description + :login :t/login-pin-description + :puk :t/enter-puk-code-description + :puk-original :t/new-puk-description + :puk-confirmation :t/new-puk-description + :t/new-pin-description) + :step step + :status status + :error-label error-label}])))