2022-11-14 19:16:55 +01:00
|
|
|
(ns status-im2.setup.events
|
2020-04-10 15:48:41 +03:00
|
|
|
(:require [clojure.string :as string]
|
|
|
|
[re-frame.core :as re-frame]
|
2022-11-14 19:16:55 +01:00
|
|
|
[status-im2.setup.db :as db]
|
|
|
|
[status-im2.common.theme.core :as theme]
|
|
|
|
[quo2.theme :as quo2.theme]
|
2022-11-16 09:09:25 +01:00
|
|
|
[utils.re-frame :as rf]
|
|
|
|
|
2022-11-14 19:16:55 +01:00
|
|
|
;; TODO (14/11/22 flexsurfer move to status-im2 namespace
|
2019-08-01 22:11:59 +02:00
|
|
|
[status-im.multiaccounts.login.core :as multiaccounts.login]
|
2018-09-06 12:04:12 +02:00
|
|
|
[status-im.native-module.core :as status]
|
2021-05-24 16:25:05 +02:00
|
|
|
[status-im.utils.keychain.core :as keychain]
|
2022-11-14 19:16:55 +01:00
|
|
|
[status-im2.navigation.events :as navigation]))
|
2018-09-06 12:04:12 +02:00
|
|
|
|
2022-11-14 19:16:55 +01:00
|
|
|
(re-frame/reg-fx
|
|
|
|
:setup/open-multiaccounts
|
|
|
|
(fn [callback]
|
|
|
|
(status/open-accounts callback)))
|
|
|
|
|
|
|
|
(re-frame/reg-fx
|
|
|
|
:setup/init-theme
|
|
|
|
(fn []
|
|
|
|
(theme/add-mode-change-listener #(re-frame/dispatch [:system-theme-mode-changed %]))
|
|
|
|
(quo2.theme/set-theme (if (theme/dark-mode?) :dark :light))))
|
2018-08-26 02:45:03 +02:00
|
|
|
|
2022-11-16 09:09:25 +01:00
|
|
|
(rf/defn initialize-views
|
2022-11-14 19:16:55 +01:00
|
|
|
{:events [:setup/initialize-view]}
|
2021-05-24 16:25:05 +02:00
|
|
|
[cofx]
|
2020-04-27 13:00:35 +02:00
|
|
|
(let [{{:multiaccounts/keys [multiaccounts]} :db} cofx]
|
2021-05-24 16:25:05 +02:00
|
|
|
(if (and (seq multiaccounts))
|
2020-12-28 12:30:50 +01:00
|
|
|
;; We specifically pass a bunch of fields instead of the whole multiaccount
|
|
|
|
;; as we want store some fields in multiaccount that are not here
|
2020-11-30 14:11:06 +03:00
|
|
|
(let [multiaccount (first (sort-by :timestamp > (vals multiaccounts)))]
|
2022-11-16 09:09:25 +01:00
|
|
|
(rf/merge cofx
|
2021-05-24 16:25:05 +02:00
|
|
|
(multiaccounts.login/open-login (select-keys
|
|
|
|
multiaccount
|
|
|
|
[:key-uid :name :public-key :identicon :images]))
|
|
|
|
(keychain/get-auth-method (:key-uid multiaccount))))
|
|
|
|
(navigation/init-root cofx :intro))))
|
2019-08-01 22:11:59 +02:00
|
|
|
|
2022-11-16 09:09:25 +01:00
|
|
|
(rf/defn initialize-multiaccounts
|
2022-11-14 19:16:55 +01:00
|
|
|
{:events [:setup/initialize-multiaccounts]}
|
2020-01-29 10:29:56 +03:00
|
|
|
[{:keys [db] :as cofx} all-multiaccounts {:keys [logout?]}]
|
2019-12-05 08:02:31 +02:00
|
|
|
(let [multiaccounts (reduce (fn [acc {:keys [key-uid keycard-pairing]
|
2020-01-29 10:29:56 +03:00
|
|
|
:as multiaccount}]
|
2019-12-05 08:02:31 +02:00
|
|
|
(-> (assoc acc key-uid multiaccount)
|
|
|
|
(assoc-in [key-uid :keycard-pairing]
|
|
|
|
(when-not (string/blank? keycard-pairing)
|
|
|
|
keycard-pairing))))
|
2019-08-01 22:11:59 +02:00
|
|
|
{}
|
|
|
|
all-multiaccounts)]
|
2022-11-16 09:09:25 +01:00
|
|
|
(rf/merge cofx
|
2022-11-14 19:16:55 +01:00
|
|
|
{:db (-> db
|
|
|
|
(assoc :multiaccounts/multiaccounts multiaccounts)
|
|
|
|
(assoc :multiaccounts/logout? logout?)
|
|
|
|
(assoc :multiaccounts/loading false))
|
|
|
|
:dispatch-n [[:setup/initialize-view]
|
2022-08-11 21:48:13 +05:30
|
|
|
[:get-opted-in-to-new-terms-of-service]
|
|
|
|
[:load-information-box-states]]})))
|
2018-08-26 02:45:03 +02:00
|
|
|
|
2022-11-16 09:09:25 +01:00
|
|
|
(rf/defn initialize-app-db
|
2022-11-14 19:16:55 +01:00
|
|
|
"Initialize db to initial state"
|
|
|
|
[{{:keys [keycard supported-biometric-auth goto-key-storage?]
|
|
|
|
:network/keys [type] :keycard/keys [banner-hidden]} :db}]
|
|
|
|
{:db (assoc db/app-db
|
|
|
|
:network/type type
|
|
|
|
:keycard/banner-hidden banner-hidden
|
|
|
|
:keycard (dissoc keycard :secrets :pin :application-info)
|
|
|
|
:supported-biometric-auth supported-biometric-auth
|
|
|
|
:goto-key-storage? goto-key-storage?
|
|
|
|
:multiaccounts/loading true)})
|
|
|
|
|
2022-11-16 09:09:25 +01:00
|
|
|
(rf/defn start-app
|
2022-11-14 19:16:55 +01:00
|
|
|
{:events [:setup/app-started]}
|
2021-02-12 15:58:43 +01:00
|
|
|
[cofx]
|
2022-11-16 09:09:25 +01:00
|
|
|
(rf/merge cofx
|
2022-11-14 19:16:55 +01:00
|
|
|
{:setup/init-theme nil
|
|
|
|
:get-supported-biometric-auth nil
|
|
|
|
:network/listen-to-network-info nil
|
2020-09-19 09:32:28 +05:30
|
|
|
:keycard/register-card-events nil
|
|
|
|
:keycard/check-nfc-support nil
|
|
|
|
:keycard/check-nfc-enabled nil
|
2022-11-14 19:16:55 +01:00
|
|
|
:keycard/retrieve-pairings nil
|
|
|
|
:setup/open-multiaccounts #(do
|
|
|
|
(re-frame/dispatch [:setup/initialize-multiaccounts % {:logout? false}])
|
|
|
|
(re-frame/dispatch [:get-keycard-banner-preference]))}
|
2019-08-01 22:11:59 +02:00
|
|
|
(initialize-app-db)))
|