[Improvements] Syncing completed events check (#15574)

This commit is contained in:
Mohamed Javid 2023-04-07 00:59:14 +08:00 committed by GitHub
parent 3238f42039
commit c3ed15f30d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 46 additions and 32 deletions

View File

@ -115,7 +115,7 @@
{:events [:system-theme-mode-changed]}
[{:keys [db] :as cofx} _]
(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))
{:multiaccounts.ui/switch-theme-fx
[(get-in db [:multiaccount :appearance])

View File

@ -238,7 +238,7 @@
:t/keycard-can-use-with-new-passcode
:t/keycard-backup-success-body))}}
(cond
(multiaccounts.model/logged-in? cofx)
(multiaccounts.model/logged-in? db)
(navigation/set-stack-root :profile-stack [:my-profile :keycard-settings])
(:multiaccounts/login db)

View File

@ -21,7 +21,7 @@
(rf/defn on-network-status-change
[{:keys [db] :as cofx}]
(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)]
(apply
rf/merge

View File

@ -21,10 +21,10 @@
(rf/defn key-and-storage-management-pressed
"This event can be dispatched before login and from profile and needs to redirect accordingly"
{:events [::key-and-storage-management-pressed]}
[cofx]
[{:keys [db] :as cofx}]
(navigation/navigate-to
cofx
(if (multiaccounts.model/logged-in? cofx)
(if (multiaccounts.model/logged-in? db)
:actions-logged-in
:actions-not-logged-in)
nil))

View File

@ -476,9 +476,6 @@
"Decides which root should be initialised depending on user and app state"
[db]
(cond
(get db :local-pairing/completed-pairing?)
(re-frame/dispatch [:syncing/pairing-completed])
(get db :onboarding-2/new-account?)
(re-frame/dispatch [:onboarding-2/finalize-setup])
@ -491,7 +488,8 @@
(rf/defn login-only-events
[{:keys [db] :as cofx} key-uid password save-password?]
(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"
"auth-method" auth-method
"new-auth-method" new-auth-method)
@ -500,7 +498,8 @@
:json-rpc/call
[{:method "settings_getSettings"
: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)
(when save-password?
(keychain/save-user-password key-uid password))

View File

@ -1,9 +1,8 @@
(ns status-im.multiaccounts.model)
(defn logged-in?
[cofx]
(boolean
(get-in cofx [:db :multiaccount])))
[{:keys [multiaccount]}]
(boolean multiaccount))
(defn credentials
[cofx]

View File

@ -4,6 +4,6 @@
(deftest logged-in-test
(testing "multiaccount is defined"
(is (multiaccounts.model/logged-in? {:db {:multiaccount {}}})))
(is (multiaccounts.model/logged-in? {:multiaccount {}})))
(testing "multiaccount is not there"
(is (not (multiaccounts.model/logged-in? {:db {}})))))
(is (not (multiaccounts.model/logged-in? {})))))

View File

@ -60,27 +60,29 @@
[{:keys [db] :as cofx} event]
(log/info "local pairing signal received"
{:event event})
(let [connection-success? (= (:type event)
(let [connection-success? (and (= (:type event)
constants/local-pairing-event-connection-success)
(= (:action event)
constants/local-pairing-action-connect))
error-on-pairing? (contains? constants/local-pairing-event-errors (:type event))
completed-pairing? (and (= (:type event)
constants/local-pairing-event-process-success)
constants/local-pairing-event-transfer-success)
(= (:action event)
constants/local-pairing-action-pairing-account))
logged-in? (multiaccounts.model/logged-in? cofx)
constants/local-pairing-action-pairing-installation))
logged-in? (multiaccounts.model/logged-in? db)
;; 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
navigate-to-syncing-devices? (and connection-success? (not logged-in?))
user-in-syncing-devices-screen? (= (:view-id db) :syncing-devices)]
(merge {:db (cond-> db
connection-success?
(assoc :local-pairing/completed-pairing? false)
(assoc-in [:syncing :pairing-in-progress?] true)
error-on-pairing?
(dissoc :local-pairing/completed-pairing?)
(update-in [:syncing :pairing-in-progress?] dissoc)
completed-pairing?
(assoc :local-pairing/completed-pairing? true))}
(assoc-in [:syncing :pairing-in-progress?] false))}
(when navigate-to-syncing-devices?
{:dispatch [:navigate-to :syncing-devices]})
(when (and error-on-pairing? user-in-syncing-devices-screen?)
@ -89,7 +91,9 @@
:icon-color colors/danger-50
:override-theme :light
:text (i18n/label :t/error-syncing-connection-failed)}]
[:navigate-back]]}))))
[:navigate-back]]})
(when completed-pairing?
{:dispatch [:syncing/pairing-completed]}))))
(rf/defn process
{:events [:signals/signal-received]}

View File

@ -184,7 +184,7 @@
on login, otherwise just handle it"
{:events [:universal-links/handle-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)
(store-url-for-later cofx url)))

View File

@ -263,6 +263,9 @@
An example of a connection string is -> cs2:5vd6J6:Jfc:27xMmHKEYwzRGXcvTtuiLZFfXscMx4Mz8d9wEHUxDj4p7:EG7Z13QScfWBJNJ5cprszzDQ5fBVsYMirXo8MaQFJvpF:3 "
"cs")
(def ^:const local-pairing-role-sender "sender")
(def ^:const local-pairing-role-receiver "receiver")
;; sender and receiver events
(def ^:const local-pairing-event-connection-success "connection-success")
(def ^:const local-pairing-event-connection-error "connection-error")

View File

@ -13,10 +13,17 @@
(rf/defn local-pairing-completed
{:events [:syncing/pairing-completed]}
[{:keys [db] :as cofx}]
(rf/merge cofx
{:db (dissoc db :local-pairing/completed-pairing?)
:dispatch [:init-root :enable-notifications]}))
[{:keys [db]}]
(let [receiver? (= (get-in db [:syncing :role]) constants/local-pairing-role-receiver)]
(merge
{: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
[installation-id]
@ -44,6 +51,7 @@
:nodeConfig final-node-config
:settingCurrentNetwork config/default-network
:deviceType utils.platform/os}}))]
(rf/dispatch [:syncing/update-role constants/local-pairing-role-receiver])
(status/input-connection-string-for-bootstrapping
connection-string
config-map
@ -61,7 +69,8 @@
[:show-bottom-sheet
{:content (fn []
[sheet/qr-code-view-with-connection-string
connection-string])}]))]
connection-string])}])
(rf/dispatch [:syncing/update-role constants/local-pairing-role-sender]))]
(if valid-password?
(let [sha3-pwd (status/sha3 (str (security/safe-unmask-data entered-password)))
key-uid (get-in db [:multiaccount :key-uid])

View File

@ -29,7 +29,7 @@
(re-frame/reg-sub
:multiaccount/logged-in?
(fn [db]
(multiaccounts.model/logged-in? {:db db})))
(multiaccounts.model/logged-in? db)))
(re-frame/reg-sub
:hide-screen?