Skip to content

Commit

Permalink
feat: biometry button on login screen
Browse files Browse the repository at this point in the history
  • Loading branch information
clauxx committed Dec 6, 2023
1 parent 5a74b91 commit ed5b192
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@
{:margin-top 8
:flex-direction :row
:align-items :center})

(def input-container
{:flex-direction :row
:align-items :flex-end})

(def input
{:flex 1
:margin-right 12})
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[quo.foundations.colors :as colors]
[quo.theme :as quo.theme]
[react-native.core :as rn]
[status-im2.common.keychain.events :as keychain]
[status-im2.common.standard-authentication.forgot-password-doc.view :as forgot-password-doc]
[status-im2.common.standard-authentication.password-input.style :as style]
[utils.i18n :as i18n]
Expand All @@ -29,19 +30,30 @@
(defn- view-internal
[{:keys [default-password theme shell?]}]
(let [{:keys [error processing]} (rf/sub [:profile/login])
auth-method (rf/sub [:auth-method])
error-message (get-error-message error)
error? (boolean (seq error-message))]
[:<>
[quo/input
{:type :password
:blur? true
:disabled? processing
:placeholder (i18n/label :t/type-your-password)
:auto-focus true
:error? error?
:label (i18n/label :t/profile-password)
:on-change-text on-change-password
:default-value (security/safe-unmask-data default-password)}]
[rn/view {:style style/input-container}
[quo/input
{:type :password
:blur? true
:container-style style/input
:disabled? processing
:placeholder (i18n/label :t/type-your-password)
:auto-focus true
:error? error?
:label (i18n/label :t/profile-password)
:on-change-text on-change-password
:default-value (security/safe-unmask-data default-password)}]
(when (= auth-method keychain/auth-method-biometric)
[quo/button
{:type :outline
:icon-only? true
:on-press #(rf/dispatch [:profile.login/biometric-auth])
:background :blur
:size 40}
:i/face-id])]
(when error?
[rn/view {:style style/error-message}
[quo/info-message
Expand Down
18 changes: 12 additions & 6 deletions src/status_im2/contexts/profile/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,25 @@
(rf/defn profile-selected
{:events [:profile/profile-selected]}
[{:keys [db]} key-uid]
{:db (update db
:profile/login
#(-> %
(assoc :key-uid key-uid)
(dissoc :error :password)))
:dispatch [:profile.login/login-with-biometric-if-available key-uid]})
{:db (update db
:profile/login
#(-> %
(assoc :key-uid key-uid)
(dissoc :error :password)))})

(rf/defn init-profiles-overview
[{:keys [db] :as cofx} profiles key-uid]
(rf/merge cofx
{:db (assoc db :profile/profiles-overview profiles)}
(profile-selected key-uid)))

(rf/reg-event-fx
:profile/switch-profile
(fn [{:keys [db]} [key-uid]]
{:db db
:fx [[:dispatch [:profile/profile-selected key-uid]]
[:dispatch [:profile.login/login-with-biometric-if-available key-uid]]]}))

(defn reduce-profiles
[profiles]
(reduce
Expand Down
17 changes: 10 additions & 7 deletions src/status_im2/contexts/profile/login/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,22 @@
{:keychain/get-auth-method [key-uid
#(rf/dispatch [:profile.login/get-auth-method-success % key-uid])]})

(rf/reg-event-fx
:profile.login/biometric-auth
(fn []
{:dispatch [:biometric/authenticate
{:on-success #(rf/dispatch [:profile.login/biometric-success])
:on-fail #(rf/dispatch
[:profile.login/biometric-auth-fail %])}]}))

(rf/defn get-auth-method-success
{:events [:profile.login/get-auth-method-success]}
[{:keys [db]} auth-method key-uid]
(merge {:db (assoc db :auth-method auth-method)}
(when (= auth-method keychain/auth-method-biometric)
{:keychain/password-hash-migration
{:key-uid key-uid
:callback (fn []
(rf/dispatch [:biometric/authenticate
{:on-success #(rf/dispatch [:profile.login/biometric-success])
:on-fail #(rf/dispatch
[:profile.login/biometric-auth-fail %])}]))}})))
:callback #(rf/dispatch [:profile.login/biometric-auth])}})))

;; result of :keychain/get-auth-method above
(rf/defn get-user-password-success
Expand All @@ -218,8 +222,7 @@
(fn [{:keys [db]} [code]]
(let [key-uid (get-in db [:profile/login :key-uid])]
{:db db
:fx [[:dispatch [:init-root :profiles]]
(if (= code "NOT_ENROLLED")
:fx [(if (= code "NOT_ENROLLED")
[:biometric/supress-not-enrolled-error
[key-uid
[:biometric/show-message code]]]
Expand Down
2 changes: 1 addition & 1 deletion src/status_im2/contexts/profile/profiles/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
:profile-picture profile-picture})
:on-card-press (fn []
(rf/dispatch
[:profile/profile-selected key-uid])
[:profile/switch-profile key-uid])
(when-not keycard-pairing (set-hide-profiles)))}]))

(defn- f-profiles-section
Expand Down

0 comments on commit ed5b192

Please sign in to comment.