|
6 | 6 | [status-im2.constants :as constants]
|
7 | 7 | [status-im2.contexts.profile.create.events :as profile.create]
|
8 | 8 | [status-im2.contexts.profile.recover.events :as profile.recover]
|
9 |
| - [status-im2.navigation.state :as state] |
10 | 9 | [taoensso.timbre :as log]
|
11 | 10 | [utils.i18n :as i18n]
|
12 | 11 | [utils.re-frame :as rf]
|
|
36 | 35 | {:biometric/authenticate {:on-success #(rf/dispatch [:onboarding-2/biometrics-done])
|
37 | 36 | :on-fail #(rf/dispatch [:onboarding-2/biometrics-fail %])}})
|
38 | 37 |
|
39 |
| -(rf/defn enable-biometrics-auth |
40 |
| - {:events [:onboarding-2/enable-biometrics-auth]} |
| 38 | +(rf/defn authenticate-enable-biometrics |
| 39 | + {:events [:onboarding-2/authenticate-enable-biometrics]} |
41 | 40 | [{:keys [db]} password]
|
42 |
| - {:db (assoc-in db [:onboarding-2/profile :password] password) |
| 41 | + {:db (-> db |
| 42 | + (assoc-in [:onboarding-2/profile :password] password) |
| 43 | + (assoc-in [:onboarding-2/profile :syncing?] true)) |
43 | 44 | :biometric/authenticate {:on-success #(rf/dispatch [:onboarding-2/biometrics-done])
|
44 | 45 | :on-fail #(rf/dispatch [:onboarding-2/biometrics-fail %])}})
|
45 | 46 |
|
46 | 47 | (rf/defn navigate-to-enable-notifications
|
47 | 48 | {:events [:onboarding-2/navigate-to-enable-notifications]}
|
48 | 49 | [{:keys [db]}]
|
49 | 50 | (let [key-uid (get-in db [:profile/profile :key-uid])]
|
50 |
| - {:dispatch [:navigate-to-within-stack [:enable-notifications :enable-biometrics]]})) |
| 51 | + {:db (dissoc db :onboarding-2/profile) |
| 52 | + :dispatch [:navigate-to-within-stack [:enable-notifications :enable-biometrics]]})) |
51 | 53 |
|
52 | 54 | (rf/defn biometrics-done
|
53 | 55 | {:events [:onboarding-2/biometrics-done]}
|
54 | 56 | [{:keys [db]}]
|
55 |
| - {:db (assoc-in db [:onboarding-2/profile :auth-method] constants/auth-method-biometric) |
56 |
| - :dispatch (if (= :syncing-results @state/root-id) |
57 |
| - [:onboarding-2/finalize-setup] |
58 |
| - [: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])})) |
59 | 62 |
|
60 | 63 | (rf/defn biometrics-fail
|
61 | 64 | {:events [:onboarding-2/biometrics-fail]}
|
|
144 | 147 | [{:keys [db]}]
|
145 | 148 | (let [masked-password (get-in db [:onboarding-2/profile :password])
|
146 | 149 | key-uid (get-in db [:profile/profile :key-uid])
|
| 150 | + syncing? (get-in db [:onboarding-2/profile :syncing?]) |
147 | 151 | biometric-enabled? (= (get-in db [:onboarding-2/profile :auth-method])
|
148 | 152 | constants/auth-method-biometric)]
|
149 |
| - (js/console.log (str "masked password" masked-password)) |
150 | 153 | (cond-> {:db (assoc db :onboarding-2/generated-keys? true)}
|
151 | 154 | biometric-enabled?
|
152 | 155 | (assoc :keychain/save-password-and-auth-method
|
153 | 156 | {:key-uid key-uid
|
154 | 157 | :masked-password masked-password
|
155 |
| - :on-success #(rf/dispatch [:navigate-to-within-stack |
156 |
| - [:enable-notifications :enable-biometrics]]) |
| 158 | + :on-success (fn [] |
| 159 | + (if syncing? |
| 160 | + (rf/dispatch [:onboarding-2/navigate-to-enable-notifications]) |
| 161 | + (log/error "successfully saved biometrics"))) |
157 | 162 | :on-error #(log/error "failed to save biometrics"
|
158 | 163 | {:key-uid key-uid
|
159 | 164 | :error %})}))))
|
|
0 commit comments