Skip to content

Commit f150b3b

Browse files
committed
Implement seed phrase fallback flow
status-im/status-go@83aa01c...2b6b665
1 parent 8cac0e4 commit f150b3b

File tree

12 files changed

+243
-41
lines changed

12 files changed

+243
-41
lines changed

src/legacy/status_im/pairing/core.cljs

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

224+
(defn should-show-syncing-pop-up?
225+
[db installations]
226+
(print " parvesh ---------------- show?" installations (:syncing/pairing-process-initiated? db))
227+
(print " parvesh ---------------- log ended")
228+
(and (:syncing/pairing-process-initiated? db)
229+
(first (filter #(not (get-in db [:pairing/installations (:id %)])) installations))))
230+
223231
(rf/defn handle-installations
224232
[{:keys [db]} installations]
225233
{:db (update db
@@ -228,7 +236,10 @@
228236
(fn [acc {:keys [id] :as i}]
229237
(update acc id merge (installation<-rpc i)))
230238
%
231-
installations))})
239+
installations))
240+
:fx [(when-let [new-installation (should-show-syncing-pop-up? db installations)]
241+
[:dispatch
242+
[:show-bottom-sheet {:content (fn [] [new-device-sheet/view (:id new-installation)])}]])]})
232243

233244
(rf/defn load-installations
234245
{:events [:pairing.callback/get-our-installations-success]}
@@ -243,6 +254,24 @@
243254
{}
244255
installations))})
245256

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

+13
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@
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})

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
@@ -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

+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
@@ -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

0 commit comments

Comments
 (0)