2018-08-26 02:45:03 +02:00
|
|
|
(ns status-im.init.core
|
2020-04-10 15:48:41 +03:00
|
|
|
(:require [clojure.string :as string]
|
|
|
|
[quo.theme :as quo-theme]
|
|
|
|
[re-frame.core :as re-frame]
|
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]
|
2019-09-03 12:51:53 +02:00
|
|
|
[status-im.network.net-info :as network]
|
2020-04-10 15:48:41 +03:00
|
|
|
[status-im.ui.components.colors :as colors]
|
2020-04-29 15:11:24 +02:00
|
|
|
[status-im.db :refer [app-db]]
|
2019-05-09 21:51:41 +02:00
|
|
|
[status-im.utils.fx :as fx]
|
2020-04-10 15:48:41 +03:00
|
|
|
[status-im.utils.theme :as theme]))
|
2018-09-06 12:04:12 +02:00
|
|
|
|
2018-09-24 17:59:02 +02:00
|
|
|
(fx/defn initialize-app-db
|
2018-08-27 06:51:04 +02:00
|
|
|
"Initialize db to initial state"
|
2020-05-05 16:18:23 +02:00
|
|
|
[{{:keys [hardwallet initial-props supported-biometric-auth app-active-since]
|
|
|
|
:desktop/keys [desktop]
|
|
|
|
:network/keys [type]} :db
|
|
|
|
now :now}]
|
2019-02-08 16:30:44 +03:00
|
|
|
{:db (assoc app-db
|
|
|
|
:initial-props initial-props
|
|
|
|
:desktop/desktop (merge desktop (:desktop/desktop app-db))
|
|
|
|
:network/type type
|
2019-09-26 16:47:40 +03:00
|
|
|
:hardwallet (dissoc hardwallet :secrets)
|
2019-05-30 16:01:20 +02:00
|
|
|
:supported-biometric-auth supported-biometric-auth
|
2020-01-14 20:24:21 +01:00
|
|
|
:app-active-since (or app-active-since now)
|
2020-02-25 14:31:04 +03:00
|
|
|
:multiaccounts/loading true)})
|
2018-08-26 02:45:03 +02:00
|
|
|
|
2018-09-24 17:59:02 +02:00
|
|
|
(fx/defn initialize-views
|
2020-03-17 12:15:02 +03:00
|
|
|
{:events [::initialize-view]}
|
2020-01-29 10:29:56 +03:00
|
|
|
[cofx {:keys [logout?]}]
|
2020-04-27 13:00:35 +02:00
|
|
|
(let [{{:multiaccounts/keys [multiaccounts]} :db} cofx]
|
2020-02-25 14:31:04 +03:00
|
|
|
(when (and (seq multiaccounts) (not logout?))
|
2020-04-27 13:00:35 +02:00
|
|
|
(let [{:keys [key-uid public-key photo-path name]}
|
|
|
|
(first (sort-by :timestamp > (vals multiaccounts)))]
|
2019-12-05 08:02:31 +02:00
|
|
|
(multiaccounts.login/open-login cofx key-uid photo-path name public-key)))))
|
2019-08-01 22:11:59 +02:00
|
|
|
|
|
|
|
(fx/defn initialize-multiaccounts
|
|
|
|
{:events [::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)]
|
|
|
|
(fx/merge cofx
|
2020-03-17 12:15:02 +03:00
|
|
|
{:db (-> db
|
|
|
|
(assoc :multiaccounts/multiaccounts multiaccounts)
|
|
|
|
(assoc :multiaccounts/logout? logout?)
|
|
|
|
(assoc :multiaccounts/loading false))
|
|
|
|
;; NOTE: Try to dispatch later navigation because of that https://github.com/react-navigation/react-navigation/issues/6879
|
|
|
|
:dispatch-later [{:dispatch [::initialize-view {:logout? logout?}]
|
|
|
|
:ms 100}]})))
|
2018-08-26 02:45:03 +02:00
|
|
|
|
2019-08-01 22:11:59 +02:00
|
|
|
(fx/defn start-app [cofx]
|
2018-09-24 17:59:02 +02:00
|
|
|
(fx/merge cofx
|
2019-09-15 17:20:10 +02:00
|
|
|
{:get-supported-biometric-auth nil
|
2020-03-16 14:02:35 +01:00
|
|
|
::init-theme nil
|
2019-08-15 17:44:25 +03:00
|
|
|
::init-keystore nil
|
2020-01-29 10:29:56 +03:00
|
|
|
::open-multiaccounts #(re-frame/dispatch [::initialize-multiaccounts % {:logout? false}])
|
2019-08-01 22:11:59 +02:00
|
|
|
:ui/listen-to-window-dimensions-change nil
|
2019-09-03 12:51:53 +02:00
|
|
|
::network/listen-to-network-info nil
|
2020-02-25 20:36:29 +02:00
|
|
|
:hardwallet/register-card-events nil
|
2019-08-15 17:44:25 +03:00
|
|
|
:hardwallet/check-nfc-support nil
|
|
|
|
:hardwallet/check-nfc-enabled nil
|
|
|
|
:hardwallet/retrieve-pairings nil}
|
2019-08-01 22:11:59 +02:00
|
|
|
(initialize-app-db)))
|
2018-09-06 12:04:12 +02:00
|
|
|
|
2018-12-18 19:30:26 +02:00
|
|
|
(re-frame/reg-fx
|
2019-08-01 22:11:59 +02:00
|
|
|
::open-multiaccounts
|
|
|
|
(fn [callback]
|
|
|
|
(status/open-accounts callback)))
|
2018-12-18 19:30:26 +02:00
|
|
|
|
2019-07-31 18:10:38 +02:00
|
|
|
(re-frame/reg-fx
|
2019-08-01 22:11:59 +02:00
|
|
|
::init-keystore
|
2019-07-31 18:10:38 +02:00
|
|
|
(fn []
|
2019-10-28 15:52:25 +01:00
|
|
|
(status/init-keystore)))
|
2020-03-16 14:02:35 +01:00
|
|
|
|
|
|
|
(re-frame/reg-fx
|
|
|
|
::init-theme
|
|
|
|
(fn []
|
|
|
|
(theme/add-mode-change-listener #(re-frame/dispatch [:system-theme-mode-changed %]))
|
|
|
|
(when (theme/is-dark-mode)
|
2020-04-10 15:48:41 +03:00
|
|
|
(quo-theme/set-theme :dark)
|
|
|
|
(colors/set-theme :dark))))
|