Skip to content

Commit

Permalink
Lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
alwx committed Apr 19, 2024
1 parent 702da7a commit d379d80
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 244 deletions.
11 changes: 6 additions & 5 deletions src/status_im/contexts/onboarding/enable_biometrics/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
(defn enable-biometrics-buttons
[insets]
(let [supported-biometric-type (rf/sub [:biometrics/supported-type])
bio-type-label (biometric/get-label-by-type supported-biometric-type)
profile-color (or (:color (rf/sub [:onboarding/profile]))
(rf/sub [:profile/customization-color]))
syncing-results? (= :screen/onboarding.syncing-results @state/root-id)]
bio-type-label (biometric/get-label-by-type supported-biometric-type)
profile-color (or (:color (rf/sub [:onboarding/profile]))
(rf/sub [:profile/customization-color]))
syncing-results? (= :screen/onboarding.syncing-results @state/root-id)]
[rn/view {:style (style/buttons insets)}
[quo/button
{:size 40
Expand All @@ -38,7 +38,8 @@
:on-press (fn []
(rf/dispatch [:biometric/authenticate
{:on-success #(rf/dispatch [:onboarding/biometrics-done])
:on-fail #(rf/dispatch [:biometric/show-message (ex-cause %)])}]))}
:on-fail #(rf/dispatch [:biometric/show-message
(ex-cause %)])}]))}
(i18n/label :t/biometric-enable-button {:bio-type-label bio-type-label})]
[quo/button
{:accessibility-label :maybe-later-button
Expand Down
277 changes: 142 additions & 135 deletions src/status_im/contexts/onboarding/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
[native-module.core :as native-module]
[re-frame.core :as re-frame]
status-im.common.biometric.events
[status-im.common.emoji-picker.utils :as emoji-picker.utils]
[status-im.constants :as constants]
[status-im.contexts.profile.config :as profile.config]
[status-im.contexts.profile.create.events :as profile.create]
[status-im.contexts.profile.recover.events :as profile.recover]
[status-im.contexts.profile.utils :as profile.utils]
[taoensso.timbre :as log]
[utils.i18n :as i18n]
Expand All @@ -16,160 +12,171 @@
[utils.transforms :as transforms]))

(re-frame/reg-fx
:multiaccount/validate-mnemonic
(fn [[mnemonic on-success on-error]]
(native-module/validate-mnemonic
(security/safe-unmask-data mnemonic)
(fn [result]
(let [{:keys [error keyUID]} (transforms/json->clj result)]
(if (seq error)
(when on-error (on-error error))
(on-success mnemonic keyUID)))))))
:multiaccount/validate-mnemonic
(fn [[mnemonic on-success on-error]]
(native-module/validate-mnemonic
(security/safe-unmask-data mnemonic)
(fn [result]
(let [{:keys [error keyUID]} (transforms/json->clj result)]
(if (seq error)
(when on-error (on-error error))
(on-success mnemonic keyUID)))))))

(rf/reg-event-fx
:onboarding/profile-data-set
(fn [{:keys [db]} [onboarding-data]]
{:db (update db :onboarding/profile merge onboarding-data)
:fx [[:dispatch [:navigate-to-within-stack
[:screen/onboarding.create-profile-password :screen/onboarding.new-to-status]]]]}))
:onboarding/profile-data-set
(fn [{:keys [db]} [onboarding-data]]
{:db (update db :onboarding/profile merge onboarding-data)
:fx [[:dispatch
[:navigate-to-within-stack
[:screen/onboarding.create-profile-password :screen/onboarding.new-to-status]]]]}))

(rf/reg-event-fx
:onboarding/navigate-to-enable-notifications
(fn [{:keys [db]}]
{:db (dissoc db :onboarding/profile)
:fx [[:dispatch [:navigate-to-within-stack
[:screen/onboarding.enable-notifications :screen/onboarding.enable-biometrics]]]]}))
:onboarding/navigate-to-enable-notifications
(fn [{:keys [db]}]
{:db (dissoc db :onboarding/profile)
:fx [[:dispatch
[:navigate-to-within-stack
[:screen/onboarding.enable-notifications :screen/onboarding.enable-biometrics]]]]}))

(rf/reg-event-fx
:onboarding/biometrics-done
(fn [{:keys [db]}]
(let [syncing? (get-in db [:onboarding/profile :syncing?])]
{:db (assoc-in db [:onboarding/profile :auth-method] constants/auth-method-biometric)
:fx [[:dispatch (if syncing?
[:onboarding/finalize-setup]
[:onboarding/create-account-and-login])]]})))
:onboarding/biometrics-done
(fn [{:keys [db]}]
(let [syncing? (get-in db [:onboarding/profile :syncing?])]
{:db (assoc-in db [:onboarding/profile :auth-method] constants/auth-method-biometric)
:fx [[:dispatch
(if syncing?
[:onboarding/finalize-setup]
[:onboarding/create-account-and-login])]]})))

(rf/reg-event-fx
:onboarding/create-account-and-login
(fn [{:keys [db]}]
(let [{:keys [seed-phrase] :as profile} (:onboarding/profile db)
restore? (boolean seed-phrase)
{:keys [password] :as profile} (profile.utils/create-profile-config profile restore?)]
(cond-> {:fx [[:dispatch [:navigate-to-within-stack
[:screen/onboarding.generating-keys :screen/onboarding.new-to-status]]]
[:dispatch-later [{:ms constants/onboarding-generating-keys-animation-duration-ms
:dispatch [:onboarding/navigate-to-identifiers]}]]]
:db (-> db
(dissoc :profile/login)
(dissoc :auth-method)
(assoc :onboarding/new-account? true)
(assoc-in [:syncing :login-sha3-password] password))}

restore?
(assoc-in [:db :onboarding/recovered-account?] true)

restore?
(assoc :effects.profile/restore-and-login profile)

(not restore?)
(assoc :effects.profile/create-and-login profile)))))
:onboarding/create-account-and-login
(fn [{:keys [db]}]
(let [{:keys [seed-phrase] :as profile} (:onboarding/profile db)
restore? (boolean seed-phrase)
{:keys [password] :as profile} (profile.utils/create-profile-config profile restore?)]
(cond-> {:fx [[:dispatch
[:navigate-to-within-stack
[:screen/onboarding.generating-keys :screen/onboarding.new-to-status]]]
[:dispatch-later
[{:ms constants/onboarding-generating-keys-animation-duration-ms
:dispatch [:onboarding/navigate-to-identifiers]}]]]
:db (-> db
(dissoc :profile/login)
(dissoc :auth-method)
(assoc :onboarding/new-account? true)
(assoc-in [:syncing :login-sha3-password] password))}

restore?
(assoc-in [:db :onboarding/recovered-account?] true)

restore?
(assoc :effects.profile/restore-and-login profile)

(not restore?)
(assoc :effects.profile/create-and-login profile)))))

(rf/reg-event-fx
:onboarding/on-delete-profile-success
(fn [{:keys [db]} [key-uid]]
(let [multiaccounts (dissoc (:profile/profiles-overview db) key-uid)]
(merge
{:db (assoc db :profile/profiles-overview multiaccounts)}
(when-not (seq multiaccounts)
{:set-root :screen/onboarding.intro})))))
:onboarding/on-delete-profile-success
(fn [{:keys [db]} [key-uid]]
(let [multiaccounts (dissoc (:profile/profiles-overview db) key-uid)]
(merge
{:db (assoc db :profile/profiles-overview multiaccounts)}
(when-not (seq multiaccounts)
{:set-root :screen/onboarding.intro})))))

(rf/reg-event-fx
:onboarding/password-set
(fn [{:keys [db]} [password]]
(let [supported-type (get-in db [:biometrics :supported-type])]
{:db (-> db
(assoc-in [:onboarding/profile :password] password)
(assoc-in [:onboarding/profile :auth-method] constants/auth-method-password))
:fx [[:dispatch (if supported-type
[:navigate-to-within-stack
[:screen/onboarding.enable-biometrics :screen/onboarding.new-to-status]]
[:onboarding/create-account-and-login])]]})))
:onboarding/password-set
(fn [{:keys [db]} [password]]
(let [supported-type (get-in db [:biometrics :supported-type])]
{:db (-> db
(assoc-in [:onboarding/profile :password] password)
(assoc-in [:onboarding/profile :auth-method] constants/auth-method-password))
:fx [[:dispatch
(if supported-type
[:navigate-to-within-stack
[:screen/onboarding.enable-biometrics :screen/onboarding.new-to-status]]
[:onboarding/create-account-and-login])]]})))

(rf/reg-event-fx
:onboarding/navigate-to-enable-biometrics
(fn [{:keys [db]}]
(let [supported-type (get-in db [:biometrics :supported-type])]
{:fx [[:dispatch (if supported-type
[:open-modal :screen/onboarding.enable-biometrics]
[:open-modal :screen/onboarding.enable-notifications])]]})))
:onboarding/navigate-to-enable-biometrics
(fn [{:keys [db]}]
(let [supported-type (get-in db [:biometrics :supported-type])]
{:fx [[:dispatch
(if supported-type
[:open-modal :screen/onboarding.enable-biometrics]
[:open-modal :screen/onboarding.enable-notifications])]]})))

(rf/reg-event-fx
:onboarding/seed-phrase-entered
(fn [_ [seed-phrase on-error]]
{:multiaccount/validate-mnemonic [seed-phrase
(fn [mnemonic key-uid]
(rf/dispatch [:onboarding/seed-phrase-validated
mnemonic key-uid]))
on-error]}))
:onboarding/seed-phrase-entered
(fn [_ [seed-phrase on-error]]
{:multiaccount/validate-mnemonic [seed-phrase
(fn [mnemonic key-uid]
(rf/dispatch [:onboarding/seed-phrase-validated
mnemonic key-uid]))
on-error]}))

(rf/reg-event-fx
:onboarding/seed-phrase-validated
(fn [{:keys [db]} [seed-phrase key-uid]]
(if (contains? (:profile/profiles-overview db) key-uid)
{:effects.utils/show-confirmation
{:title (i18n/label :t/multiaccount-exists-title)
:content (i18n/label :t/multiaccount-exists-content)
:confirm-button-text (i18n/label :t/unlock)
:on-accept (fn []
(re-frame/dispatch [:pop-to-root :screen/profile.profiles])
(re-frame/dispatch
[:profile/profile-selected key-uid]))
:on-cancel #(re-frame/dispatch [:pop-to-root :multiaccounts])}}
{:db (assoc-in db [:onboarding/profile :seed-phrase] seed-phrase)
:fx [[:dispatch [:navigate-to-within-stack
[:screen/onboarding.create-profile :screen/onboarding.new-to-status]]]]})))
:onboarding/seed-phrase-validated
(fn [{:keys [db]} [seed-phrase key-uid]]
(if (contains? (:profile/profiles-overview db) key-uid)
{:effects.utils/show-confirmation
{:title (i18n/label :t/multiaccount-exists-title)
:content (i18n/label :t/multiaccount-exists-content)
:confirm-button-text (i18n/label :t/unlock)
:on-accept (fn []
(re-frame/dispatch [:pop-to-root :screen/profile.profiles])
(re-frame/dispatch
[:profile/profile-selected key-uid]))
:on-cancel #(re-frame/dispatch [:pop-to-root :multiaccounts])}}
{:db (assoc-in db [:onboarding/profile :seed-phrase] seed-phrase)
:fx [[:dispatch
[:navigate-to-within-stack
[:screen/onboarding.create-profile :screen/onboarding.new-to-status]]]]})))

(rf/reg-event-fx
:onboarding/navigate-to-create-profile
(fn [{:keys [db]}]
{:db (dissoc db :onboarding/profile)
:fx [[:dispatch [:navigate-to-within-stack
[:screen/onboarding.create-profile :screen/onboarding.new-to-status]]]]}))
:onboarding/navigate-to-create-profile
(fn [{:keys [db]}]
{:db (dissoc db :onboarding/profile)
:fx [[:dispatch
[:navigate-to-within-stack
[:screen/onboarding.create-profile :screen/onboarding.new-to-status]]]]}))

(rf/reg-event-fx
:onboarding/set-auth-method
(fn [{:keys [db]} [auth-method]]
{:db (assoc db :auth-method auth-method)}))
:onboarding/set-auth-method
(fn [{:keys [db]} [auth-method]]
{:db (assoc db :auth-method auth-method)}))

(rf/reg-event-fx
:onboarding/finalize-setup
(fn [{:keys [db]}]
(let [masked-password (get-in db [:onboarding/profile :password])
key-uid (get-in db [:profile/profile :key-uid])
syncing? (get-in db [:onboarding/profile :syncing?])
auth-method (get-in db [:onboarding/profile :auth-method])
biometric-enabled? (= auth-method
constants/auth-method-biometric)]
(cond-> {:db (assoc db :onboarding/generated-keys? true)}
biometric-enabled?
(assoc :keychain/save-password-and-auth-method
{:key-uid key-uid
:masked-password (if syncing?
masked-password
(security/hash-masked-password masked-password))
:on-success (fn []
(rf/dispatch [:onboarding/set-auth-method auth-method])
(when syncing?
(rf/dispatch [:onboarding/navigate-to-enable-notifications])))
:on-error #(log/error "failed to save biometrics"
{:key-uid key-uid
:error %})})))))
:onboarding/finalize-setup
(fn [{:keys [db]}]
(let [masked-password (get-in db [:onboarding/profile :password])
key-uid (get-in db [:profile/profile :key-uid])
syncing? (get-in db [:onboarding/profile :syncing?])
auth-method (get-in db [:onboarding/profile :auth-method])
biometric-enabled? (= auth-method
constants/auth-method-biometric)]
(cond-> {:db (assoc db :onboarding/generated-keys? true)}
biometric-enabled?
(assoc :keychain/save-password-and-auth-method
{:key-uid key-uid
:masked-password (if syncing?
masked-password
(security/hash-masked-password masked-password))
:on-success (fn []
(rf/dispatch [:onboarding/set-auth-method auth-method])
(when syncing?
(rf/dispatch [:onboarding/navigate-to-enable-notifications])))
:on-error #(log/error "failed to save biometrics"
{:key-uid key-uid
:error %})})))))

(rf/reg-event-fx
:onboarding/navigate-to-identifiers
(fn [{:keys [db]}]
{:fx [(if (:onboarding/generated-keys? db)
[:dispatch [:navigate-to-within-stack
[:screen/onboarding.identifiers :screen/onboarding.new-to-status]]]
[:dispatch-later [{:ms constants/onboarding-generating-keys-navigation-retry-ms
:dispatch [:onboarding/navigate-to-identifiers]}]])]}))
:onboarding/navigate-to-identifiers
(fn [{:keys [db]}]
{:fx [(if (:onboarding/generated-keys? db)
[:dispatch
[:navigate-to-within-stack
[:screen/onboarding.identifiers :screen/onboarding.new-to-status]]]
[:dispatch-later
[{:ms constants/onboarding-generating-keys-navigation-retry-ms
:dispatch [:onboarding/navigate-to-identifiers]}]])]}))
8 changes: 4 additions & 4 deletions src/status_im/contexts/profile/create/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[utils.re-frame :as rf]))

(rf/reg-event-fx :profile.create/create-and-login
(fn [{:keys [db]} [profile]]
(let [{:keys [password] :as profile} (profile.utils/create-profile-config profile false)]
{:db (assoc-in db [:syncing :login-sha3-password] password)
:effects.profile/create-and-login profile})))
(fn [{:keys [db]} [profile]]
(let [{:keys [password] :as profile} (profile.utils/create-profile-config profile false)]
{:db (assoc-in db [:syncing :login-sha3-password] password)
:effects.profile/create-and-login profile})))
26 changes: 13 additions & 13 deletions src/status_im/contexts/profile/push_notifications/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@
#(handle-notification-press (transforms/json->clj %)))))

(rf/reg-event-fx :push-notifications/registered-for-push-notifications
(fn [_ [token]]
{:json-rpc/call [{:method "wakuext_registerForPushNotifications"
:params [token (if platform/ios? config/apn-topic)
(if platform/ios? apn-token-type firebase-token-type)]
:on-success #(log/info "[push-notifications] register-success" %)
:on-error #(log/info "[push-notifications] register-error" %)}]}))
(fn [_ [token]]
{:json-rpc/call [{:method "wakuext_registerForPushNotifications"
:params [token (if platform/ios? config/apn-topic)
(if platform/ios? apn-token-type firebase-token-type)]
:on-success #(log/info "[push-notifications] register-success" %)
:on-error #(log/info "[push-notifications] register-error" %)}]}))

(rf/reg-event-fx :push-notifications/unregistered-from-push-notifications
(fn [_]
{:json-rpc/call [{:method "wakuext_unregisterFromPushNotifications"
:params []
:on-success #(log/info "[push-notifications] unregister-success" %)
:on-error #(log/info "[push-notifications] unregister-error" %)}]}))
(fn [_]
{:json-rpc/call [{:method "wakuext_unregisterFromPushNotifications"
:params []
:on-success #(log/info "[push-notifications] unregister-success" %)
:on-error #(log/info "[push-notifications] unregister-error" %)}]}))

(rf/reg-event-fx :push-notifications/preferences-loaded
(fn [{:keys [db]} [preferences]]
{:db (assoc db :push-notifications/preferences preferences)}))
(fn [{:keys [db]} [preferences]]
{:db (assoc db :push-notifications/preferences preferences)}))

(re-frame/reg-fx :push-notifications/load-preferences
(fn []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
[react-native.platform :as platform]
[status-im.constants :as constants]
status-im.contexts.profile.push-notifications.local.effects
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
[utils.i18n :as i18n]))

(def ^:private push-notification-types
#{"transaction" "message"})
Expand Down

0 comments on commit d379d80

Please sign in to comment.