Skip to content

Commit 909d7a3

Browse files
committed
Implement seed phrase fallback flow
status-im/status-go@81cfce7...ddc0342
1 parent 4105951 commit 909d7a3

File tree

11 files changed

+233
-41
lines changed

11 files changed

+233
-41
lines changed

src/legacy/status_im/pairing/core.cljs

+29-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[re-frame.core :as re-frame]
55
[react-native.platform :as utils.platform]
66
[status-im.common.json-rpc.events :as json-rpc]
7+
[status-im.common.new-device-sheet.view :as new-device-sheet]
78
[status-im.config :as config]
89
[status-im.navigation.events :as navigation]
910
[taoensso.timbre :as log]
@@ -220,6 +221,11 @@
220221
:name (:name metadata)
221222
:device-type (:deviceType metadata))})
222223

224+
(defn should-show-syncing-pop-up?
225+
[db installations]
226+
(and (:syncing/pairing-process-initiated? db)
227+
(first (filter #(not (get-in db [:pairing/installations (:id %)])) installations))))
228+
223229
(rf/defn handle-installations
224230
[{:keys [db]} installations]
225231
{:db (update db
@@ -228,7 +234,11 @@
228234
(fn [acc {:keys [id] :as i}]
229235
(update acc id merge (installation<-rpc i)))
230236
%
231-
installations))})
237+
installations))
238+
:fx [(when-let [new-installation (should-show-syncing-pop-up? db installations)]
239+
[:dispatch
240+
[:show-bottom-sheet
241+
{:content (fn [] [new-device-sheet/origin-device-view (:id new-installation)])}]])]})
232242

233243
(rf/defn load-installations
234244
{:events [:pairing.callback/get-our-installations-success]}
@@ -243,6 +253,24 @@
243253
{}
244254
installations))})
245255

256+
(rf/defn finish-seed-phrase-fallback-syncing
257+
{:events [:pairing/finish-seed-phrase-fallback-syncing]}
258+
[{:keys [db]}]
259+
{:fx [[:dispatch [:show-bottom-sheet {:content (fn [] [new-device-sheet/other-device-view])}]]
260+
[:json-rpc/call
261+
[{:method "wakuext_finishPairingThroughSeedPhraseProcess"
262+
:params [{:installationId (:syncing/installation-id db)}]
263+
:js-response true
264+
:on-success #(rf/dispatch [:sanitize-messages-and-process-response %])}]]]})
265+
266+
(rf/defn pair-and-sync
267+
{:events [:pairing/pair-and-sync]}
268+
[cofx installation-id]
269+
{:fx [[:json-rpc/call
270+
[{:method "wakuext_enableAndSyncInstallation"
271+
:params [{:installationId installation-id}]
272+
:on-success #(log/debug "successfully synced devices")}]]]})
273+
246274
(rf/defn enable-installation-success
247275
{:events [:pairing.callback/enable-installation-success]}
248276
[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)}))

src/status_im/contexts/syncing/events.cljs

+30-3
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,44 @@
2121
{:events [:syncing/clear-states]}
2222
[{:keys [db]} role]
2323
{:db (dissoc db :syncing)})
24+
2425
(defn- input-connection-string-callback
2526
[res]
2627
(log/info "[local-pairing] input-connection-string-for-bootstrapping callback"
2728
{:response res
2829
:event :syncing/input-connection-string-for-bootstrapping})
29-
(let [error (when (sync-utils/extract-error res)
30-
(str "generic-error: " res))]
31-
(when (some? error)
30+
(let [response (transforms/json->clj res)
31+
installation-id (:installationId response)
32+
key-uid (:keyUID response)
33+
error (:error response)]
34+
(when (seq installation-id)
35+
(rf/dispatch [:syncing/set-syncing-installation-id installation-id key-uid]))
36+
(when (seq error)
3237
(rf/dispatch [:toasts/upsert
3338
{:type :negative
3439
:text error}]))))
3540

41+
(rf/defn initiate-pairing-process
42+
{:events [:syncing/initiate-pairing-process]}
43+
[{:keys [db]}]
44+
{:db (assoc db :syncing/pairing-process-initiated? true)})
45+
46+
(rf/defn set-syncing-installation-id
47+
{:events [:syncing/set-syncing-installation-id]}
48+
[{:keys [db]} installation-id key-uid]
49+
{:db (assoc db
50+
:syncing/key-uid key-uid
51+
:syncing/installation-id installation-id)})
52+
53+
(rf/defn clear-syncing-data
54+
{:events [:syncing/clear-syncing-data]}
55+
[{:keys [db]}]
56+
{:db (dissoc
57+
db
58+
:syncing/key-uid
59+
:syncing/installation-id
60+
:syncing/pairing-process-initiated?)})
61+
3662
(rf/defn preflight-outbound-check-for-local-pairing
3763
{:events [:syncing/preflight-outbound-check]}
3864
[_ set-checks-passed]
@@ -67,6 +93,7 @@
6793
(when (sync-utils/valid-connection-string? response)
6894
(on-valid-connection-string response)
6995
(rf/dispatch [:syncing/update-role constants/local-pairing-role-sender])
96+
(rf/dispatch [:syncing/initiate-pairing-process])
7097
(rf/dispatch [:hide-bottom-sheet])))]
7198
(when-not (and error (string/blank? error))
7299
(let [key-uid (get-in db [:profile/profile :key-uid])

src/status_im/subs/profile.cljs

+5
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@
266266
(fn [{:keys [preview-privacy?]}]
267267
(boolean preview-privacy?)))
268268

269+
(re-frame/reg-sub :profile/installation-id
270+
:<- [:profile/profile]
271+
(fn [{:keys [installation-id]}]
272+
installation-id))
273+
269274
(defn- replace-multiaccount-image-uri
270275
[profile ens-names port font-file avatar-opts theme]
271276
(let [{:keys [key-uid ens-name? images

status-go-version.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"_comment": "Instead use: scripts/update-status-go.sh <rev>",
44
"owner": "status-im",
55
"repo": "status-go",
6-
"version": "v0.184.52",
7-
"commit-sha1": "81cfce709e8d123eb1956b87f8e0f19dc47c122c",
8-
"src-sha256": "0hna30ms4ccxmi20l5v36y84pva1s4jjkqg11whwmdjgw75d0fan"
6+
"version": "feat/enable_sync_fallback",
7+
"commit-sha1": "ddc034270a5eb12938a7092e69811c043f417769",
8+
"src-sha256": "1i8j5ri839xizwc7v2h45bxpg80v4k2i437578r7y32m1ipw3rxk"
99
}

0 commit comments

Comments
 (0)