Skip to content

Commit 4a2cc66

Browse files
committed
Implement seed phrase fallback flow
status-im/status-go@9e7d130...5127998
1 parent eecd1d5 commit 4a2cc66

File tree

12 files changed

+251
-42
lines changed

12 files changed

+251
-42
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,12 @@
220221
:name (:name metadata)
221222
:device-type (:deviceType metadata))})
222223

224+
225+
(defn should-show-syncing-pop-up?
226+
[db installations]
227+
(and (:syncing/pairing-process-initiated? db)
228+
(first (filter #(not (get-in db [:pairing/installations (:id %)])) installations))))
229+
223230
(rf/defn handle-installations
224231
[{:keys [db]} installations]
225232
{:db (update db
@@ -228,7 +235,10 @@
228235
(fn [acc {:keys [id] :as i}]
229236
(update acc id merge (installation<-rpc i)))
230237
%
231-
installations))})
238+
installations))
239+
:fx [(when-let [new-installation (should-show-syncing-pop-up? db installations)]
240+
[:dispatch
241+
[:show-bottom-sheet {:content (fn [] [new-device-sheet/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/view-2])}]]
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,24 @@
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})
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
(ns status-im.common.new-device-sheet.view
2+
(:require
3+
[quo.core :as quo]
4+
[status-im.common.new-device-sheet.style :as style]
5+
[utils.i18n :as i18n]
6+
[utils.re-frame :as rf]))
7+
8+
(defn- dismiss-keyboard
9+
[]
10+
(rf/dispatch [:dismiss-keyboard]))
11+
12+
(defn- hide-bottom-sheet
13+
[]
14+
(rf/dispatch [:hide-bottom-sheet]))
15+
16+
(defn- pair-and-sync
17+
[installation-id]
18+
(rf/dispatch [:pairing/pair-and-sync installation-id])
19+
(hide-bottom-sheet))
20+
21+
(defn view
22+
[installation-id]
23+
(dismiss-keyboard)
24+
[:<>
25+
[quo/text
26+
{:weight :semi-bold
27+
:size :heading-2
28+
:accessibility-label :new-device-sheet-heading
29+
:style style/heading}
30+
(i18n/label :t/pair-new-device-and-sync)]
31+
[quo/text
32+
{:weight :regular
33+
:size :paragraph-1
34+
:accessibility-label :new-device-sheet-message
35+
:style style/message}
36+
(i18n/label :t/new-device-detected)]
37+
[quo/text
38+
{:weight :semi-bold
39+
:size :heading-2
40+
:accessibility-label :new-device-installation-id
41+
:style style/heading}
42+
installation-id]
43+
[quo/bottom-actions
44+
{:actions :two-actions
45+
:blur? true
46+
:container-style {:margin-top 12}
47+
:button-two-label (i18n/label :t/cancel)
48+
:button-two-props {:type :grey
49+
:on-press hide-bottom-sheet}
50+
:button-one-label (i18n/label :t/pair-and-sync)
51+
:button-one-props {:on-press #(pair-and-sync installation-id)}}]])
52+
53+
(defn view-2
54+
[]
55+
(let [installation-id (rf/sub [:profile/installation-id])]
56+
(dismiss-keyboard)
57+
[:<>
58+
[quo/text
59+
{:weight :semi-bold
60+
:size :heading-2
61+
:accessibility-label :new-device-sheet-heading
62+
:style style/heading}
63+
(i18n/label :t/pair-new-device-and-sync)]
64+
[quo/text
65+
{:weight :regular
66+
:size :paragraph-1
67+
:accessibility-label :new-device-sheet-message
68+
:style style/message}
69+
(i18n/label :t/new-device-detected)]
70+
[quo/text
71+
{:weight :semi-bold
72+
:size :heading-2
73+
:accessibility-label :new-device-installation-id
74+
:style style/heading}
75+
installation-id]
76+
[quo/bottom-actions
77+
{:actions :one-action
78+
:blur? true
79+
:container-style {:margin-top 12}
80+
:button-one-label (i18n/label :t/close)
81+
:button-one-props {:type :grey
82+
:on-press hide-bottom-sheet}}]]))

src/status_im/contexts/onboarding/common/overlay/events.cljs

+14
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,17 @@
1717
{:events [:onboarding/overlay-dismiss]}
1818
[_]
1919
{:onboarding/overlay-dismiss-fx nil})
20+
21+
(re-frame/reg-fx
22+
:onboarding/overlay-show-fx
23+
(fn []
24+
(when-let [blur-show-fn @overlay/blur-show-fn-atom]
25+
(blur-show-fn))
26+
(when-let [push-animation-fn @profiles/push-animation-fn-atom]
27+
(push-animation-fn))))
28+
29+
(rf/defn overlay-show
30+
{:events [:onboarding/overlay-show]}
31+
[_]
32+
{:onboarding/overlay-show-fx nil})
33+

src/status_im/contexts/onboarding/events.cljs

+22-16
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,31 @@
125125
mnemonic key-uid]))
126126
on-error]})
127127

128+
;; TODO: clear syncing data if key-uid does not match
128129
(rf/defn seed-phrase-validated
129130
{:events [:onboarding/seed-phrase-validated]}
130131
[{: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)]]}))
132+
(let [next-screen (if (and (seq (:syncing/key-uid db))
133+
(= (:syncing/key-uid db) key-uid))
134+
:screen/onboarding.create-profile-password
135+
:screen/onboarding.create-profile)]
136+
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+
[next-screen
150+
(get db
151+
:onboarding/navigated-to-enter-seed-phrase-from-screen
152+
:screen/onboarding.new-to-status)]]})))
147153

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

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

+38-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,42 @@
2526
:title-accessibility-label :progress-screen-title
2627
:description-accessibility-label :progress-screen-sub-title}])
2728

29+
(defn navigate-to-enter-seed-phrase
30+
[view-id]
31+
(if (= view-id :screen/onboarding.syncing-progress-intro)
32+
(do
33+
(rf/dispatch [:navigate-back-to :screen/onboarding.sync-or-recover-profile])
34+
(debounce/debounce-and-dispatch
35+
[:onboarding/navigate-to-sign-in-by-seed-phrase :screen/onboarding.sync-or-recover-profile]
36+
300))
37+
(do
38+
(rf/dispatch [:navigate-back])
39+
(debounce/debounce-and-dispatch [:onboarding/overlay-show] 100)
40+
(debounce/debounce-and-dispatch [:open-modal :screen/onboarding.new-to-status] 200)
41+
(debounce/debounce-and-dispatch
42+
[:onboarding/navigate-to-sign-in-by-seed-phrase :screen/onboarding.new-to-status]
43+
300))))
44+
2845
(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)])
46+
[profile-color logged-in?]
47+
(let [view-id (rf/sub [:view-id])]
48+
[rn/view
49+
(when-not logged-in?
50+
[quo/button
51+
{:on-press #(navigate-to-enter-seed-phrase view-id)
52+
:accessibility-label :try-seed-phrase-button
53+
:customization-color profile-color
54+
:container-style style/try-again-button}
55+
(i18n/label :t/enter-seed-phrase)])
56+
[quo/button
57+
{:on-press (fn []
58+
(rf/dispatch [:syncing/clear-states])
59+
(rf/dispatch [:navigate-back]))
60+
:accessibility-label :try-again-later-button
61+
:customization-color profile-color
62+
:size 40
63+
:container-style style/try-again-button}
64+
(i18n/label :t/try-again)]]))
3965

4066
(defn- illustration
4167
[pairing-progress?]
@@ -47,6 +73,7 @@
4773
(defn view
4874
[in-onboarding?]
4975
(let [pairing-status (rf/sub [:pairing/pairing-status])
76+
logged-in? (rf/sub [:multiaccount/logged-in?])
5077
pairing-progress? (pairing-progress pairing-status)
5178
profile-color (or (:color (rf/sub [:onboarding/profile]))
5279
(rf/sub [:profile/customization-color]))]
@@ -58,7 +85,7 @@
5885
[page-title pairing-progress?]
5986
[illustration pairing-progress?]
6087
(when-not (pairing-progress pairing-status)
61-
[try-again-button profile-color])]))
88+
[try-again-button profile-color logged-in?])]))
6289

6390
(defn view-onboarding
6491
[]

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

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

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
(:require
33
[native-module.core :as native-module]
44
[status-im.common.emoji-picker.utils :as emoji-picker.utils]
5+
[status-im.constants :as constants]
56
[status-im.contexts.profile.config :as profile.config]
67
status-im.contexts.profile.recover.effects
78
[utils.re-frame :as rf]
@@ -17,11 +18,11 @@
1718
(assoc-in [:syncing :login-sha3-password] login-sha3-password))
1819

1920
:effects.profile/restore-and-login
20-
(merge (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 color
26-
:emoji (emoji-picker.utils/random-emoji)
27-
:fetchBackup true})}))
21+
(assoc (profile.config/create)
22+
:displayName display-name
23+
:mnemonic (security/safe-unmask-data seed-phrase)
24+
:password login-sha3-password
25+
:imagePath (profile.config/strip-file-prefix image-path)
26+
:customizationColor (or color constants/profile-default-color)
27+
:emoji (emoji-picker.utils/random-emoji)
28+
:fetchBackup true)}))

src/status_im/contexts/syncing/events.cljs

+20-3
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,29 @@
2626
(log/info "[local-pairing] input-connection-string-for-bootstrapping callback"
2727
{:response res
2828
: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)
29+
(let [response (transforms/json->clj res)
30+
installation-id (:installationId response)
31+
key-uid (:keyUID response)
32+
error (:error response)]
33+
(when (seq installation-id)
34+
(rf/dispatch [:syncing/set-syncing-installation-id installation-id key-uid]))
35+
(when (seq error)
3236
(rf/dispatch [:toasts/upsert
3337
{:type :negative
3438
:text error}]))))
3539

40+
(rf/defn initiate-pairing-process
41+
{:events [:syncing/initiate-pairing-process]}
42+
[{:keys [db]}]
43+
{:db (assoc db :syncing/pairing-process-initiated? true)})
44+
45+
(rf/defn set-syncing-installation-id
46+
{:events [:syncing/set-syncing-installation-id]}
47+
[{:keys [db]} installation-id key-uid]
48+
{:db (assoc db
49+
:syncing/key-uid key-uid
50+
:syncing/installation-id installation-id)})
51+
3652
(rf/defn preflight-outbound-check-for-local-pairing
3753
{:events [:syncing/preflight-outbound-check]}
3854
[_ set-checks-passed]
@@ -67,6 +83,7 @@
6783
(when (sync-utils/valid-connection-string? response)
6884
(on-valid-connection-string response)
6985
(rf/dispatch [:syncing/update-role constants/local-pairing-role-sender])
86+
(rf/dispatch [:syncing/initiate-pairing-process])
7087
(rf/dispatch [:hide-bottom-sheet])))]
7188
(when-not (and error (string/blank? error))
7289
(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
@@ -257,6 +257,11 @@
257257
(fn [{:keys [preview-privacy?]}]
258258
(boolean preview-privacy?)))
259259

260+
(re-frame/reg-sub :profile/installation-id
261+
:<- [:profile/profile]
262+
(fn [{:keys [installation-id]}]
263+
installation-id))
264+
260265
(defn- replace-multiaccount-image-uri
261266
[profile ens-names port font-file avatar-opts theme]
262267
(let [{:keys [key-uid ens-name? images

0 commit comments

Comments
 (0)