Skip to content

Commit a8fbe7e

Browse files
committed
Implement seed phrase fallback flow
status-im/status-go@81cfce7...b501c88
1 parent d7242f1 commit a8fbe7e

File tree

17 files changed

+367
-79
lines changed

17 files changed

+367
-79
lines changed

src/legacy/status_im/data_store/activities.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
:chatId :chat-id
6363
:contactVerificationStatus :contact-verification-status
6464
:communityId :community-id
65+
:installationId :installation-id
6566
:membershipStatus :membership-status
6667
:albumMessages :album-messages})
6768
(update :last-message #(when % (messages/<-rpc %)))

src/legacy/status_im/data_store/activities_test.cljs

+19-15
Original file line numberDiff line numberDiff line change
@@ -117,20 +117,24 @@
117117

118118
(deftest parse-notification-counts-response-test
119119
(is
120-
(= {notification-types/one-to-one-chat 15
121-
notification-types/private-group-chat 16
122-
notification-types/mention 17
123-
notification-types/reply 18
124-
notification-types/contact-request 19
125-
notification-types/admin 20
126-
notification-types/contact-verification 21}
120+
(= {notification-types/one-to-one-chat 15
121+
notification-types/private-group-chat 16
122+
notification-types/mention 17
123+
notification-types/reply 18
124+
notification-types/contact-request 19
125+
notification-types/admin 20
126+
notification-types/contact-verification 21
127+
notification-types/new-installation-received 22
128+
notification-types/new-installation-created 23}
127129
(store/parse-notification-counts-response
128-
{(keyword (str notification-types/one-to-one-chat)) 15
129-
(keyword (str notification-types/private-group-chat)) 16
130-
(keyword (str notification-types/mention)) 17
131-
(keyword (str notification-types/reply)) 18
132-
(keyword (str notification-types/contact-request)) 19
133-
(keyword (str notification-types/admin)) 20
134-
(keyword (str notification-types/contact-verification)) 21
130+
{(keyword (str notification-types/one-to-one-chat)) 15
131+
(keyword (str notification-types/private-group-chat)) 16
132+
(keyword (str notification-types/mention)) 17
133+
(keyword (str notification-types/reply)) 18
134+
(keyword (str notification-types/contact-request)) 19
135+
(keyword (str notification-types/admin)) 20
136+
(keyword (str notification-types/contact-verification)) 21
137+
(keyword (str notification-types/new-installation-received)) 22
138+
(keyword (str notification-types/new-installation-created)) 23
135139
;; Unsupported type in the response is ignored
136-
:999 100}))))
140+
:999 100}))))

src/legacy/status_im/pairing/core.cljs

+17
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,23 @@
243243
{}
244244
installations))})
245245

246+
(rf/defn finish-seed-phrase-fallback-syncing
247+
{:events [:pairing/finish-seed-phrase-fallback-syncing]}
248+
[{:keys [db]}]
249+
{:fx [[:json-rpc/call
250+
[{:method "wakuext_enableInstallationAndPair"
251+
:params [{:installationId (:syncing/installation-id db)}]
252+
:js-response true
253+
:on-success [:sanitize-messages-and-process-response]}]]]})
254+
255+
(rf/defn pair-and-sync
256+
{:events [:pairing/pair-and-sync]}
257+
[cofx installation-id]
258+
{:fx [[:json-rpc/call
259+
[{:method "wakuext_enableInstallationAndSync"
260+
:params [{:installationId installation-id}]
261+
:on-success #(log/debug "successfully synced devices")}]]]})
262+
246263
(rf/defn enable-installation-success
247264
{:events [:pairing.callback/enable-installation-success]}
248265
[cofx installation-id]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
(ns status-im.common.new-device-sheet.style
2+
(:require [quo.foundations.colors :as colors]))
3+
4+
(def heading
5+
{:padding-left 20
6+
:padding-bottom 8})
7+
8+
(def message
9+
{:padding-horizontal 20
10+
:padding-top 4})
11+
12+
(def warning
13+
{:margin-horizontal 20
14+
:margin-top 10})
15+
16+
(def drawer-container
17+
{:padding-horizontal 13
18+
:padding-top 16})
19+
20+
(def settings-subtext
21+
{:color colors/white-opa-70
22+
:align-self :center
23+
:margin-bottom 12})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
(ns status-im.common.new-device-sheet.view
2+
(:require
3+
[quo.core :as quo]
4+
[react-native.core :as rn]
5+
[status-im.common.events-helper :as events-helper]
6+
[status-im.common.new-device-sheet.style :as style]
7+
[utils.i18n :as i18n]
8+
[utils.re-frame :as rf]))
9+
10+
(defn- pair-and-sync
11+
[installation-id]
12+
(rf/dispatch [:pairing/pair-and-sync installation-id])
13+
(events-helper/hide-bottom-sheet))
14+
15+
(defn installation-request-receiver-view
16+
[installation-id]
17+
(rn/use-mount events-helper/dismiss-keyboard)
18+
[:<>
19+
[quo/text
20+
{:weight :semi-bold
21+
:size :heading-2
22+
:accessibility-label :new-device-sheet-heading
23+
:style style/heading}
24+
(i18n/label :t/pair-new-device-and-sync)]
25+
[quo/text
26+
{:weight :regular
27+
:size :paragraph-1
28+
:accessibility-label :new-device-sheet-message
29+
:style style/message}
30+
(i18n/label :t/new-device-detected-recovered-device-message)]
31+
[quo/text
32+
{:weight :semi-bold
33+
:size :heading-2
34+
:accessibility-label :new-device-installation-id
35+
:style style/heading}
36+
installation-id]
37+
[quo/bottom-actions
38+
{:actions :two-actions
39+
:blur? true
40+
:container-style {:margin-top 12}
41+
:button-two-label (i18n/label :t/cancel)
42+
:button-two-props {:type :grey
43+
:on-press events-helper/hide-bottom-sheet}
44+
:button-one-label (i18n/label :t/pair-and-sync)
45+
:button-one-props {:on-press #(pair-and-sync installation-id)}}]])
46+
47+
(defn installation-request-creator-view
48+
[installation-id]
49+
(rn/use-mount events-helper/dismiss-keyboard)
50+
[:<>
51+
[quo/text
52+
{:weight :semi-bold
53+
:size :heading-2
54+
:accessibility-label :new-device-sheet-heading
55+
:style style/heading}
56+
(i18n/label :t/pair-this-device-and-sync)]
57+
[quo/text
58+
{:weight :regular
59+
:size :paragraph-1
60+
:accessibility-label :new-device-sheet-message
61+
:style style/message}
62+
(i18n/label :t/new-device-detected-other-device-message)]
63+
[quo/text
64+
{:weight :semi-bold
65+
:size :heading-2
66+
:accessibility-label :new-device-installation-id
67+
:style style/heading}
68+
installation-id]
69+
[quo/bottom-actions
70+
{:actions :one-action
71+
:blur? true
72+
:container-style {:margin-top 12}
73+
:button-one-label (i18n/label :t/close)
74+
:button-one-props {:type :grey
75+
:on-press events-helper/hide-bottom-sheet}}]])

src/status_im/contexts/onboarding/events.cljs

+24-16
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,30 @@
134134
(rf/defn seed-phrase-validated
135135
{:events [:onboarding/seed-phrase-validated]}
136136
[{:keys [db]} seed-phrase key-uid]
137-
(if (contains? (:profile/profiles-overview db) key-uid)
138-
{:effects.utils/show-confirmation
139-
{:title (i18n/label :t/multiaccount-exists-title)
140-
:content (i18n/label :t/multiaccount-exists-content)
141-
:confirm-button-text (i18n/label :t/unlock)
142-
:on-accept (fn []
143-
(re-frame/dispatch [:pop-to-root :screen/profile.profiles])
144-
(re-frame/dispatch
145-
[:profile/profile-selected key-uid]))
146-
:on-cancel #(re-frame/dispatch [:pop-to-root :multiaccounts])}}
147-
{:db (assoc-in db [:onboarding/profile :seed-phrase] seed-phrase)
148-
:dispatch [:navigate-to-within-stack
149-
[:screen/onboarding.create-profile
150-
(get db
151-
:onboarding/navigated-to-enter-seed-phrase-from-screen
152-
:screen/onboarding.new-to-status)]]}))
137+
(let [syncing-account-recovered? (and (seq (:syncing/key-uid db))
138+
(= (:syncing/key-uid db) key-uid))
139+
next-screen (if syncing-account-recovered?
140+
:screen/onboarding.create-profile-password
141+
:screen/onboarding.create-profile)]
142+
(if (contains? (:profile/profiles-overview db) key-uid)
143+
{:effects.utils/show-confirmation
144+
{:title (i18n/label :t/multiaccount-exists-title)
145+
:content (i18n/label :t/multiaccount-exists-content)
146+
:confirm-button-text (i18n/label :t/unlock)
147+
:on-accept (fn []
148+
(re-frame/dispatch [:pop-to-root :screen/profile.profiles])
149+
(re-frame/dispatch
150+
[:profile/profile-selected key-uid]))
151+
:on-cancel #(re-frame/dispatch [:pop-to-root :multiaccounts])}}
152+
{:db (assoc-in db [:onboarding/profile :seed-phrase] seed-phrase)
153+
:fx [[:dispatch
154+
[:navigate-to-within-stack
155+
[next-screen
156+
(get db
157+
:onboarding/navigated-to-enter-seed-phrase-from-screen
158+
:screen/onboarding.new-to-status)]]]
159+
(when-not syncing-account-recovered?
160+
[:dispatch [:syncing/clear-syncing-data]])]})))
153161

154162
(rf/defn navigate-to-create-profile
155163
{:events [:onboarding/navigate-to-create-profile]}

src/status_im/contexts/onboarding/syncing/progress/view.cljs

+28-11
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[status-im.common.resources :as resources]
66
[status-im.contexts.onboarding.common.background.view :as background]
77
[status-im.contexts.onboarding.syncing.progress.style :as style]
8+
[utils.debounce :as debounce]
89
[utils.i18n :as i18n]
910
[utils.re-frame :as rf]))
1011

@@ -25,17 +26,32 @@
2526
:title-accessibility-label :progress-screen-title
2627
:description-accessibility-label :progress-screen-sub-title}])
2728

29+
(defn- navigate-to-enter-seed-phrase
30+
[]
31+
(rf/dispatch [:navigate-back-to :screen/onboarding.sync-or-recover-profile])
32+
(debounce/debounce-and-dispatch
33+
[:onboarding/navigate-to-sign-in-by-seed-phrase :screen/onboarding.sync-or-recover-profile]
34+
500))
35+
2836
(defn try-again-button
29-
[profile-color]
30-
[quo/button
31-
{:on-press (fn []
32-
(rf/dispatch [:syncing/clear-states])
33-
(rf/dispatch [:navigate-back]))
34-
:accessibility-label :try-again-later-button
35-
:customization-color profile-color
36-
:size 40
37-
:container-style style/try-again-button}
38-
(i18n/label :t/try-again)])
37+
[profile-color logged-in?]
38+
[:<>
39+
(when-not logged-in?
40+
[quo/button
41+
{:on-press navigate-to-enter-seed-phrase
42+
:accessibility-label :try-seed-phrase-button
43+
:customization-color profile-color
44+
:container-style style/try-again-button}
45+
(i18n/label :t/enter-seed-phrase)])
46+
[quo/button
47+
{:on-press (fn []
48+
(rf/dispatch [:syncing/clear-states])
49+
(rf/dispatch [:navigate-back]))
50+
:accessibility-label :try-again-later-button
51+
:customization-color profile-color
52+
:size 40
53+
:container-style style/try-again-button}
54+
(i18n/label :t/try-again)]])
3955

4056
(defn- illustration
4157
[pairing-progress?]
@@ -47,6 +63,7 @@
4763
(defn view
4864
[in-onboarding?]
4965
(let [pairing-status (rf/sub [:pairing/pairing-status])
66+
logged-in? (rf/sub [:multiaccount/logged-in?])
5067
pairing-progress? (pairing-progress pairing-status)
5168
profile-color (or (:color (rf/sub [:onboarding/profile]))
5269
(rf/sub [:profile/customization-color]))]
@@ -58,7 +75,7 @@
5875
[page-title pairing-progress?]
5976
[illustration pairing-progress?]
6077
(when-not (pairing-progress pairing-status)
61-
[try-again-button profile-color])]))
78+
[try-again-button profile-color logged-in?])]))
6279

6380
(defn view-onboarding
6481
[]

src/status_im/contexts/profile/login/events.cljs

+2
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@
134134
(rf/dispatch [:chats-list/load-success result])
135135
(rf/dispatch [:communities/get-user-requests-to-join])
136136
(rf/dispatch [:profile.login/get-chats-callback]))}]
137+
(when (:syncing/installation-id db)
138+
[:dispatch [:pairing/finish-seed-phrase-fallback-syncing]])
137139
(when-not new-account?
138140
[:dispatch [:universal-links/process-stored-event]])]})))
139141

src/status_im/contexts/profile/recover/events.cljs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns status-im.contexts.profile.recover.events
22
(:require
33
[native-module.core :as native-module]
4+
[status-im.constants :as constants]
45
[status-im.contexts.profile.config :as profile.config]
56
status-im.contexts.profile.recover.effects
67
[utils.re-frame :as rf]
@@ -16,10 +17,10 @@
1617
(assoc-in [:syncing :login-sha3-password] login-sha3-password))
1718

1819
:effects.profile/restore-and-login
19-
(merge (profile.config/create)
20-
{:displayName display-name
21-
:mnemonic (security/safe-unmask-data seed-phrase)
22-
:password login-sha3-password
23-
:imagePath (profile.config/strip-file-prefix image-path)
24-
:customizationColor color
25-
:fetchBackup true})}))
20+
(assoc (profile.config/create)
21+
:displayName display-name
22+
:mnemonic (security/safe-unmask-data seed-phrase)
23+
:password login-sha3-password
24+
:imagePath (profile.config/strip-file-prefix image-path)
25+
:customizationColor (or color constants/profile-default-color)
26+
:fetchBackup true)}))

0 commit comments

Comments
 (0)