Skip to content

Commit 3e4ef18

Browse files
committed
enable biometric when user signs in with syncing
1 parent 8f8c8de commit 3e4ef18

File tree

11 files changed

+186
-68
lines changed

11 files changed

+186
-68
lines changed
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(ns status-im2.common.standard-authentication.core
2+
(:require
3+
status-im2.common.standard-authentication.standard-auth.button.view
4+
status-im2.common.standard-authentication.standard-auth.slide-button.view))
5+
6+
(def button status-im2.common.standard-authentication.standard-auth.button.view/view)
7+
(def slide-button status-im2.common.standard-authentication.standard-auth.slide-button.view/view)
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
(ns status-im2.common.standard-authentication.standard-auth.view
1+
(ns status-im2.common.standard-authentication.standard-auth.authorize
22
(:require
3-
[quo.core :as quo]
4-
[quo.theme :as quo.theme]
5-
[react-native.core :as rn]
63
[react-native.touch-id :as biometric]
7-
[reagent.core :as reagent]
84
[status-im2.common.standard-authentication.enter-password.view :as enter-password]
95
[taoensso.timbre :as log]
106
[utils.i18n :as i18n]
@@ -46,39 +42,3 @@
4642
{:on-enter-password on-enter-password
4743
:button-icon-left auth-button-icon-left
4844
:button-label auth-button-label}])}]))))))
49-
50-
(defn- view-internal
51-
[_]
52-
(let [reset-slider? (reagent/atom false)
53-
on-close #(reset! reset-slider? true)]
54-
(fn [{:keys [biometric-auth?
55-
track-text
56-
customization-color
57-
auth-button-label
58-
on-enter-password
59-
on-auth-success
60-
on-auth-fail
61-
auth-button-icon-left
62-
size
63-
theme
64-
blur?
65-
container-style]}]
66-
[rn/view {:style {:flex 1}}
67-
[quo/slide-button
68-
{:size size
69-
:container-style container-style
70-
:customization-color customization-color
71-
:on-reset (when @reset-slider? #(reset! reset-slider? false))
72-
:on-complete #(authorize {:on-close on-close
73-
:auth-button-icon-left auth-button-icon-left
74-
:theme theme
75-
:blur? blur?
76-
:on-enter-password on-enter-password
77-
:biometric-auth? biometric-auth?
78-
:on-auth-success on-auth-success
79-
:on-auth-fail on-auth-fail
80-
:auth-button-label auth-button-label})
81-
:track-icon (if biometric-auth? :i/face-id :password)
82-
:track-text track-text}]])))
83-
84-
(def view (quo.theme/with-theme view-internal))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
(ns status-im2.common.standard-authentication.standard-auth.button.view
2+
(:require
3+
[quo.core :as quo]
4+
[quo.theme :as quo.theme]
5+
[reagent.core :as reagent]
6+
[status-im2.common.standard-authentication.standard-auth.authorize :as authorize]))
7+
8+
(defn- view-internal
9+
[_]
10+
(let [reset-slider? (reagent/atom false)
11+
on-close #(reset! reset-slider? true)]
12+
(fn [{:keys [biometric-auth?
13+
customization-color
14+
auth-button-label
15+
on-enter-password
16+
on-auth-success
17+
on-press
18+
on-auth-fail
19+
auth-button-icon-left
20+
size
21+
button-label
22+
theme
23+
blur?
24+
container-style
25+
icon-left]}]
26+
[quo/button
27+
{:size size
28+
:container-style container-style
29+
:customization-color customization-color
30+
:icon-left icon-left
31+
:on-press (if on-press
32+
on-press
33+
#(authorize/authorize {:on-close on-close
34+
:auth-button-icon-left auth-button-icon-left
35+
:theme theme
36+
:blur? blur?
37+
:on-enter-password on-enter-password
38+
:biometric-auth? biometric-auth?
39+
:on-auth-success on-auth-success
40+
:on-auth-fail on-auth-fail
41+
:auth-button-label auth-button-label}))}
42+
button-label])))
43+
44+
(def view (quo.theme/with-theme view-internal))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
(ns status-im2.common.standard-authentication.standard-auth.slide-button.view
2+
(:require
3+
[quo.core :as quo]
4+
[quo.theme :as quo.theme]
5+
[react-native.core :as rn]
6+
[reagent.core :as reagent]
7+
[status-im2.common.standard-authentication.standard-auth.authorize :as authorize]))
8+
9+
(defn- view-internal
10+
[_]
11+
(let [reset-slider? (reagent/atom false)
12+
on-close #(reset! reset-slider? true)]
13+
(fn [{:keys [biometric-auth?
14+
track-text
15+
customization-color
16+
auth-button-label
17+
on-enter-password
18+
on-auth-success
19+
on-auth-fail
20+
auth-button-icon-left
21+
size
22+
theme
23+
blur?
24+
container-style]}]
25+
[rn/view {:style {:flex 1}}
26+
[quo/slide-button
27+
{:size size
28+
:container-style container-style
29+
:customization-color customization-color
30+
:on-reset (when @reset-slider? #(reset! reset-slider? false))
31+
:on-complete #(authorize/authorize {:on-close on-close
32+
:auth-button-icon-left auth-button-icon-left
33+
:theme theme
34+
:blur? blur?
35+
:on-enter-password on-enter-password
36+
:biometric-auth? biometric-auth?
37+
:on-auth-success on-auth-success
38+
:on-auth-fail on-auth-fail
39+
:auth-button-label auth-button-label})
40+
:track-icon (if biometric-auth? :i/face-id :password)
41+
:track-text track-text}]])))
42+
43+
(def view (quo.theme/with-theme view-internal))

Diff for: src/status_im2/contexts/onboarding/enable_biometrics/view.cljs

+42-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
(ns status-im2.contexts.onboarding.enable-biometrics.view
22
(:require
33
[quo.core :as quo]
4+
[quo.theme :as quo.theme]
45
[react-native.core :as rn]
56
[react-native.safe-area :as safe-area]
67
[status-im2.common.biometric.events :as biometric]
78
[status-im2.common.parallax.view :as parallax]
89
[status-im2.common.parallax.whitelist :as whitelist]
910
[status-im2.common.resources :as resources]
11+
[status-im2.common.standard-authentication.core :as standard-auth]
1012
[status-im2.contexts.onboarding.enable-biometrics.style :as style]
13+
[status-im2.navigation.state :as state]
1114
[utils.i18n :as i18n]
12-
[utils.re-frame :as rf]))
15+
[utils.re-frame :as rf]
16+
[utils.security.core :as security]))
17+
1318

1419
(defn page-title
1520
[]
@@ -21,22 +26,39 @@
2126
:description-accessibility-label :enable-biometrics-sub-title}])
2227

2328
(defn enable-biometrics-buttons
24-
[insets]
29+
[insets theme]
2530
(let [supported-biometric-type (rf/sub [:biometric/supported-type])
2631
bio-type-label (biometric/get-label-by-type supported-biometric-type)
27-
profile-color (:color (rf/sub [:onboarding-2/profile]))]
32+
profile-color (or (:color (rf/sub [:onboarding-2/profile]))
33+
(rf/sub [:profile/customization-color]))
34+
syncing-results? (= :syncing-results @state/root-id)]
2835
[rn/view {:style (style/buttons insets)}
29-
[quo/button
30-
{:accessibility-label :enable-biometrics-button
31-
:on-press #(rf/dispatch [:onboarding-2/enable-biometrics])
32-
:icon-left :i/face-id
33-
:customization-color profile-color}
34-
(i18n/label :t/biometric-enable-button {:bio-type-label bio-type-label})]
36+
[standard-auth/button
37+
(merge
38+
{:size 40
39+
:accessibility-label :enable-biometrics-button
40+
:icon-left :i/face-id
41+
:customization-color profile-color
42+
:button-label (i18n/label :t/biometric-enable-button {:bio-type-label bio-type-label})}
43+
(if syncing-results?
44+
{:theme theme
45+
:blur? true
46+
:on-enter-password (fn [entered-password]
47+
(rf/dispatch
48+
[:onboarding-2/authenticate-enable-biometrics
49+
(security/safe-unmask-data
50+
entered-password)])
51+
(rf/dispatch [:hide-bottom-sheet]))
52+
:auth-button-label (i18n/label :t/confirm)}
53+
{:on-press #(rf/dispatch [:onboarding-2/enable-biometrics])}))]
3554
[quo/button
3655
{:accessibility-label :maybe-later-button
3756
:background :blur
3857
:type :grey
39-
:on-press #(rf/dispatch [:onboarding-2/create-account-and-login])
58+
:on-press #(rf/dispatch (if syncing-results?
59+
[:navigate-to-within-stack
60+
[:enable-notifications :enable-biometrics]]
61+
[:onboarding-2/create-account-and-login]))
4062
:container-style {:margin-top 12}}
4163
(i18n/label :t/maybe-later)]]))
4264

@@ -55,12 +77,19 @@
5577
:style (style/page-illustration width)
5678
:source (resources/get-image :biometrics)}]))
5779

58-
(defn enable-biometrics
59-
[]
80+
(defn f-enable-biometrics
81+
[{:keys [theme]}]
6082
(let [insets (safe-area/get-insets)]
6183
[rn/view {:style (style/page-container insets)}
6284
[page-title]
6385
(if whitelist/whitelisted?
6486
[enable-biometrics-parallax]
6587
[enable-biometrics-simple])
66-
[enable-biometrics-buttons insets]]))
88+
[enable-biometrics-buttons insets theme]]))
89+
90+
91+
(defn- internale-enable-biometrics
92+
[params]
93+
[:f> f-enable-biometrics params])
94+
95+
(def view (quo.theme/with-theme internale-enable-biometrics))

Diff for: src/status_im2/contexts/onboarding/enable_notifications/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
[quo/page-nav
5252
{:background :blur
5353
:icon-name :i/arrow-left
54-
:on-press #(rf/dispatch [:navigate-back-within-stack :new-to-status])}]
54+
:on-press #(rf/dispatch [:navigate-back-within-stack :enable-biometrics])}]
5555
[page-title]
5656
[rn/view {:style style/page-illustration}
5757
[quo/text

Diff for: src/status_im2/contexts/onboarding/events.cljs

+34-3
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,30 @@
3535
{:biometric/authenticate {:on-success #(rf/dispatch [:onboarding-2/biometrics-done])
3636
:on-fail #(rf/dispatch [:onboarding-2/biometrics-fail %])}})
3737

38+
(rf/defn authenticate-enable-biometrics
39+
{:events [:onboarding-2/authenticate-enable-biometrics]}
40+
[{:keys [db]} password]
41+
{:db (-> db
42+
(assoc-in [:onboarding-2/profile :password] password)
43+
(assoc-in [:onboarding-2/profile :syncing?] true))
44+
:biometric/authenticate {:on-success #(rf/dispatch [:onboarding-2/biometrics-done])
45+
:on-fail #(rf/dispatch [:onboarding-2/biometrics-fail %])}})
46+
47+
(rf/defn navigate-to-enable-notifications
48+
{:events [:onboarding-2/navigate-to-enable-notifications]}
49+
[{:keys [db]}]
50+
(let [key-uid (get-in db [:profile/profile :key-uid])]
51+
{:db (dissoc db :onboarding-2/profile)
52+
:dispatch [:navigate-to-within-stack [:enable-notifications :enable-biometrics]]}))
53+
3854
(rf/defn biometrics-done
3955
{:events [:onboarding-2/biometrics-done]}
4056
[{:keys [db]}]
41-
{:db (assoc-in db [:onboarding-2/profile :auth-method] constants/auth-method-biometric)
42-
:dispatch [:onboarding-2/create-account-and-login]})
57+
(let [syncing? (get-in db [:onboarding-2/profile :syncing?])]
58+
{:db (assoc-in db [:onboarding-2/profile :auth-method] constants/auth-method-biometric)
59+
:dispatch (if syncing?
60+
[:onboarding-2/finalize-setup]
61+
[:onboarding-2/create-account-and-login])}))
4362

4463
(rf/defn biometrics-fail
4564
{:events [:onboarding-2/biometrics-fail]}
@@ -83,6 +102,14 @@
83102
[:navigate-to-within-stack [:enable-biometrics :new-to-status]]
84103
[:onboarding-2/create-account-and-login])}))
85104

105+
(rf/defn navigate-to-enable-biometrics
106+
{:events [:onboarding-2/navigate-to-enable-biometrics]}
107+
[{:keys [db]}]
108+
(let [supported-type (:biometric/supported-type db)]
109+
{:dispatch (if supported-type
110+
[:open-modal :enable-biometrics]
111+
[:open-modal :enable-notifications])}))
112+
86113
(rf/defn seed-phrase-entered
87114
{:events [:onboarding-2/seed-phrase-entered]}
88115
[_ seed-phrase on-error]
@@ -120,14 +147,18 @@
120147
[{:keys [db]}]
121148
(let [masked-password (get-in db [:onboarding-2/profile :password])
122149
key-uid (get-in db [:profile/profile :key-uid])
150+
syncing? (get-in db [:onboarding-2/profile :syncing?])
123151
biometric-enabled? (= (get-in db [:onboarding-2/profile :auth-method])
124152
constants/auth-method-biometric)]
125153
(cond-> {:db (assoc db :onboarding-2/generated-keys? true)}
126154
biometric-enabled?
127155
(assoc :keychain/save-password-and-auth-method
128156
{:key-uid key-uid
129157
:masked-password masked-password
130-
:on-success #(log/debug "successfully saved biometric")
158+
:on-success (fn []
159+
(if syncing?
160+
(rf/dispatch [:onboarding-2/navigate-to-enable-notifications])
161+
(log/error "successfully saved biometrics")))
131162
:on-error #(log/error "failed to save biometrics"
132163
{:key-uid key-uid
133164
:error %})}))))

Diff for: src/status_im2/contexts/onboarding/syncing/results/view.cljs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
{:on-press (fn []
5555
(when on-press
5656
(on-press))
57-
(rf/dispatch [:open-modal :enable-notifications]))
57+
(rf/dispatch [:onboarding-2/navigate-to-enable-biometrics]))
5858
:accessibility-label :continue-button
5959
:customization-color profile-color
6060
:container-style style/continue-button}

Diff for: src/status_im2/contexts/syncing/setup_syncing/view.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[reagent.core :as reagent]
99
[status-im2.common.qr-codes.view :as qr-codes]
1010
[status-im2.common.resources :as resources]
11-
[status-im2.common.standard-authentication.standard-auth.view :as standard-auth]
11+
[status-im2.common.standard-authentication.core :as standard-auth]
1212
[status-im2.contexts.syncing.setup-syncing.style :as style]
1313
[status-im2.contexts.syncing.utils :as sync-utils]
1414
[utils.datetime :as datetime]
@@ -119,7 +119,7 @@
119119
(i18n/label :t/copy-qr)]])
120120
(when-not (sync-utils/valid-connection-string? @code)
121121
[rn/view {:style style/standard-auth}
122-
[standard-auth/view
122+
[standard-auth/slide-button
123123
{:blur? true
124124
:size :size-40
125125
:track-text (i18n/label :t/slide-to-reveal-code)

Diff for: src/status_im2/contexts/wallet/create_account/view.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[react-native.core :as rn]
88
[react-native.safe-area :as safe-area]
99
[reagent.core :as reagent]
10-
[status-im2.common.standard-authentication.standard-auth.view :as standard-auth]
10+
[status-im2.common.standard-authentication.core :as standard-auth]
1111
[status-im2.constants :as constants]
1212
[status-im2.contexts.emoji-picker.utils :as emoji-picker.utils]
1313
[status-im2.contexts.wallet.common.utils :as utils]
@@ -114,7 +114,7 @@
114114
{:list-type :settings
115115
:label (i18n/label :t/origin)
116116
:data (get-keypair-data primary-name @derivation-path @account-color)}]
117-
[standard-auth/view
117+
[standard-auth/slide-button
118118
{:size :size-48
119119
:track-text (i18n/label :t/slide-to-create-account)
120120
:customization-color @account-color

Diff for: src/status_im2/navigation/screens.cljs

+9-5
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,15 @@
161161
:component create-password/create-password}
162162

163163
{:name :enable-biometrics
164-
:options {:theme :dark
165-
:layout options/onboarding-transparent-layout
166-
:animations transitions/push-animations-for-transparent-background
167-
:popGesture false}
168-
:component enable-biometrics/enable-biometrics}
164+
:options {:theme :dark
165+
:layout options/onboarding-transparent-layout
166+
:animations (merge transitions/new-to-status-modal-animations
167+
transitions/push-animations-for-transparent-background)
168+
:popGesture false
169+
:modalPresentationStyle :overCurrentContext
170+
:hardwareBackButton {:dismissModalOnPress false
171+
:popStackOnPress false}}
172+
:component enable-biometrics/view}
169173

170174
{:name :generating-keys
171175
:options {:theme :dark

0 commit comments

Comments
 (0)