[Improvements] Syncing completed events check (#15574)
This commit is contained in:
parent
3238f42039
commit
c3ed15f30d
|
@ -115,7 +115,7 @@
|
||||||
{:events [:system-theme-mode-changed]}
|
{:events [:system-theme-mode-changed]}
|
||||||
[{:keys [db] :as cofx} _]
|
[{:keys [db] :as cofx} _]
|
||||||
(let [current-theme-type (get-in cofx [:db :multiaccount :appearance])]
|
(let [current-theme-type (get-in cofx [:db :multiaccount :appearance])]
|
||||||
(when (and (multiaccounts.model/logged-in? cofx)
|
(when (and (multiaccounts.model/logged-in? db)
|
||||||
(= current-theme-type status-im2.constants/theme-type-system))
|
(= current-theme-type status-im2.constants/theme-type-system))
|
||||||
{:multiaccounts.ui/switch-theme-fx
|
{:multiaccounts.ui/switch-theme-fx
|
||||||
[(get-in db [:multiaccount :appearance])
|
[(get-in db [:multiaccount :appearance])
|
||||||
|
|
|
@ -238,7 +238,7 @@
|
||||||
:t/keycard-can-use-with-new-passcode
|
:t/keycard-can-use-with-new-passcode
|
||||||
:t/keycard-backup-success-body))}}
|
:t/keycard-backup-success-body))}}
|
||||||
(cond
|
(cond
|
||||||
(multiaccounts.model/logged-in? cofx)
|
(multiaccounts.model/logged-in? db)
|
||||||
(navigation/set-stack-root :profile-stack [:my-profile :keycard-settings])
|
(navigation/set-stack-root :profile-stack [:my-profile :keycard-settings])
|
||||||
|
|
||||||
(:multiaccounts/login db)
|
(:multiaccounts/login db)
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
(rf/defn on-network-status-change
|
(rf/defn on-network-status-change
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db] :as cofx}]
|
||||||
(let [initialized? (get db :network-status/initialized?)
|
(let [initialized? (get db :network-status/initialized?)
|
||||||
logged-in? (multiaccounts.model/logged-in? cofx)
|
logged-in? (multiaccounts.model/logged-in? db)
|
||||||
{:keys [remember-syncing-choice?]} (:multiaccount db)]
|
{:keys [remember-syncing-choice?]} (:multiaccount db)]
|
||||||
(apply
|
(apply
|
||||||
rf/merge
|
rf/merge
|
||||||
|
|
|
@ -21,10 +21,10 @@
|
||||||
(rf/defn key-and-storage-management-pressed
|
(rf/defn key-and-storage-management-pressed
|
||||||
"This event can be dispatched before login and from profile and needs to redirect accordingly"
|
"This event can be dispatched before login and from profile and needs to redirect accordingly"
|
||||||
{:events [::key-and-storage-management-pressed]}
|
{:events [::key-and-storage-management-pressed]}
|
||||||
[cofx]
|
[{:keys [db] :as cofx}]
|
||||||
(navigation/navigate-to
|
(navigation/navigate-to
|
||||||
cofx
|
cofx
|
||||||
(if (multiaccounts.model/logged-in? cofx)
|
(if (multiaccounts.model/logged-in? db)
|
||||||
:actions-logged-in
|
:actions-logged-in
|
||||||
:actions-not-logged-in)
|
:actions-not-logged-in)
|
||||||
nil))
|
nil))
|
||||||
|
|
|
@ -476,9 +476,6 @@
|
||||||
"Decides which root should be initialised depending on user and app state"
|
"Decides which root should be initialised depending on user and app state"
|
||||||
[db]
|
[db]
|
||||||
(cond
|
(cond
|
||||||
(get db :local-pairing/completed-pairing?)
|
|
||||||
(re-frame/dispatch [:syncing/pairing-completed])
|
|
||||||
|
|
||||||
(get db :onboarding-2/new-account?)
|
(get db :onboarding-2/new-account?)
|
||||||
(re-frame/dispatch [:onboarding-2/finalize-setup])
|
(re-frame/dispatch [:onboarding-2/finalize-setup])
|
||||||
|
|
||||||
|
@ -490,8 +487,9 @@
|
||||||
|
|
||||||
(rf/defn login-only-events
|
(rf/defn login-only-events
|
||||||
[{:keys [db] :as cofx} key-uid password save-password?]
|
[{:keys [db] :as cofx} key-uid password save-password?]
|
||||||
(let [auth-method (:auth-method db)
|
(let [auth-method (:auth-method db)
|
||||||
new-auth-method (get-new-auth-method auth-method save-password?)]
|
new-auth-method (get-new-auth-method auth-method save-password?)
|
||||||
|
pairing-in-progress? (get-in db [:syncing :pairing-in-progress?])]
|
||||||
(log/debug "[login] login-only-events"
|
(log/debug "[login] login-only-events"
|
||||||
"auth-method" auth-method
|
"auth-method" auth-method
|
||||||
"new-auth-method" new-auth-method)
|
"new-auth-method" new-auth-method)
|
||||||
|
@ -500,7 +498,8 @@
|
||||||
:json-rpc/call
|
:json-rpc/call
|
||||||
[{:method "settings_getSettings"
|
[{:method "settings_getSettings"
|
||||||
:on-success #(do (re-frame/dispatch [::get-settings-callback %])
|
:on-success #(do (re-frame/dispatch [::get-settings-callback %])
|
||||||
(redirect-to-root db))}]}
|
(when-not pairing-in-progress?
|
||||||
|
(redirect-to-root db)))}]}
|
||||||
(notifications/load-notification-preferences)
|
(notifications/load-notification-preferences)
|
||||||
(when save-password?
|
(when save-password?
|
||||||
(keychain/save-user-password key-uid password))
|
(keychain/save-user-password key-uid password))
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
(ns status-im.multiaccounts.model)
|
(ns status-im.multiaccounts.model)
|
||||||
|
|
||||||
(defn logged-in?
|
(defn logged-in?
|
||||||
[cofx]
|
[{:keys [multiaccount]}]
|
||||||
(boolean
|
(boolean multiaccount))
|
||||||
(get-in cofx [:db :multiaccount])))
|
|
||||||
|
|
||||||
(defn credentials
|
(defn credentials
|
||||||
[cofx]
|
[cofx]
|
||||||
|
|
|
@ -4,6 +4,6 @@
|
||||||
|
|
||||||
(deftest logged-in-test
|
(deftest logged-in-test
|
||||||
(testing "multiaccount is defined"
|
(testing "multiaccount is defined"
|
||||||
(is (multiaccounts.model/logged-in? {:db {:multiaccount {}}})))
|
(is (multiaccounts.model/logged-in? {:multiaccount {}})))
|
||||||
(testing "multiaccount is not there"
|
(testing "multiaccount is not there"
|
||||||
(is (not (multiaccounts.model/logged-in? {:db {}})))))
|
(is (not (multiaccounts.model/logged-in? {})))))
|
||||||
|
|
|
@ -60,27 +60,29 @@
|
||||||
[{:keys [db] :as cofx} event]
|
[{:keys [db] :as cofx} event]
|
||||||
(log/info "local pairing signal received"
|
(log/info "local pairing signal received"
|
||||||
{:event event})
|
{:event event})
|
||||||
(let [connection-success? (= (:type event)
|
(let [connection-success? (and (= (:type event)
|
||||||
constants/local-pairing-event-connection-success)
|
constants/local-pairing-event-connection-success)
|
||||||
|
(= (:action event)
|
||||||
|
constants/local-pairing-action-connect))
|
||||||
error-on-pairing? (contains? constants/local-pairing-event-errors (:type event))
|
error-on-pairing? (contains? constants/local-pairing-event-errors (:type event))
|
||||||
completed-pairing? (and (= (:type event)
|
completed-pairing? (and (= (:type event)
|
||||||
constants/local-pairing-event-process-success)
|
constants/local-pairing-event-transfer-success)
|
||||||
(= (:action event)
|
(= (:action event)
|
||||||
constants/local-pairing-action-pairing-account))
|
constants/local-pairing-action-pairing-installation))
|
||||||
logged-in? (multiaccounts.model/logged-in? cofx)
|
logged-in? (multiaccounts.model/logged-in? db)
|
||||||
;; since `connection-success` event is received on both sender and receiver devices
|
;; since `connection-success` event is received on both sender and receiver devices
|
||||||
;; we check the `logged-in?` status to identify the receiver and take the user to next screen
|
;; we check the `logged-in?` status to identify the receiver and take the user to next screen
|
||||||
navigate-to-syncing-devices? (and connection-success? (not logged-in?))
|
navigate-to-syncing-devices? (and connection-success? (not logged-in?))
|
||||||
user-in-syncing-devices-screen? (= (:view-id db) :syncing-devices)]
|
user-in-syncing-devices-screen? (= (:view-id db) :syncing-devices)]
|
||||||
(merge {:db (cond-> db
|
(merge {:db (cond-> db
|
||||||
connection-success?
|
connection-success?
|
||||||
(assoc :local-pairing/completed-pairing? false)
|
(assoc-in [:syncing :pairing-in-progress?] true)
|
||||||
|
|
||||||
error-on-pairing?
|
error-on-pairing?
|
||||||
(dissoc :local-pairing/completed-pairing?)
|
(update-in [:syncing :pairing-in-progress?] dissoc)
|
||||||
|
|
||||||
completed-pairing?
|
completed-pairing?
|
||||||
(assoc :local-pairing/completed-pairing? true))}
|
(assoc-in [:syncing :pairing-in-progress?] false))}
|
||||||
(when navigate-to-syncing-devices?
|
(when navigate-to-syncing-devices?
|
||||||
{:dispatch [:navigate-to :syncing-devices]})
|
{:dispatch [:navigate-to :syncing-devices]})
|
||||||
(when (and error-on-pairing? user-in-syncing-devices-screen?)
|
(when (and error-on-pairing? user-in-syncing-devices-screen?)
|
||||||
|
@ -89,7 +91,9 @@
|
||||||
:icon-color colors/danger-50
|
:icon-color colors/danger-50
|
||||||
:override-theme :light
|
:override-theme :light
|
||||||
:text (i18n/label :t/error-syncing-connection-failed)}]
|
:text (i18n/label :t/error-syncing-connection-failed)}]
|
||||||
[:navigate-back]]}))))
|
[:navigate-back]]})
|
||||||
|
(when completed-pairing?
|
||||||
|
{:dispatch [:syncing/pairing-completed]}))))
|
||||||
|
|
||||||
(rf/defn process
|
(rf/defn process
|
||||||
{:events [:signals/signal-received]}
|
{:events [:signals/signal-received]}
|
||||||
|
|
|
@ -184,7 +184,7 @@
|
||||||
on login, otherwise just handle it"
|
on login, otherwise just handle it"
|
||||||
{:events [:universal-links/handle-url]}
|
{:events [:universal-links/handle-url]}
|
||||||
[{:keys [db] :as cofx} url]
|
[{:keys [db] :as cofx} url]
|
||||||
(if (and (multiaccounts.model/logged-in? cofx) (= (:app-state db) "active"))
|
(if (and (multiaccounts.model/logged-in? db) (= (:app-state db) "active"))
|
||||||
(route-url cofx url)
|
(route-url cofx url)
|
||||||
(store-url-for-later cofx url)))
|
(store-url-for-later cofx url)))
|
||||||
|
|
||||||
|
|
|
@ -263,6 +263,9 @@
|
||||||
An example of a connection string is -> cs2:5vd6J6:Jfc:27xMmHKEYwzRGXcvTtuiLZFfXscMx4Mz8d9wEHUxDj4p7:EG7Z13QScfWBJNJ5cprszzDQ5fBVsYMirXo8MaQFJvpF:3 "
|
An example of a connection string is -> cs2:5vd6J6:Jfc:27xMmHKEYwzRGXcvTtuiLZFfXscMx4Mz8d9wEHUxDj4p7:EG7Z13QScfWBJNJ5cprszzDQ5fBVsYMirXo8MaQFJvpF:3 "
|
||||||
"cs")
|
"cs")
|
||||||
|
|
||||||
|
(def ^:const local-pairing-role-sender "sender")
|
||||||
|
(def ^:const local-pairing-role-receiver "receiver")
|
||||||
|
|
||||||
;; sender and receiver events
|
;; sender and receiver events
|
||||||
(def ^:const local-pairing-event-connection-success "connection-success")
|
(def ^:const local-pairing-event-connection-success "connection-success")
|
||||||
(def ^:const local-pairing-event-connection-error "connection-error")
|
(def ^:const local-pairing-event-connection-error "connection-error")
|
||||||
|
|
|
@ -13,10 +13,17 @@
|
||||||
|
|
||||||
(rf/defn local-pairing-completed
|
(rf/defn local-pairing-completed
|
||||||
{:events [:syncing/pairing-completed]}
|
{:events [:syncing/pairing-completed]}
|
||||||
[{:keys [db] :as cofx}]
|
[{:keys [db]}]
|
||||||
(rf/merge cofx
|
(let [receiver? (= (get-in db [:syncing :role]) constants/local-pairing-role-receiver)]
|
||||||
{:db (dissoc db :local-pairing/completed-pairing?)
|
(merge
|
||||||
:dispatch [:init-root :enable-notifications]}))
|
{:db (dissoc db :syncing)}
|
||||||
|
(when receiver?
|
||||||
|
{:dispatch [:init-root :enable-notifications]}))))
|
||||||
|
|
||||||
|
(rf/defn local-pairing-update-role
|
||||||
|
{:events [:syncing/update-role]}
|
||||||
|
[{:keys [db]} role]
|
||||||
|
{:db (assoc-in db [:syncing :role] role)})
|
||||||
|
|
||||||
(defn- get-default-node-config
|
(defn- get-default-node-config
|
||||||
[installation-id]
|
[installation-id]
|
||||||
|
@ -44,6 +51,7 @@
|
||||||
:nodeConfig final-node-config
|
:nodeConfig final-node-config
|
||||||
:settingCurrentNetwork config/default-network
|
:settingCurrentNetwork config/default-network
|
||||||
:deviceType utils.platform/os}}))]
|
:deviceType utils.platform/os}}))]
|
||||||
|
(rf/dispatch [:syncing/update-role constants/local-pairing-role-receiver])
|
||||||
(status/input-connection-string-for-bootstrapping
|
(status/input-connection-string-for-bootstrapping
|
||||||
connection-string
|
connection-string
|
||||||
config-map
|
config-map
|
||||||
|
@ -61,7 +69,8 @@
|
||||||
[:show-bottom-sheet
|
[:show-bottom-sheet
|
||||||
{:content (fn []
|
{:content (fn []
|
||||||
[sheet/qr-code-view-with-connection-string
|
[sheet/qr-code-view-with-connection-string
|
||||||
connection-string])}]))]
|
connection-string])}])
|
||||||
|
(rf/dispatch [:syncing/update-role constants/local-pairing-role-sender]))]
|
||||||
(if valid-password?
|
(if valid-password?
|
||||||
(let [sha3-pwd (status/sha3 (str (security/safe-unmask-data entered-password)))
|
(let [sha3-pwd (status/sha3 (str (security/safe-unmask-data entered-password)))
|
||||||
key-uid (get-in db [:multiaccount :key-uid])
|
key-uid (get-in db [:multiaccount :key-uid])
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:multiaccount/logged-in?
|
:multiaccount/logged-in?
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(multiaccounts.model/logged-in? {:db db})))
|
(multiaccounts.model/logged-in? db)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:hide-screen?
|
:hide-screen?
|
||||||
|
|
Loading…
Reference in New Issue