Skip to content

Commit 8de051c

Browse files
committed
Implement seed phrase fallback flow
status-im/status-go@81cfce7...ddc0342
1 parent 601045e commit 8de051c

File tree

16 files changed

+365
-79
lines changed

16 files changed

+365
-79
lines changed

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_finishPairingThroughSeedPhraseProcess"
251+
:params [{:installationId (:syncing/installation-id db)}]
252+
:js-response true
253+
:on-success #(rf/dispatch [: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_enableAndSyncInstallation"
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,76 @@
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 origin-device-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 other-device-view
48+
[]
49+
(let [installation-id (rf/sub [:profile/installation-id])]
50+
(rn/use-mount events-helper/dismiss-keyboard)
51+
[:<>
52+
[quo/text
53+
{:weight :semi-bold
54+
:size :heading-2
55+
:accessibility-label :new-device-sheet-heading
56+
:style style/heading}
57+
(i18n/label :t/pair-this-device-and-sync)]
58+
[quo/text
59+
{:weight :regular
60+
:size :paragraph-1
61+
:accessibility-label :new-device-sheet-message
62+
:style style/message}
63+
(i18n/label :t/new-device-detected-other-device-message)]
64+
[quo/text
65+
{:weight :semi-bold
66+
:size :heading-2
67+
:accessibility-label :new-device-installation-id
68+
:style style/heading}
69+
installation-id]
70+
[quo/bottom-actions
71+
{:actions :one-action
72+
:blur? true
73+
:container-style {:margin-top 12}
74+
:button-one-label (i18n/label :t/close)
75+
:button-one-props {:type :grey
76+
:on-press events-helper/hide-bottom-sheet}}]]))

src/status_im/contexts/onboarding/events.cljs

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

148156
(rf/defn navigate-to-create-profile
149157
{: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+
300))
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+
[rn/view
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)}))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
(ns status-im.contexts.shell.activity-center.notification.syncing.view
2+
(:require
3+
[quo.core :as quo]
4+
quo.theme
5+
[react-native.core :as rn]
6+
[status-im.common.new-device-sheet.view :as new-device-sheet]
7+
[status-im.contexts.shell.activity-center.notification.common.view :as common]
8+
[utils.datetime :as datetime]
9+
[utils.i18n :as i18n]
10+
[utils.re-frame :as rf]))
11+
12+
(defn- swipeable
13+
[{:keys [extra-fn]} child]
14+
[common/swipeable
15+
{:left-button common/swipe-button-read-or-unread
16+
:left-on-press common/swipe-on-press-toggle-read
17+
:right-button common/swipe-button-delete
18+
:right-on-press common/swipe-on-press-delete
19+
:extra-fn extra-fn}
20+
child])
21+
22+
(defn installation-created-view
23+
[{:keys [notification extra-fn]}]
24+
(let [{:keys [installationId read timestamp]} notification
25+
customization-color (rf/sub [:profile/customization-color])
26+
theme (quo.theme/use-theme)
27+
more-details (rn/use-callback
28+
(fn []
29+
(rf/dispatch [:show-bottom-sheet
30+
{:content
31+
(fn []
32+
[new-device-sheet/other-device-view
33+
(:id installationId)])}]))
34+
[installationId])]
35+
[swipeable {:extra-fn extra-fn}
36+
[quo/activity-log
37+
{:title (i18n/label :t/sync-your-profile)
38+
:customization-color customization-color
39+
:icon :i/mobile
40+
:timestamp (datetime/timestamp->relative timestamp)
41+
:unread? (not read)
42+
:context [(i18n/label :t/check-other-device-for-pairing)]
43+
:items [{:type :button
44+
:subtype :positive
45+
:key :review-pairing-request
46+
:blur? true
47+
:label (i18n/label :t/more-details)
48+
:theme theme
49+
:on-press more-details}]}]]))
50+
51+
(defn installation-received-view
52+
[{:keys [notification extra-fn]}]
53+
(let [{:keys [installationId read timestamp]} notification
54+
customization-color (rf/sub [:profile/customization-color])
55+
theme (quo.theme/use-theme)
56+
review-pairing-request (rn/use-callback
57+
(fn []
58+
(rf/dispatch [:show-bottom-sheet
59+
{:content
60+
(fn []
61+
[new-device-sheet/origin-device-view
62+
(:id installationId)])}]))
63+
[installationId])]
64+
[swipeable {:extra-fn extra-fn}
65+
[quo/activity-log
66+
{:title (i18n/label :t/new-device-detected)
67+
:customization-color customization-color
68+
:icon :i/mobile
69+
:timestamp (datetime/timestamp->relative timestamp)
70+
:unread? (not read)
71+
:context [(i18n/label :t/new-device-detected)]
72+
:items [{:type :button
73+
:subtype :positive
74+
:key :review-pairing-request
75+
:blur? true
76+
:label (i18n/label :t/review-pairing-request)
77+
:theme theme
78+
:on-press review-pairing-request}]}]]))

0 commit comments

Comments
 (0)