Skip to content

Commit 0eb065b

Browse files
Implement seed phrase fallback flow (#21090)
Co-authored-by: Parvesh Monu <[email protected]> Co-authored-by: Andrea Maria Piana <[email protected]>
1 parent 2e61f94 commit 0eb065b

File tree

25 files changed

+445
-88
lines changed

25 files changed

+445
-88
lines changed
723 KB
Loading
1.27 MB
Loading

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/common/resources.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
:notifications (js/require "../resources/images/ui2/notifications.png")
2929
:nfc-prompt (js/require "../resources/images/ui2/nfc-prompt.png")
3030
:nfc-success (js/require "../resources/images/ui2/nfc-success.png")
31+
:preparing-status (js/require "../resources/images/ui2/preparing-status.png")
3132
:syncing-devices (js/require "../resources/images/ui2/syncing_devices.png")
3233
:syncing-wrong (js/require "../resources/images/ui2/syncing_wrong.png")})
3334

src/status_im/contexts/centralized_metrics/tracking.cljs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
:screen/onboarding.enable-biometrics
3838
:screen/onboarding.generating-keys
3939
:screen/onboarding.enable-notifications
40+
:screen/onboarding.preparing-status
4041
:screen/onboarding.sign-in-intro
4142
:screen/onboarding.sign-in
4243
:screen/onboarding.syncing-progress

src/status_im/contexts/onboarding/events.cljs

+32-19
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,20 @@
7171
{:events [:onboarding/create-account-and-login]}
7272
[{:keys [db] :as cofx}]
7373
(let [{:keys [display-name seed-phrase password image-path color] :as profile}
74-
(:onboarding/profile db)]
74+
(:onboarding/profile db)
75+
loading-screen (if (seq (:syncing/key-uid db))
76+
:screen/onboarding.preparing-status
77+
:screen/onboarding.generating-keys)]
7578
(rf/merge cofx
7679
{:dispatch [:navigate-to-within-stack
77-
[:screen/onboarding.generating-keys
80+
[loading-screen
7881
(get db
7982
:onboarding/navigated-to-enter-seed-phrase-from-screen
8083
:screen/onboarding.new-to-status)]]
8184
:dispatch-later [{:ms constants/onboarding-generating-keys-animation-duration-ms
8285
:dispatch [:navigate-to-within-stack
8386
[:screen/onboarding.enable-notifications
84-
:screen/onboarding.generating-keys]]}]
87+
loading-screen]]}]
8588
:db (-> db
8689
(dissoc :profile/login)
8790
(dissoc :auth-method)
@@ -134,22 +137,32 @@
134137
(rf/defn seed-phrase-validated
135138
{:events [:onboarding/seed-phrase-validated]}
136139
[{: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)]]}))
140+
(let [syncing-account-recovered? (and (seq (:syncing/key-uid db))
141+
(= (:syncing/key-uid db) key-uid))
142+
next-screen (if syncing-account-recovered?
143+
:screen/onboarding.create-profile-password
144+
:screen/onboarding.create-profile)]
145+
(if (contains? (:profile/profiles-overview db) key-uid)
146+
{:effects.utils/show-confirmation
147+
{:title (i18n/label :t/multiaccount-exists-title)
148+
:content (i18n/label :t/multiaccount-exists-content)
149+
:confirm-button-text (i18n/label :t/unlock)
150+
:on-accept (fn []
151+
(re-frame/dispatch [:pop-to-root :screen/profile.profiles])
152+
(re-frame/dispatch
153+
[:profile/profile-selected key-uid]))
154+
:on-cancel #(re-frame/dispatch [:pop-to-root :multiaccounts])}}
155+
{:db (-> db
156+
(assoc-in [:onboarding/profile :seed-phrase] seed-phrase)
157+
(assoc-in [:onboarding/profile :color] constants/profile-default-color))
158+
:fx [[:dispatch
159+
[:navigate-to-within-stack
160+
[next-screen
161+
(get db
162+
:onboarding/navigated-to-enter-seed-phrase-from-screen
163+
:screen/onboarding.new-to-status)]]]
164+
(when-not syncing-account-recovered?
165+
[:dispatch [:syncing/clear-syncing-data]])]})))
153166

154167
(rf/defn navigate-to-create-profile
155168
{:events [:onboarding/navigate-to-create-profile]}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(ns status-im.contexts.onboarding.preparing-status.style)
2+
3+
(defn page-container
4+
[insets]
5+
{:flex 1
6+
:padding-top (:top insets)})
7+
8+
(defn page-illustration
9+
[width]
10+
{:flex 1
11+
:width width})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(ns status-im.contexts.onboarding.preparing-status.view
2+
(:require
3+
[quo.core :as quo]
4+
[react-native.core :as rn]
5+
[react-native.safe-area :as safe-area]
6+
[status-im.common.resources :as resources]
7+
[status-im.contexts.onboarding.generating-keys.style :as style]
8+
[utils.i18n :as i18n]))
9+
10+
(defn title
11+
[]
12+
[rn/view
13+
{:style {:margin-top 56
14+
:height 56
15+
:margin-bottom 10}}
16+
[quo/text-combinations
17+
{:container-style {:margin-horizontal 20
18+
:margin-vertical 12}
19+
:title (i18n/label :t/preparing-app-for-you)
20+
:description (i18n/label :t/hang-in-there)}]])
21+
22+
(defn content
23+
[]
24+
(let [width (:width (rn/get-window))]
25+
[rn/image
26+
{:resize-mode :stretch
27+
:style (style/page-illustration width)
28+
:source (resources/get-image :preparing-status)}]))
29+
30+
(defn view
31+
[]
32+
(let [insets (safe-area/get-insets)]
33+
[rn/view {:style (style/page-container insets)}
34+
[:<>
35+
[title]
36+
[content]]]))

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

-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,3 @@
2727
:align-items :center
2828
:align-self :center
2929
:justify-content :center})
30-
31-
(def try-again-button
32-
{:margin-top 20
33-
:padding-horizontal 20})

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

+36-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,40 @@
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+
(debounce/debounce-and-dispatch
32+
[:onboarding/navigate-to-sign-in-by-seed-phrase :screen/onboarding.sync-or-recover-profile]
33+
500))
34+
35+
(defn- try-again
36+
[logged-in?]
37+
(rf/dispatch [:syncing/clear-states])
38+
(if logged-in?
39+
(rf/dispatch [:navigate-back])
40+
(rf/dispatch [:navigate-back-to :screen/onboarding.sync-or-recover-profile])))
41+
2842
(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)])
43+
[profile-color logged-in?]
44+
[quo/bottom-actions
45+
{:actions (if logged-in? :one-action :two-actions)
46+
:blur? true
47+
:button-one-label (i18n/label :t/recovery-phrase)
48+
:button-one-props {:type :primary
49+
:accessibility-label :try-seed-phrase-button
50+
:customization-color profile-color
51+
:container-style {:flex 1}
52+
:size 40
53+
:on-press navigate-to-enter-seed-phrase}
54+
(if logged-in? :button-one-label :button-two-label)
55+
(i18n/label :t/try-again)
56+
(if logged-in? :button-one-props :button-two-props)
57+
{:type (if logged-in? :primary :grey)
58+
:accessibility-label :try-again-later-button
59+
:customization-color profile-color
60+
:container-style {:flex 1}
61+
:size 40
62+
:on-press #(try-again logged-in?)}}])
3963

4064
(defn- illustration
4165
[pairing-progress?]
@@ -47,6 +71,7 @@
4771
(defn view
4872
[in-onboarding?]
4973
(let [pairing-status (rf/sub [:pairing/pairing-status])
74+
logged-in? (rf/sub [:multiaccount/logged-in?])
5075
pairing-progress? (pairing-progress pairing-status)
5176
profile-color (or (:color (rf/sub [:onboarding/profile]))
5277
(rf/sub [:profile/customization-color]))]
@@ -58,7 +83,7 @@
5883
[page-title pairing-progress?]
5984
[illustration pairing-progress?]
6085
(when-not (pairing-progress pairing-status)
61-
[try-again-button profile-color])]))
86+
[try-again-button profile-color logged-in?])]))
6287

6388
(defn view-onboarding
6489
[]

0 commit comments

Comments
 (0)