diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 7568fe3fb1..574e48397b 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -628,7 +628,7 @@ EXTERNAL SOURCES: CHECKOUT OPTIONS: Keycard: - :commit: 75c956d64a7d9fdf63e1aac9c2f36237e792c3eb + :commit: abf2be41c70846ab6f11c8bd445faf81b0befc1f :git: https://github.com/status-im/Keycard.swift.git secp256k1: :commit: 46a1fa30d9b8babeae85ff519050f42394ab5fcc diff --git a/ios/StatusIm/Info.plist b/ios/StatusIm/Info.plist index bc9264967d..d5fff3fa83 100644 --- a/ios/StatusIm/Info.plist +++ b/ios/StatusIm/Info.plist @@ -131,6 +131,7 @@ A00000080400010101 A00000080400010301 + A000000151000000 NFCReaderUsageDescription Enable Keycard diff --git a/ios/StatusImPR/Info.plist b/ios/StatusImPR/Info.plist index b93d2c175c..5066250e5f 100644 --- a/ios/StatusImPR/Info.plist +++ b/ios/StatusImPR/Info.plist @@ -137,6 +137,7 @@ A00000080400010101 A00000080400010301 + A000000151000000 NFCReaderUsageDescription Enable Keycard diff --git a/ios/StatusImTests/Info.plist b/ios/StatusImTests/Info.plist index 51031e10b1..db4d420079 100644 --- a/ios/StatusImTests/Info.plist +++ b/ios/StatusImTests/Info.plist @@ -24,6 +24,7 @@ A00000080400010101 A00000080400010301 + A000000151000000 NFCReaderUsageDescription Enable Keycard diff --git a/package.json b/package.json index 62a34d0d37..7f246a88e6 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.34", + "react-native-status-keycard": "git+https://github.com/status-im/react-native-status-keycard.git#v2.5.35", "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 7174adfd99..819d1d6bcc 100644 --- a/src/status_im/keycard/card.cljs +++ b/src/status_im/keycard/card.cljs @@ -99,6 +99,25 @@ [:keycard.callback/on-get-application-info-error (error-object->map response)]))}))) +(defn factory-reset [{:keys [on-success] :as args}] + (log/debug "[keycard] factory-reset") + (keycard/factory-reset + card + (merge + args + {:on-success + (fn [response] + (log/debug "[keycard response succ] get-application-info") + (re-frame/dispatch + [:keycard.callback/on-get-application-info-success + response on-success])) + :on-failure + (fn [response] + (log/debug "[keycard response fail] get-application-info") + (re-frame/dispatch + [:keycard.callback/on-get-application-info-error + (error-object->map response)]))}))) + (defn install-applet [] (log/debug "[keycard] install-applet") (keycard/install-applet diff --git a/src/status_im/keycard/common.cljs b/src/status_im/keycard/common.cljs index 162301e52a..8282a1563b 100644 --- a/src/status_im/keycard/common.cljs +++ b/src/status_im/keycard/common.cljs @@ -409,6 +409,13 @@ (navigation/navigate-to-cofx :keycard-recovery-pin nil))) (show-wrong-keycard-alert true))))) +(fx/defn factory-reset + {:events [:keycard/factory-reset]} + [{:keys [db]} on-card-read] + (log/debug "[keycard] factory-reset") + {:db (update db :keycard dissoc :factory-reset-card?) + :keycard/factory-reset {:on-success on-card-read}}) + ;; Get application info (fx/defn get-application-info diff --git a/src/status_im/keycard/fx.cljs b/src/status_im/keycard/fx.cljs index 14b72051ed..ad932520fd 100644 --- a/src/status_im/keycard/fx.cljs +++ b/src/status_im/keycard/fx.cljs @@ -59,6 +59,10 @@ :keycard/get-application-info card/get-application-info) +(re-frame/reg-fx + :keycard/factory-reset + card/factory-reset) + (re-frame/reg-fx :keycard/check-nfc-support card/check-nfc-support) diff --git a/src/status_im/keycard/ios_keycard.cljs b/src/status_im/keycard/ios_keycard.cljs deleted file mode 100644 index f5c738924c..0000000000 --- a/src/status_im/keycard/ios_keycard.cljs +++ /dev/null @@ -1,34 +0,0 @@ -(ns status-im.keycard.ios-keycard - (:require [status-im.keycard.keycard :as keycard])) - -(defrecord IOSKeycard [] - keycard/Keycard - (check-nfc-support [this args]) - (check-nfc-enabled [this args]) - (open-nfc-settings [this]) - (register-card-events [this args]) - (on-card-disconnected [this callback]) - (on-card-connected [this callback]) - (remove-event-listener [this event]) - (remove-event-listeners [this]) - (get-application-info [this args]) - (install-applet [this args]) - (init-card [this args]) - (install-applet-and-init-card [this args]) - (pair [this args]) - (generate-and-load-key [this args]) - (unblock-pin [this args]) - (verify-pin [this args]) - (change-pin [this args]) - (unpair [this args]) - (delete [this args]) - (remove-key [this args]) - (remove-key-with-unpair [this args]) - (export-key [this args]) - (unpair-and-delete [this args]) - (import-keys [this args]) - (get-keys [this args]) - (sign [this args]) - (save-multiaccount-and-login [this args]) - (login [this args]) - (send-transaction-with-signature [this args])) diff --git a/src/status_im/keycard/keycard.cljs b/src/status_im/keycard/keycard.cljs index 39a49879bf..795b6da340 100644 --- a/src/status_im/keycard/keycard.cljs +++ b/src/status_im/keycard/keycard.cljs @@ -14,6 +14,7 @@ (remove-event-listener [this event]) (remove-event-listeners [this]) (get-application-info [this args]) + (factory-reset [this args]) (install-applet [this args]) (install-cash-applet [this args]) (init-card [this args]) diff --git a/src/status_im/keycard/onboarding.cljs b/src/status_im/keycard/onboarding.cljs index e6fd2f0645..a8c69ca4d3 100644 --- a/src/status_im/keycard/onboarding.cljs +++ b/src/status_im/keycard/onboarding.cljs @@ -4,6 +4,7 @@ [status-im.i18n.i18n :as i18n] [status-im.navigation :as navigation] [status-im.utils.fx :as fx] + [status-im.utils.utils :as utils] [status-im.keycard.common :as common] [status-im.keycard.mnemonic :as mnemonic] [taoensso.timbre :as log] @@ -274,6 +275,11 @@ {:mnemonic mnemonic :pin pin'}}))) +(fx/defn factory-reset-card-toggle + {:events [:keycard.onboarding.intro.ui/factory-reset-card-toggle]} + [{:keys [db] :as cofx} checked?] + {:db (assoc-in db [:keycard :factory-reset-card?] checked?)}) + (fx/defn begin-setup-pressed {:events [:keycard.onboarding.intro.ui/begin-setup-pressed]} [{:keys [db] :as cofx}] @@ -282,14 +288,34 @@ {:db (-> db (update :keycard dissoc :secrets :card-state :multiaccount-wallet-address - :multiaccount-whisper-public-key - :application-info) + :multiaccount-whisper-public-key :application-info) (assoc-in [:keycard :setup-step] :begin) (assoc-in [:keycard :pin :on-verified] nil))} - (common/show-connection-sheet - {:on-card-connected :keycard/get-application-info - :on-card-read :keycard/check-card-state - :handler (common/get-application-info :keycard/check-card-state)}))) + (if (get-in db [:keycard :factory-reset-card?]) + (utils/show-confirmation {:title (i18n/label :t/keycard-factory-reset-title) + :content (i18n/label :t/keycard-factory-reset-text) + :confirm-button-text (i18n/label :t/yes) + :cancel-button-text (i18n/label :t/no) + :on-accept #(re-frame/dispatch [::factory-reset]) + :on-cancel #(re-frame/dispatch [::factory-reset-cancel])}) + (common/show-connection-sheet + {:on-card-connected :keycard/get-application-info + :on-card-read :keycard/check-card-state + :handler (common/get-application-info :keycard/check-card-state)})))) + +(fx/defn factory-reset + {:events [::factory-reset]} + [cofx] + (common/show-connection-sheet + cofx + {:on-card-connected :keycard/factory-reset + :on-card-read :keycard/check-card-state + :handler (common/factory-reset :keycard/check-card-state)})) + +(fx/defn factory-reset-cancel + {:events [::factory-reset-cancel]} + [{:keys [db] :as cofx}] + {:db (update db :keycard dissoc :factory-reset-card?)}) (fx/defn cancel-confirm {:events [::cancel-confirm]} diff --git a/src/status_im/keycard/real_keycard.cljs b/src/status_im/keycard/real_keycard.cljs index 51566eb5ce..2fc7821dcf 100644 --- a/src/status_im/keycard/real_keycard.cljs +++ b/src/status_im/keycard/real_keycard.cljs @@ -107,6 +107,17 @@ (on-success info)))) (catch on-failure))) +(defn factory-reset + [{:keys [on-success on-failure]}] + (.. status-keycard + (factoryReset) + (then (fn [response] + (let [info (-> response + (js->clj :keywordize-keys true) + (update :key-uid ethereum/normalized-hex))] + (on-success info)))) + (catch on-failure))) + (defn install-applet [{:keys [on-success on-failure]}] (.. status-keycard installApplet @@ -313,6 +324,8 @@ (set-pairings args)) (keycard/get-application-info [this args] (get-application-info args)) + (keycard/factory-reset [this args] + (factory-reset args)) (keycard/install-applet [this args] (install-applet args)) (keycard/install-cash-applet [this args] diff --git a/src/status_im/keycard/simulated_keycard.cljs b/src/status_im/keycard/simulated_keycard.cljs index 6c9e389c41..a8d0175730 100644 --- a/src/status_im/keycard/simulated_keycard.cljs +++ b/src/status_im/keycard/simulated_keycard.cljs @@ -119,6 +119,7 @@ (log/debug "get-application-info") (later #(on-success (get @state :application-info)))) +(defn factory-reset [_]) (defn install-applet [_]) (defn install-cash-applet [_]) @@ -459,6 +460,9 @@ (keycard/get-application-info [this args] (log/debug "simulated card get-application-info") (get-application-info args)) + (keycard/factory-reset [this args] + (log/debug "simulated card factory-reset") + (get-application-info args)) (keycard/install-applet [this args] (log/debug "simulated card install-applet") (install-applet args)) diff --git a/src/status_im/ui/screens/keycard/onboarding/views.cljs b/src/status_im/ui/screens/keycard/onboarding/views.cljs index 78a19c1e46..7aa3456fe4 100644 --- a/src/status_im/ui/screens/keycard/onboarding/views.cljs +++ b/src/status_im/ui/screens/keycard/onboarding/views.cljs @@ -11,13 +11,14 @@ [status-im.ui.components.topbar :as topbar] [status-im.ui.screens.keycard.pin.views :as pin.views] [status-im.ui.screens.keycard.styles :as styles] + [status-im.ui.components.checkbox.view :as checkbox] [quo.core :as quo] [status-im.constants :as constants]) (:require-macros [status-im.utils.views :refer [defview letsubs]])) (defview intro [] (letsubs [flow [:keycard-flow] - {:keys [from-key-storage-and-migration?]} [:keycard]] + {:keys [from-key-storage-and-migration? factory-reset-card?]} [:keycard]] [react/view styles/container (when-not from-key-storage-and-migration? [topbar/topbar]) @@ -86,6 +87,11 @@ [react/text {:style {:color colors/gray :padding-right 35}} text]]]]))] + [react/view {:style {:flex-direction :row}} + [checkbox/checkbox {:checked? factory-reset-card? + :style {:margin-right 10} + :on-value-change #(re-frame/dispatch [:keycard.onboarding.intro.ui/factory-reset-card-toggle %])}] + [react/text (i18n/label :t/keycard-factory-reset)]] [react/view {:margin-bottom 40} [quo/button {:on-press #(re-frame/dispatch [:keycard.onboarding.intro.ui/begin-setup-pressed])} (i18n/label :t/begin-set-up)]]]])) diff --git a/translations/en.json b/translations/en.json index b68c4a3124..07b30e2993 100644 --- a/translations/en.json +++ b/translations/en.json @@ -714,6 +714,9 @@ "keycard-desc": "Own a Keycard? Store your keys on it; you’ll need it for transactions", "keycard-dont-ask-card": "Don't ask for card to sign in", "keycard-reset-passcode": "Reset passcode", + "keycard-factory-reset": "Return card to factory settings", + "keycard-factory-reset-title": "Are you sure you want to perform a factory reset?", + "keycard-factory-reset-text": "Performing this will delete any mnemonic phrase stored on the card. Make sure you have a backup of the mnemonic phrase you've been using with this Keycard.", "keycard-enter-new-passcode": "Enter new passcode {{step}}/2", "keycard-has-multiaccount-on-it": "This card is full. Each card can hold one main keypair", "keycard-onboarding-finishing-header": "Finishing up", diff --git a/yarn.lock b/yarn.lock index 6ee88b180d..ca6a92d9d6 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.34": - version "2.5.34" - resolved "git+https://github.com/status-im/react-native-status-keycard.git#b9f242aa11afbb6a79c269459c48e32a6091176c" +"react-native-status-keycard@git+https://github.com/status-im/react-native-status-keycard.git#v2.5.35": + version "2.5.35" + resolved "git+https://github.com/status-im/react-native-status-keycard.git#8cf7cbff803b080b2069202ea6179703b8c69d2e" react-native-svg@^9.8.4: version "9.13.6"