Skip to content

Commit ed10ed7

Browse files
authored
[#21993] Keycard - Unlock Keycard (#22030)
1 parent 8c089bb commit ed10ed7

File tree

11 files changed

+221
-33
lines changed

11 files changed

+221
-33
lines changed

src/status_im/contexts/keycard/backup/events.cljs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{:theme :dark
3232
:on-error
3333
(fn [error]
34-
(if (= error :keycard/error.keycard-blank)
34+
(if (= error :keycard/error.keycard-empty)
3535
(rf/dispatch [:keycard/backup.generate-and-load-key])
3636
(ready-to-add-not-empty error)))}]]]}))
3737

@@ -52,7 +52,7 @@
5252
{:theme :dark
5353
:on-error
5454
(fn [error]
55-
(if (= error :keycard/error.keycard-blank)
55+
(if (= error :keycard/error.keycard-empty)
5656
(do
5757
(rf/dispatch [:keycard/disconnect])
5858
(rf/dispatch [:keycard/backup.create-or-enter-pin]))
@@ -78,7 +78,7 @@
7878
{:theme :dark
7979
:on-error
8080
(fn [error]
81-
(if (= error :keycard/error.keycard-blank)
81+
(if (= error :keycard/error.keycard-empty)
8282
(rf/dispatch
8383
[:keycard/verify-pin
8484
{:pin pin
@@ -95,15 +95,15 @@
9595
{:theme :dark
9696
:on-error
9797
(fn [error]
98-
(if (= error :keycard/error.keycard-blank)
98+
(if (= error :keycard/error.keycard-empty)
9999
(rf/dispatch
100100
[:keycard/init-card
101101
{:pin pin
102102
:on-success #(rf/dispatch
103103
[:keycard/get-application-info
104104
{:on-error
105105
(fn [error]
106-
(if (= error :keycard/error.keycard-blank)
106+
(if (= error :keycard/error.keycard-empty)
107107
(save-pin-and-navigate-to-phrase pin)
108108
(init-card-not-empty pin error)))}])}])
109109
(init-card-not-empty pin error)))}]))

src/status_im/contexts/keycard/check/events.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
:on-error
1919
(fn [error]
2020
(rf/dispatch [:navigate-back])
21-
(if (and (= error :keycard/error.keycard-blank)
21+
(if (and (= error :keycard/error.keycard-empty)
2222
(not keycard-profile?))
2323
(do
2424
(rf/dispatch [:keycard/disconnect])

src/status_im/contexts/keycard/create/events.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
{:theme :dark
1111
:on-error
1212
(fn [error]
13-
(if (= error :keycard/error.keycard-blank)
13+
(if (= error :keycard/error.keycard-empty)
1414
(do
1515
(rf/dispatch [:keycard/disconnect])
1616
(rf/dispatch [:open-modal :screen/keycard.empty-create]))
@@ -74,7 +74,7 @@
7474

7575
(rf/reg-event-fx :keycard/create.on-application-info-error
7676
(fn [{:keys [db]} [error]]
77-
(if (or (= error :keycard/error.keycard-blank)
77+
(if (or (= error :keycard/error.keycard-empty)
7878
(and (get-in db [:keycard :application-info :initialized?])
7979
(= error :keycard/error.keycard-wrong-profile)))
8080
(rf/dispatch [:keycard/create.continue])

src/status_im/contexts/keycard/error/view.cljs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
[status-im.common.events-helper :as events-helper]
55
[status-im.contexts.keycard.backup.view :as backup.view]
66
[status-im.contexts.keycard.factory-reset.view :as factory-reset]
7+
[status-im.contexts.keycard.unblock.view :as keycard.unblock]
78
[utils.i18n :as i18n]
89
[utils.re-frame :as rf]))
910

1011
(def titles
11-
{:keycard/error.keycard-blank {:title (i18n/label :t/keycard-empty)
12+
{:keycard/error.keycard-empty {:title (i18n/label :t/keycard-empty)
1213
:description (i18n/label :t/no-key-pair-keycard)}
1314
:keycard/error.keycard-wrong-profile {:title (i18n/label :t/keycard-not-empty)
1415
:description (i18n/label :t/cant-store-new-keys)}
@@ -35,7 +36,7 @@
3536
[quo/keycard {:holder-name ""}]
3637
[quo/section-label
3738
{:section (i18n/label :t/what-you-can-do) :container-style {:padding-vertical 8}}]
38-
(if (= error :keycard/error.keycard-blank)
39+
(if (= error :keycard/error.keycard-empty)
3940
[quo/settings-item
4041
{:title (i18n/label :t/use-backup-keycard)
4142
:image :icon
@@ -51,15 +52,28 @@
5152
{:on-continue
5253
(rf/dispatch
5354
[:keycard/backup.create-or-enter-pin])}])}]))}]
54-
[quo/settings-item
55-
{:title (i18n/label :t/factory-reset)
56-
:image :icon
57-
:image-props :i/placeholder
58-
:action :arrow
59-
:description :text
60-
:description-props {:text (i18n/label :t/remove-keycard-content)}
61-
:on-press (fn []
62-
(rf/dispatch [:show-bottom-sheet
63-
{:theme :dark
64-
:shell? true
65-
:content factory-reset/sheet}]))}])]]))
55+
[:<>
56+
(when (or (= error :keycard/error.keycard-frozen)
57+
(= error :keycard/error.keycard-locked))
58+
[quo/settings-item
59+
{:title (i18n/label :t/unblock-keycard)
60+
:image :icon
61+
:image-props :i/placeholder
62+
:action :arrow
63+
:description :text
64+
:description-props {:text (i18n/label :t/with-recovery-phrase)}
65+
:on-press (fn []
66+
(rf/dispatch [:show-bottom-sheet
67+
{:content keycard.unblock/sheet}]))}])
68+
[quo/settings-item
69+
{:title (i18n/label :t/factory-reset)
70+
:image :icon
71+
:image-props :i/placeholder
72+
:action :arrow
73+
:description :text
74+
:description-props {:text (i18n/label :t/remove-keycard-content)}
75+
:on-press (fn []
76+
(rf/dispatch [:show-bottom-sheet
77+
{:theme :dark
78+
:shell? true
79+
:content factory-reset/sheet}]))}]])]]))

src/status_im/contexts/keycard/events.cljs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
status-im.contexts.keycard.nfc.sheets.events
1111
status-im.contexts.keycard.pin.events
1212
status-im.contexts.keycard.sign.events
13+
status-im.contexts.keycard.unblock.events
1314
[status-im.contexts.keycard.utils :as keycard.utils]
1415
[utils.address :as address]
1516
utils.datetime
@@ -160,14 +161,22 @@
160161
(rf/dispatch [:keycard/on-application-info-error
161162
:keycard/error.not-keycard]))))}}))
162163

164+
(rf/reg-event-fx :keycard/connect.next-stage
165+
(fn [{:keys [db]} [{:keys [key-uid on-success on-error]}]]
166+
(let [event-vector [:keycard/get-application-info
167+
{:key-uid key-uid
168+
:on-success on-success
169+
:on-error on-error}]]
170+
{:db (assoc-in db [:keycard :on-card-connected-event-vector] event-vector)
171+
:fx [(when (get-in db [:keycard :card-connected?])
172+
[:dispatch event-vector])]})))
173+
163174
(rf/reg-event-fx :keycard/connect
164-
(fn [{:keys [db]} [{:keys [key-uid on-success on-error on-connect-event-vector theme]}]]
165-
(let [event-vector
166-
(or on-connect-event-vector
167-
[:keycard/get-application-info
168-
{:key-uid key-uid
169-
:on-success on-success
170-
:on-error on-error}])]
175+
(fn [{:keys [db]} [{:keys [key-uid on-success on-error theme]}]]
176+
(let [event-vector [:keycard/get-application-info
177+
{:key-uid key-uid
178+
:on-success on-success
179+
:on-error on-error}]]
171180
{:db (assoc-in db [:keycard :on-card-connected-event-vector] event-vector)
172181
:fx [[:dispatch
173182
[:keycard/show-connection-sheet

src/status_im/contexts/keycard/migrate/events.cljs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
:on-success #(rf/dispatch [:keycard/migration.continue])
1111
:on-error
1212
(fn [error]
13-
(if (= error :keycard/error.keycard-blank)
13+
(if (= error :keycard/error.keycard-empty)
1414
(rf/dispatch [:keycard/migration.continue])
1515
(rf/dispatch [:keycard/on-application-info-error error])))}]))
1616

@@ -49,7 +49,7 @@
4949
:theme :dark
5050
:on-error
5151
(fn [error]
52-
(if (= error :keycard/error.keycard-blank)
52+
(if (= error :keycard/error.keycard-empty)
5353
(rf/dispatch [:keycard/migration.continue])
5454
(rf/dispatch [:keycard/on-application-info-error error])))}]]]}))
5555

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
(ns status-im.contexts.keycard.unblock.events
2+
(:require [utils.re-frame :as rf]
3+
[utils.security.core :as security]))
4+
5+
(rf/reg-event-fx :keycard/unblock.pin-created
6+
(fn [{:keys [db]} [pin]]
7+
{:db (assoc-in db [:keycard :unblock :pin] pin)
8+
:fx [[:dispatch [:navigate-back]]
9+
[:dispatch [:open-modal :screen/keycard.unblock.ready-to-unblock]]]}))
10+
11+
(rf/reg-event-fx :keycard/unblock.phrase-entered
12+
(fn [{:keys [db]} [{:keys [phrase]}]]
13+
{:db (assoc-in db [:keycard :unblock :masked-phrase] phrase)
14+
:fx [[:dispatch [:navigate-back]]
15+
[:dispatch
16+
[:open-modal :screen/keycard.pin.create
17+
{:on-complete #(rf/dispatch [:keycard/unblock.pin-created %])}]]]}))
18+
19+
(rf/reg-event-fx :keycard/unblock.generate-and-load-key
20+
(fn [{:keys [db]}]
21+
(let [{:keys [masked-phrase pin]} (get-in db [:keycard :unblock])]
22+
{:fx [[:effects.keycard/generate-and-load-key
23+
{:mnemonic (security/safe-unmask-data masked-phrase)
24+
:pin pin
25+
:on-success (fn []
26+
(rf/dispatch [:keycard/disconnect])
27+
(rf/dispatch [:navigate-back])
28+
(rf/dispatch [:open-modal :screen/keycard.unblock.success]))}]]})))
29+
30+
;; third stage, import keys
31+
(rf/reg-event-fx :keycard/unblock.import-keys
32+
(fn []
33+
{:fx [[:dispatch
34+
[:keycard/connect.next-stage
35+
{:on-error (fn [error]
36+
(if (= error :keycard/error.keycard-empty)
37+
(rf/dispatch [:keycard/unblock.generate-and-load-key])
38+
(do
39+
(rf/dispatch [:navigate-back])
40+
(rf/dispatch [:keycard/on-application-info-error error]))))}]]]}))
41+
42+
;; second stage, check if card initialized
43+
(rf/reg-event-fx :keycard/unblock.init-card-or-import-keys
44+
(fn [{:keys [db]}]
45+
(let [pin (get-in db [:keycard :unblock :pin])
46+
{:keys [initialized?]} (get-in db [:keycard :application-info])]
47+
{:fx [(if initialized?
48+
[:dispatch [:keycard/unblock.import-keys]]
49+
[:effects.keycard/init-card
50+
{:pin pin
51+
:on-success #(rf/dispatch [:keycard/unblock.import-keys])}])]})))
52+
53+
;; second stage, init card with pin
54+
(defn init-with-pin
55+
[]
56+
(rf/dispatch
57+
[:keycard/connect.next-stage
58+
{:on-error (fn [error]
59+
(if (= error :keycard/error.keycard-empty)
60+
(rf/dispatch [:keycard/unblock.init-card-or-import-keys])
61+
(do
62+
(rf/dispatch [:navigate-back])
63+
(rf/dispatch [:keycard/on-application-info-error error]))))}]))
64+
65+
;; first stage, reset card
66+
(rf/reg-event-fx :keycard/unblock
67+
(fn [{:keys [db]}]
68+
{:fx [[:dispatch
69+
[:keycard/connect
70+
{:key-uid (get-in db [:keycard :application-info :key-uid])
71+
:on-error (fn [error]
72+
(cond
73+
(or (= error :keycard/error.keycard-frozen)
74+
(= error :keycard/error.keycard-locked))
75+
(rf/dispatch [:keycard/factory-reset {:on-success init-with-pin}])
76+
77+
(= error :keycard/error.keycard-empty)
78+
(init-with-pin)
79+
80+
:else
81+
(do
82+
(rf/dispatch [:navigate-back])
83+
(if (= error :keycard/error.keycard-wrong-profile)
84+
(do
85+
(rf/dispatch [:keycard/disconnect])
86+
(rf/dispatch [:open-modal :screen/keycard.different-card]))
87+
(rf/dispatch [:keycard/on-application-info-error error])))))}]]]}))
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
(ns status-im.contexts.keycard.unblock.view
2+
(:require [quo.core :as quo]
3+
[react-native.core :as rn]
4+
[status-im.common.events-helper :as events-helper]
5+
[status-im.contexts.keycard.common.view :as common.view]
6+
[utils.i18n :as i18n]
7+
[utils.re-frame :as rf]))
8+
9+
(defn success-view
10+
[]
11+
[:<>
12+
[quo/page-nav
13+
{:icon-name :i/close
14+
:on-press events-helper/navigate-back}]
15+
[quo/page-top
16+
{:title (i18n/label :t/keycard-unblocked)}]
17+
[rn/view {:style {:flex 1}}]
18+
[rn/view {:style {:padding-horizontal 20}}
19+
[quo/button {:on-press events-helper/navigate-back}
20+
(i18n/label :t/done)]]])
21+
22+
(defn ready-to-unblock
23+
[]
24+
[:<>
25+
[quo/page-nav
26+
{:icon-name :i/close
27+
:on-press events-helper/navigate-back}]
28+
[quo/page-top
29+
{:title (i18n/label :t/ready-to-unblock-keycard)}]
30+
[rn/view {:style {:flex 1}}]
31+
[common.view/tips]
32+
[quo/bottom-actions
33+
{:actions :one-action
34+
:button-one-label (i18n/label :t/scan-keycard)
35+
:button-one-props {:on-press #(rf/dispatch [:keycard/unblock])}}]])
36+
37+
(defn sheet
38+
[]
39+
(let [customization-color (rf/sub [:profile/customization-color])]
40+
[:<>
41+
[quo/drawer-top {:title (i18n/label :t/unblock-keycard-recovery)}]
42+
[quo/text
43+
{:style {:padding-horizontal 20
44+
:padding-vertical 8}}
45+
(i18n/label :t/unblock-keycard-instructions)]
46+
[quo/bottom-actions
47+
{:actions :two-actions
48+
:button-one-label (i18n/label :t/continue)
49+
:button-one-props {:customization-color
50+
customization-color
51+
:on-press
52+
(fn []
53+
(rf/dispatch [:hide-bottom-sheet])
54+
(rf/dispatch [:navigate-back])
55+
(rf/dispatch
56+
[:open-modal :screen/use-recovery-phrase-dark
57+
{:on-success #(rf/dispatch [:keycard/unblock.phrase-entered %])}]))}
58+
:button-two-label (i18n/label :t/cancel)
59+
:button-two-props {:type :grey
60+
:on-press #(rf/dispatch [:hide-bottom-sheet])}}]]))

src/status_im/contexts/keycard/utils.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
:keycard/error.not-keycard
2929

3030
(not has-master-key?)
31-
:keycard/error.keycard-blank
31+
:keycard/error.keycard-empty
3232

3333
(and (zero? pin-retry-counter)
3434
(or (nil? puk-retry-counter)

src/status_im/navigation/screens.cljs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
[status-im.contexts.keycard.not-keycard.view :as keycard.not-keycard]
4949
[status-im.contexts.keycard.pin.create.view :as keycard.pin.create]
5050
[status-im.contexts.keycard.pin.enter.view :as keycard.pin.enter]
51+
[status-im.contexts.keycard.unblock.view :as keycard.unblock]
5152
[status-im.contexts.onboarding.create-password.view :as create-password]
5253
[status-im.contexts.onboarding.create-profile.view :as create-profile]
5354
[status-im.contexts.onboarding.enable-biometrics.view :as enable-biometrics]
@@ -1097,8 +1098,19 @@
10971098
:options {:theme :dark
10981099
:modalPresentationStyle :fullScreen
10991100
:insets {:top? true :bottom? true}}
1100-
:component keycard.backup/success-view}])
1101+
:component keycard.backup/success-view}
11011102

1103+
{:name :screen/keycard.unblock.ready-to-unblock
1104+
:metrics {:track? true}
1105+
:options {:insets {:top? true :bottom? true}
1106+
:modalPresentationStyle :fullScreen}
1107+
:component keycard.unblock/ready-to-unblock}
1108+
1109+
{:name :screen/keycard.unblock.success
1110+
:metrics {:track? true}
1111+
:options {:insets {:top? true :bottom? true}
1112+
:modalPresentationStyle :fullScreen}
1113+
:component keycard.unblock/success-view}])
11021114

11031115
(defn screens
11041116
[]

0 commit comments

Comments
 (0)