From eea5b4eb0f83684b436d6b6e139ff6567bb0e91c Mon Sep 17 00:00:00 2001 From: Michele Balistreri Date: Fri, 9 Apr 2021 11:56:28 +0300 Subject: [PATCH] add change PUK functionality Signed-off-by: Michele Balistreri --- package.json | 2 +- src/status_im/keycard/card.cljs | 18 +++++ src/status_im/keycard/change_pin.cljs | 67 ++++++++++++++++--- src/status_im/keycard/core.cljs | 27 +++++++- src/status_im/keycard/fx.cljs | 4 ++ src/status_im/keycard/keycard.cljs | 1 + src/status_im/keycard/real_keycard.cljs | 10 +++ src/status_im/keycard/simulated_keycard.cljs | 5 ++ .../ui/screens/keycard/pin/views.cljs | 6 +- .../ui/screens/keycard/settings/views.cljs | 11 ++- translations/en.json | 5 ++ yarn.lock | 6 +- 12 files changed, 142 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index ddd4d85b0d..62a34d0d37 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "react-native-screens": "^2.10.1", "react-native-shake": "^3.3.1", "react-native-splash-screen": "^3.2.0", - "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.33", + "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.34", "react-native-svg": "^9.8.4", "react-native-touch-id": "^4.4.1", "react-native-webview": "git+https://github.com/status-im/react-native-webview.git#v10.9.2", diff --git a/src/status_im/keycard/card.cljs b/src/status_im/keycard/card.cljs index fd37208898..7841da788d 100644 --- a/src/status_im/keycard/card.cljs +++ b/src/status_im/keycard/card.cljs @@ -238,6 +238,24 @@ [:keycard.callback/on-change-pin-error (error-object->map response)]))}))) +(defn change-puk [args] + (log/debug "[keycard] change-puk") + (keycard/change-puk + card + (merge + args + {:on-success + (fn [response] + (log/debug "[keycard response succ] change-puk") + (re-frame/dispatch + [:keycard.callback/on-change-puk-success response])) + :on-failure + (fn [response] + (log/debug "[keycard response fail] change-puk") + (re-frame/dispatch + [:keycard.callback/on-change-pin-error + (error-object->map response)]))}))) + (defn unpair [args] (log/debug "[keycard] unpair") (keycard/unpair diff --git a/src/status_im/keycard/change_pin.cljs b/src/status_im/keycard/change_pin.cljs index 0512dc1252..40eb9e388c 100644 --- a/src/status_im/keycard/change_pin.cljs +++ b/src/status_im/keycard/change_pin.cljs @@ -7,23 +7,27 @@ [status-im.keycard.common :as common] [status-im.keycard.login :as keycard.login])) -(fx/defn change-pin-pressed - {:events [:keycard-settings.ui/change-pin-pressed]} - [{:keys [db] :as cofx}] +(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 [] - :status nil - :error-label nil - :on-verified :keycard/proceed-to-change-pin})} + (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)})} (common/navigate-to-enter-pin-screen))))) (fx/defn proceed-to-change-pin @@ -35,6 +39,15 @@ (assoc-in [:keycard :pin :status] nil))} (navigation/navigate-to-cofx :enter-pin-settings nil))) +(fx/defn proceed-to-change-puk + {:events [:keycard/proceed-to-change-puk]} + [{:keys [db] :as cofx}] + (fx/merge cofx + {:db (-> db + (assoc-in [:keycard :pin :enter-step] :puk-original) + (assoc-in [:keycard :pin :status] nil))} + (navigation/navigate-to-cofx :enter-pin-settings nil))) + (fx/defn discard-pin-change {:events [::on-cancel]} [{:keys [db] :as cofx}] @@ -71,6 +84,25 @@ {:new-pin new-pin :current-pin current-pin}})))})))) +(fx/defn change-puk + {:events [:keycard/change-puk]} + [{:keys [db] :as cofx}] + (common/show-connection-sheet + cofx + {:sheet-options {:on-cancel [::on-cancel]} + :on-card-connected :keycard/change-puk + :handler + (fn [{:keys [db] :as cofx}] + (let [puk (common/vector->string + (get-in db [:keycard :pin :puk-original])) + pin (common/vector->string + (get-in db [:keycard :pin :current]))] + (fx/merge + cofx + {:db (assoc-in db [:keycard :pin :status] :verifying) + :keycard/change-puk {:puk puk + :pin pin}})))})) + (fx/defn on-change-pin-success {:events [:keycard.callback/on-change-pin-success]} [{:keys [db] :as cofx}] @@ -90,6 +122,19 @@ (when (:multiaccounts/login db) (common/get-keys-from-keycard))))) +(fx/defn on-change-puk-success + {:events [:keycard.callback/on-change-puk-success]} + [{:keys [db] :as cofx}] + (fx/merge cofx + {:db (assoc-in db [:keycard :pin] {:status nil + :puk-original [] + :puk-confirmation [] + :error-label nil}) + :utils/show-popup {:title "" + :content (i18n/label :t/puk-changed)}} + (common/hide-connection-sheet) + (navigation/navigate-to-cofx :keycard-settings nil))) + (fx/defn on-change-pin-error {:events [:keycard.callback/on-change-pin-error]} [{:keys [db] :as cofx} error] diff --git a/src/status_im/keycard/core.cljs b/src/status_im/keycard/core.cljs index 9be3aef6a3..27b5870925 100644 --- a/src/status_im/keycard/core.cljs +++ b/src/status_im/keycard/core.cljs @@ -135,6 +135,9 @@ (defn- proceed-to-pin-confirmation [fx] (assoc-in fx [:db :keycard :pin :enter-step] :confirmation)) +(defn- proceed-to-change-puk-confirmation [fx] + (assoc-in fx [:db :keycard :pin :enter-step] :puk-confirmation)) + (defn- proceed-to-pin-reset-confirmation [fx] (-> fx (update-in [:db :keycard :pin] dissoc :reset-confirmation) @@ -289,7 +292,7 @@ [{:keys [db] :as cofx} number enter-step] (log/debug "update-pin" enter-step) (let [numbers-entered (count (get-in db [:keycard :pin enter-step])) - need-update? (if (= enter-step :puk) + need-update? (if (or (= enter-step :puk) (= enter-step :puk-original) (= enter-step :puk-confirmation)) (< numbers-entered puk-code-length) (< numbers-entered pin-code-length))] (fx/merge cofx @@ -307,6 +310,13 @@ :original [] :confirmation []})) +(defn- puk-enter-error [fx error-label] + (update-in fx [:db :keycard :pin] merge {:status :error + :error-label error-label + :enter-step :puk-original + :puk-original [] + :puk-confirmation []})) + (defn- pin-reset-error [fx error-label] (update-in fx [:db :keycard :pin] merge {:status :error :error-label error-label @@ -375,6 +385,21 @@ (get-in db [:keycard :pin :confirmation]))) (pin-enter-error :t/pin-mismatch) + (and (= enter-step :puk-original) + (= puk-code-length numbers-entered)) + (proceed-to-change-puk-confirmation) + + (and (= enter-step :puk-confirmation) + (= (get-in db [:keycard :pin :puk-original]) + (get-in db [:keycard :pin :puk-confirmation]))) + (change-pin/change-puk) + + (and (= enter-step :puk-confirmation) + (= puk-code-length numbers-entered) + (not= (get-in db [:keycard :pin :puk-original]) + (get-in db [:keycard :pin :puk-confirmation]))) + (puk-enter-error :t/puk-mismatch) + (= enter-step :reset) (proceed-to-pin-reset-confirmation) diff --git a/src/status_im/keycard/fx.cljs b/src/status_im/keycard/fx.cljs index c81e591961..d12bf6ad67 100644 --- a/src/status_im/keycard/fx.cljs +++ b/src/status_im/keycard/fx.cljs @@ -107,6 +107,10 @@ :keycard/change-pin card/change-pin) +(re-frame/reg-fx + :keycard/change-puk + card/change-puk) + (re-frame/reg-fx :keycard/unpair card/unpair) diff --git a/src/status_im/keycard/keycard.cljs b/src/status_im/keycard/keycard.cljs index dd71457c28..13d48eaaaf 100644 --- a/src/status_im/keycard/keycard.cljs +++ b/src/status_im/keycard/keycard.cljs @@ -23,6 +23,7 @@ (unblock-pin [this args]) (verify-pin [this args]) (change-pin [this args]) + (change-puk [this args]) (unpair [this args]) (delete [this args]) (remove-key [this args]) diff --git a/src/status_im/keycard/real_keycard.cljs b/src/status_im/keycard/real_keycard.cljs index 0a17850cb3..a84e79e1a3 100644 --- a/src/status_im/keycard/real_keycard.cljs +++ b/src/status_im/keycard/real_keycard.cljs @@ -170,6 +170,14 @@ (then on-success) (catch on-failure)))) +(defn change-puk + [{:keys [pin puk on-success on-failure]}] + (when (and pin puk) + (.. status-keycard + (changePUK pin puk) + (then on-success) + (catch on-failure)))) + (defn unpair [{:keys [pin on-success on-failure]}] (when (and pin) @@ -315,6 +323,8 @@ (verify-pin args)) (keycard/change-pin [this args] (change-pin args)) + (keycard/change-puk [this args] + (change-puk args)) (keycard/unpair [this args] (unpair args)) (keycard/delete [this args] diff --git a/src/status_im/keycard/simulated_keycard.cljs b/src/status_im/keycard/simulated_keycard.cljs index 424bd2d884..afdb845ce7 100644 --- a/src/status_im/keycard/simulated_keycard.cljs +++ b/src/status_im/keycard/simulated_keycard.cljs @@ -259,6 +259,8 @@ (defn change-pin [args] (log/warn "change-pin not implemented" args)) +(defn change-puk [args] + (log/warn "change-puk not implemented" args)) (defn unpair [args] (log/warn "unpair not implemented" args)) (defn delete [args] @@ -479,6 +481,9 @@ (keycard/change-pin [this args] (log/debug "simulated card change-pin") (change-pin args)) + (keycard/change-puk [this args] + (log/debug "simulated card change-puk") + (change-puk args)) (keycard/unpair [this args] (log/debug "simulated card unpair") (unpair args)) diff --git a/src/status_im/ui/screens/keycard/pin/views.cljs b/src/status_im/ui/screens/keycard/pin/views.cljs index 577e1fb5ef..70a91cb34a 100644 --- a/src/status_im/ui/screens/keycard/pin/views.cljs +++ b/src/status_im/ui/screens/keycard/pin/views.cljs @@ -181,7 +181,7 @@ retry-counter small-screen? save-password-checkbox?]}] (let [enabled? (and (not= status :verifying) (not @!error?)) - puk? (= step :puk)] + puk? (or (= step :puk) (= step :puk-original) (= step :puk-confirmation))] [react/scroll-view [react/view styles/pin-container [react/view (styles/center-container title-label) @@ -261,12 +261,16 @@ :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 diff --git a/src/status_im/ui/screens/keycard/settings/views.cljs b/src/status_im/ui/screens/keycard/settings/views.cljs index 6c4f9b8d63..371eb9da55 100644 --- a/src/status_im/ui/screens/keycard/settings/views.cljs +++ b/src/status_im/ui/screens/keycard/settings/views.cljs @@ -92,14 +92,19 @@ [quo/list-item {:icon :main-icons/add :size :small :title (i18n/label :t/change-pin) - :on-press #(re-frame/dispatch [:keycard-settings.ui/change-pin-pressed])}] - ;; TODO(rasom): uncomment this when unpairing will be enabled - ;; https://github.com/status-im/status-react/issues/9227 + :on-press #(re-frame/dispatch [:keycard-settings.ui/change-credentials-pressed :pin])}] + [quo/list-item {:icon :main-icons/security + :size :small + :title (i18n/label :t/change-puk) + :accessibility-label "change-puk" + :on-press #(re-frame/dispatch [:keycard-settings.ui/change-credentials-pressed :puk])}] [quo/list-item {:icon :main-icons/keycard :size :small :title (i18n/label :t/keycard-backup) :accessibility-label "create-backup-keycard" :on-press #(re-frame/dispatch [:keycard-settings.ui/backup-card-pressed])}] + ;; TODO(rasom): uncomment this when unpairing will be enabled + ;; https://github.com/status-im/status-react/issues/9227 #_[quo/list-item {:icon :main-icons/close :size :small :title (i18n/label :t/unpair-card) diff --git a/translations/en.json b/translations/en.json index b47c8ed642..f3c071f5ca 100644 --- a/translations/en.json +++ b/translations/en.json @@ -120,6 +120,7 @@ "change-passcode": "Change Passcode", "change-password": "Change Password", "change-pin": "Change 6-digit passcode", + "change-puk": "Change 12-digit PUK", "changed-amount-warning": "Amount was changed from {{old}} to {{new}}", "changed-asset-warning": "Asset was changed from {{old}} to {{new}}", "chaos-mode": "Chaos mode", @@ -237,6 +238,7 @@ "counter-99-plus": "99+", "create": "Create", "create-a-pin": "Create a 6-digit passcode", + "create-a-puk": "Create a 12-digit PUK", "create-group-chat": "Create group chat", "create-multiaccount": "Generate keys", "create-new-key": "Get new keys", @@ -878,6 +880,7 @@ "new-group-chat": "New group chat", "new-network": "New network", "new-pin-description": "Enter new 6-digit passcode", + "new-puk-description": "Enter new 12-digit PUK", "new-public-group-chat": "Join public chat", "next": "Next", "no": "No", @@ -968,6 +971,7 @@ "phone-e164": "International 1", "photos-access-error": "To grant the required photos permission, please go to your system settings and make sure that Status > Photos is selected.", "pin-changed": "6-digit passcode has been changed", + "puk-changed": "12-digit PUK has been changed", "pin-code": "6-digit passcode", "pin-mismatch": "Wrong passcode", "pin-retries-left": "{{number}} attemps left", @@ -1027,6 +1031,7 @@ "remove-token": "Remove token", "removed": "removed", "repeat-pin": "Repeat new 6-digit passcode", + "repeat-puk": "Repeat new 12-digit PUK", "report-bug-email-template": "1. Issue Description\n(Describe the feature you would like, or briefly summarise the bug and what you did, what you expected to happen, and what actually happens. Sections below)\n\n\n2. Steps to reproduce\n(Describe how we can replicate the bug step by step.)\n-Open Status\n-...\n-Step 3, etc.\n\n\n3. Expected behavior\n(Describe what you expected to happen.)\n\n\n4. Actual behavior\n(Describe what actually happened.)\n\n\n5. Attach screenshots that can demo the problem, please\n", "request-transaction": "Request transaction", "required-field": "Required field", diff --git a/yarn.lock b/yarn.lock index 3a26730e61..6ee88b180d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6751,9 +6751,9 @@ react-native-splash-screen@^3.2.0: resolved "https://registry.yarnpkg.com/react-native-splash-screen/-/react-native-splash-screen-3.2.0.tgz#d47ec8557b1ba988ee3ea98d01463081b60fff45" integrity sha512-Ls9qiNZzW/OLFoI25wfjjAcrf2DZ975hn2vr6U9gyuxi2nooVbzQeFoQS5vQcbCt9QX5NY8ASEEAtlLdIa6KVg== -"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.33": - version "2.5.33" - resolved "git+https://github.com/status-im/react-native-status-keycard.git#d1098e969a1007919134e210781bdc57222bf8d3" +"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.34": + version "2.5.34" + resolved "git+https://github.com/status-im/react-native-status-keycard.git#b9f242aa11afbb6a79c269459c48e32a6091176c" react-native-svg@^9.8.4: version "9.13.6"