Skip to content

add factory reset option on new Keycard account #12055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ios/StatusIm/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<array>
<string>A00000080400010101</string>
<string>A00000080400010301</string>
<string>A000000151000000</string>
</array>
<key>NFCReaderUsageDescription</key>
<string>Enable Keycard</string>
Expand Down
1 change: 1 addition & 0 deletions ios/StatusImPR/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<array>
<string>A00000080400010101</string>
<string>A00000080400010301</string>
<string>A000000151000000</string>
</array>
<key>NFCReaderUsageDescription</key>
<string>Enable Keycard</string>
Expand Down
1 change: 1 addition & 0 deletions ios/StatusImTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<array>
<string>A00000080400010101</string>
<string>A00000080400010301</string>
<string>A000000151000000</string>
</array>
<key>NFCReaderUsageDescription</key>
<string>Enable Keycard</string>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions src/status_im/keycard/card.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/status_im/keycard/common.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/status_im/keycard/fx.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 0 additions & 34 deletions src/status_im/keycard/ios_keycard.cljs

This file was deleted.

1 change: 1 addition & 0 deletions src/status_im/keycard/keycard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
38 changes: 32 additions & 6 deletions src/status_im/keycard/onboarding.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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}]
Expand All @@ -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]}
Expand Down
13 changes: 13 additions & 0 deletions src/status_im/keycard/real_keycard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Copy link
Contributor

@shivekkhurana shivekkhurana May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does catch work without a try block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the same pattern is used throughout the file and the error handlers are known to work. I would leave it like this for consistency. Thanks for the review!


(defn install-applet [{:keys [on-success on-failure]}]
(.. status-keycard
installApplet
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions src/status_im/keycard/simulated_keycard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [_])

Expand Down Expand Up @@ -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))
Expand Down
8 changes: 7 additions & 1 deletion src/status_im/ui/screens/keycard/onboarding/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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)]]]]))
Expand Down
3 changes: 3 additions & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down