|
10 | 10 | [utils.re-frame :as rf] |
11 | 11 | [utils.security.core :as security])) |
12 | 12 |
|
| 13 | +(defn- partially-operable-accounts? |
| 14 | + [accounts] |
| 15 | + (->> accounts |
| 16 | + vals |
| 17 | + (some #(= :partially (:operable %))) |
| 18 | + boolean)) |
| 19 | + |
| 20 | +(rf/reg-event-fx :standard-auth/migrate-partially-operable-accounts |
| 21 | + (fn [{:keys [db]} [{:keys [masked-password on-success]}]] |
| 22 | + (let [on-auth-success-callback #(on-success masked-password) |
| 23 | + has-partially-operable-accounts? (-> (get-in db [:wallet :accounts]) |
| 24 | + partially-operable-accounts?)] |
| 25 | + {:fx [(if has-partially-operable-accounts? |
| 26 | + [:dispatch |
| 27 | + [:wallet/make-partially-operable-accounts-fully-operable |
| 28 | + {:password masked-password |
| 29 | + :on-success on-auth-success-callback |
| 30 | + :on-error on-auth-success-callback}]] |
| 31 | + [:effects.standard-auth/on-auth-success on-auth-success-callback])]}))) |
| 32 | + |
13 | 33 | (defn- handle-password-success |
14 | | - [has-partially-operable-accounts? on-auth-success masked-password] |
| 34 | + [{:keys [migrate-partially-operable-accounts? on-auth-success masked-password]}] |
15 | 35 | (let [on-auth-success-callback #(on-auth-success masked-password)] |
16 | 36 | (rf/dispatch [:standard-auth/set-success true]) |
17 | 37 | (rf/dispatch [:standard-auth/reset-login-password]) |
18 | | - (if has-partially-operable-accounts? |
19 | | - (rf/dispatch [:wallet/make-partially-operable-accounts-fully-operable |
20 | | - {:password masked-password |
21 | | - :on-success on-auth-success-callback |
22 | | - :on-error on-auth-success-callback}]) |
| 38 | + (if migrate-partially-operable-accounts? |
| 39 | + (rf/dispatch [:standard-auth/migrate-partially-operable-accounts |
| 40 | + {:masked-password masked-password |
| 41 | + :on-success on-auth-success}]) |
23 | 42 | (on-auth-success-callback)))) |
24 | 43 |
|
25 | 44 | (defn authorize |
|
42 | 61 | {:pin pin |
43 | 62 | :on-success (fn [{:keys [encryption-public-key]}] |
44 | 63 | (rf/dispatch [:keycard/disconnect]) |
45 | | - (handle-password-success false |
46 | | - on-auth-success |
47 | | - (security/mask-data encryption-public-key))) |
| 64 | + (handle-password-success {:migrate-partially-operable-accounts? false |
| 65 | + :on-auth-success on-auth-success |
| 66 | + :masked-password (security/mask-data |
| 67 | + encryption-public-key)})) |
48 | 68 | :on-failure #(rf/dispatch [:keycard/on-action-with-pin-error |
49 | 69 | %])}]))}]))}]] |
50 | 70 | [:effects.biometric/check-if-available |
|
85 | 105 | keycard? (get-in db [:profile/profile :keycard-pairing])] |
86 | 106 | {:fx [(if keycard? |
87 | 107 | [:keychain/get-keycard-keys [key-uid on-auth-success]] |
88 | | - [:keychain/get-user-password [key-uid on-auth-success]]) |
| 108 | + [:keychain/get-user-password |
| 109 | + [key-uid |
| 110 | + (fn [masked-password] |
| 111 | + (rf/dispatch [:standard-auth/migrate-partially-operable-accounts |
| 112 | + {:masked-password masked-password |
| 113 | + :on-success on-auth-success}]))]]) |
89 | 114 | [:dispatch [:standard-auth/set-success true]] |
90 | 115 | [:dispatch [:standard-auth/reset-login-password]]]})) |
91 | 116 |
|
|
108 | 133 | (defn- bottom-sheet-password-view |
109 | 134 | [{:keys [on-press-biometric on-auth-success auth-button-icon-left auth-button-label]}] |
110 | 135 | (fn [] |
111 | | - (let [has-partially-operable-accounts? (rf/sub [:wallet/has-partially-operable-accounts?])] |
112 | | - [enter-password/view |
113 | | - {:on-enter-password #(handle-password-success |
114 | | - has-partially-operable-accounts? |
115 | | - on-auth-success |
116 | | - (security/hash-masked-password %)) |
117 | | - :on-press-biometrics on-press-biometric |
118 | | - :button-icon-left auth-button-icon-left |
119 | | - :button-label auth-button-label}]))) |
| 136 | + [enter-password/view |
| 137 | + {:on-enter-password #(handle-password-success {:migrate-partially-operable-accounts? true |
| 138 | + :on-auth-success on-auth-success |
| 139 | + :masked-password (security/hash-masked-password |
| 140 | + %)}) |
| 141 | + :on-press-biometrics on-press-biometric |
| 142 | + :button-icon-left auth-button-icon-left |
| 143 | + :button-label auth-button-label}])) |
120 | 144 |
|
121 | 145 | (defn authorize-with-keycard |
122 | 146 | [_ [{:keys [on-complete]}]] |
|
155 | 179 | (when on-close |
156 | 180 | (on-close success?)))) |
157 | 181 |
|
| 182 | +(rf/reg-fx |
| 183 | + :effects.standard-auth/on-auth-success |
| 184 | + (fn [on-auth-success] |
| 185 | + (when on-auth-success |
| 186 | + (on-auth-success)))) |
| 187 | + |
158 | 188 | (rf/reg-event-fx |
159 | 189 | :standard-auth/close |
160 | 190 | (fn [{:keys [db]} [on-close]] |
|
0 commit comments