2018-08-26 02:45:03 +02:00
|
|
|
(ns status-im.init.core
|
|
|
|
(:require [re-frame.core :as re-frame]
|
2019-08-01 22:11:59 +02:00
|
|
|
[status-im.biometric-auth.core :as biometric-auth]
|
|
|
|
[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]
|
2018-08-27 06:51:04 +02:00
|
|
|
[status-im.notifications.core :as notifications]
|
2019-05-09 21:51:41 +02:00
|
|
|
[status-im.react-native.js-dependencies :as rn-dependencies]
|
2018-08-26 02:45:03 +02:00
|
|
|
[status-im.ui.screens.db :refer [app-db]]
|
2018-08-27 06:51:04 +02:00
|
|
|
[status-im.ui.screens.navigation :as navigation]
|
2019-05-09 21:51:41 +02:00
|
|
|
[status-im.utils.fx :as fx]
|
2019-08-01 22:11:59 +02:00
|
|
|
[status-im.utils.platform :as platform]))
|
2018-09-06 12:04:12 +02:00
|
|
|
|
2018-12-18 19:30:26 +02:00
|
|
|
(defn restore-native-settings! []
|
|
|
|
(when platform/desktop?
|
|
|
|
(.getValue rn-dependencies/desktop-config "logging_enabled"
|
2018-12-24 16:08:42 +02:00
|
|
|
#(re-frame/dispatch [:set-in [:desktop/desktop :logging-enabled]
|
2019-08-01 22:11:59 +02:00
|
|
|
(if (boolean? %)
|
|
|
|
%
|
|
|
|
(cljs.reader/read-string %))]))))
|
2018-09-28 16:48:59 +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"
|
2019-08-23 16:11:23 +02:00
|
|
|
[{{:keys [view-id hardwallet initial-props desktop/desktop
|
|
|
|
device-UUID supported-biometric-auth push-notifications/stored network/type]} :db}]
|
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
|
|
|
|
:hardwallet hardwallet
|
|
|
|
:device-UUID device-UUID
|
2019-05-30 16:01:20 +02:00
|
|
|
:supported-biometric-auth supported-biometric-auth
|
2019-02-08 16:30:44 +03:00
|
|
|
:view-id view-id
|
|
|
|
:push-notifications/stored stored)})
|
2018-08-26 02:45:03 +02:00
|
|
|
|
2018-09-24 17:59:02 +02:00
|
|
|
(fx/defn set-device-uuid
|
|
|
|
[{:keys [db]} device-uuid]
|
2018-09-06 12:04:12 +02:00
|
|
|
{:db (assoc db :device-UUID device-uuid)})
|
2018-08-26 02:45:03 +02:00
|
|
|
|
2019-05-30 16:01:20 +02:00
|
|
|
(fx/defn set-supported-biometric-auth
|
|
|
|
{:events [:init.callback/get-supported-biometric-auth-success]}
|
|
|
|
[{:keys [db]} supported-biometric-auth]
|
|
|
|
{:db (assoc db :supported-biometric-auth supported-biometric-auth)})
|
|
|
|
|
2018-09-24 17:59:02 +02:00
|
|
|
(fx/defn initialize-views
|
|
|
|
[cofx]
|
2019-07-03 16:29:01 +02:00
|
|
|
(let [{{:multiaccounts/keys [multiaccounts] :as db} :db} cofx]
|
|
|
|
(if (empty? multiaccounts)
|
2019-04-08 18:03:08 +03:00
|
|
|
(navigation/navigate-to-cofx cofx :intro nil)
|
2019-07-03 16:29:01 +02:00
|
|
|
(let [multiaccount-with-notification
|
2018-11-20 19:36:11 +01:00
|
|
|
(when-not platform/desktop?
|
|
|
|
(notifications/lookup-contact-pubkey-from-hash
|
|
|
|
cofx
|
|
|
|
(first (keys (:push-notifications/stored db)))))
|
|
|
|
selection-fn
|
2019-07-03 16:29:01 +02:00
|
|
|
(if (not-empty multiaccount-with-notification)
|
|
|
|
#(filter (fn [multiaccount]
|
|
|
|
(= multiaccount-with-notification
|
|
|
|
(:public-key multiaccount)))
|
2018-11-20 19:36:11 +01:00
|
|
|
%)
|
|
|
|
#(sort-by :last-sign-in > %))
|
2019-08-01 22:11:59 +02:00
|
|
|
{:keys [address public-key photo-path name]} (first (selection-fn (vals multiaccounts)))]
|
|
|
|
(multiaccounts.login/open-login cofx address photo-path name public-key)))))
|
|
|
|
|
|
|
|
(fx/defn initialize-multiaccounts
|
|
|
|
{:events [::initialize-multiaccounts]}
|
|
|
|
[{:keys [db] :as cofx} all-multiaccounts]
|
|
|
|
(let [multiaccounts (reduce (fn [acc {:keys [address] :as multiaccount}]
|
|
|
|
(assoc acc address multiaccount))
|
|
|
|
{}
|
|
|
|
all-multiaccounts)]
|
|
|
|
(fx/merge cofx
|
|
|
|
{:db (assoc db :multiaccounts/multiaccounts multiaccounts)}
|
|
|
|
(initialize-views))))
|
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-08-01 22:11:59 +02:00
|
|
|
{::get-device-UUID nil
|
|
|
|
::get-supported-biometric-auth nil
|
|
|
|
::init-keystore nil
|
|
|
|
::restore-native-settings nil
|
|
|
|
::open-multiaccounts #(re-frame/dispatch [::initialize-multiaccounts %])
|
|
|
|
:ui/listen-to-window-dimensions-change nil
|
|
|
|
:notifications/init nil
|
2019-09-03 12:51:53 +02:00
|
|
|
::network/listen-to-network-info nil
|
2019-08-01 22:11:59 +02:00
|
|
|
:hardwallet/register-card-events nil
|
|
|
|
:hardwallet/check-nfc-support nil
|
|
|
|
:hardwallet/check-nfc-enabled nil}
|
|
|
|
(initialize-app-db)))
|
2018-09-06 12:04:12 +02:00
|
|
|
|
|
|
|
(re-frame/reg-fx
|
2019-08-01 22:11:59 +02:00
|
|
|
::restore-native-settings
|
|
|
|
restore-native-settings!)
|
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 []
|
|
|
|
(status/init-keystore)))
|
|
|
|
|
2018-09-06 12:04:12 +02:00
|
|
|
(re-frame/reg-fx
|
2019-08-01 22:11:59 +02:00
|
|
|
::get-device-UUID
|
2018-09-06 12:04:12 +02:00
|
|
|
(fn []
|
|
|
|
(status/get-device-UUID #(re-frame/dispatch [:init.callback/get-device-UUID-success %]))))
|
|
|
|
|
2019-05-30 16:01:20 +02:00
|
|
|
(re-frame/reg-fx
|
2019-08-01 22:11:59 +02:00
|
|
|
::get-supported-biometric-auth
|
2019-05-30 16:01:20 +02:00
|
|
|
(fn []
|
|
|
|
(biometric-auth/get-supported #(re-frame/dispatch [:init.callback/get-supported-biometric-auth-success %]))))
|