Skip to content

Commit

Permalink
[#21652] The main part of a backup flow is missing at Keycard migrati…
Browse files Browse the repository at this point in the history
…on flow and Create User flow
  • Loading branch information
flexsurfer committed Jan 9, 2025
1 parent 32a3f85 commit 628b671
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 41 deletions.
9 changes: 8 additions & 1 deletion src/status_im/contexts/keycard/create/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@
(rf/dispatch [:open-modal :screen/keycard.empty-create]))
(rf/dispatch [:keycard/on-application-info-error error])))}]]]}))

(defn- backup-recovery-phrase-success
[masked-seed-phrase]
(rf/dispatch [:navigate-back])
(rf/dispatch [:open-modal :screen/confirm-backup
{:masked-seed-phrase masked-seed-phrase
:on-success #(rf/dispatch [:keycard/create.phrase-backed-up %])}]))

(rf/reg-event-fx :keycard/create.get-phrase
(fn [{:keys [db]}]
{:db (assoc-in db [:keycard :create] nil)
:fx [[:dispatch [:navigate-back]]
[:dispatch
[:open-modal :screen/backup-recovery-phrase-dark
{:on-success #(rf/dispatch [:keycard/create.phrase-backed-up %])}]]]}))
{:on-success backup-recovery-phrase-success}]]]}))

(rf/reg-event-fx :keycard/create.phrase-backed-up
(fn [{:keys [db]} [masked-phrase-vector]]
Expand Down
9 changes: 8 additions & 1 deletion src/status_im/contexts/keycard/migrate/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
(rf/dispatch [:keycard/migration.continue])
(rf/dispatch [:keycard/on-application-info-error error])))}]]]}))

(defn- backup-recovery-phrase-success
[masked-seed-phrase]
(rf/dispatch [:navigate-back])
(rf/dispatch [:open-modal :screen/confirm-backup
{:masked-seed-phrase masked-seed-phrase
:on-success #(rf/dispatch [:keycard/migration.phrase-backed-up])}]))

(rf/reg-event-fx :keycard/migration.get-phrase
(fn [{:keys [db]}]
(let [mnemonic (get-in db [:profile/profile :mnemonic])]
Expand All @@ -80,7 +87,7 @@
{:on-success #(rf/dispatch [:keycard/migration.phrase-entered %])}]]
[:dispatch
[:open-modal :screen/backup-recovery-phrase-dark
{:on-success #(rf/dispatch [:keycard/migration.phrase-backed-up])
{:on-success backup-recovery-phrase-success
:masked-seed-phrase (security/mask-data mnemonic)}]])]})))

(rf/reg-event-fx :keycard/migration.phrase-entered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,6 @@

(rf/reg-event-fx :wallet/confirm-account-origin confirm-account-origin)

(defn store-new-seed-phrase
[{:keys [db]} [{:keys [seed-phrase]}]]
{:db (update-in db
[:wallet :ui :create-account :new-keypair]
assoc
:seed-phrase
seed-phrase)
:fx [[:dispatch-later
[{:ms 20
:dispatch [:navigate-to :screen/wallet.confirm-backup]}]]]})

(rf/reg-event-fx :wallet/store-new-seed-phrase store-new-seed-phrase)

(defn seed-phrase-validated
[{:keys [db]} [seed-phrase key-uid on-error]]
(let [keypair-already-added? (-> db
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@
result-db (:db effects)]
(is (match? result-db expected-db))))

(deftest store-seed-phrase-test
(let [db {}
props [{:seed-phrase "test-secret" :random-phrase "random-test"}]
expected-db {:wallet {:ui {:create-account {:new-keypair {:seed-phrase "test-secret"
:random-phrase "random-test"}}}}}
effects (events/store-new-seed-phrase {:db db} props)
result-db (:db effects)]
(is (match? result-db expected-db))))

(deftest store-account-generated-test
(let [db {:wallet {:ui {:create-account
{:new-keypair {:seed-phrase "test-secret"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,43 @@
:margin-right 12)]
[button (assoc params :word (second options))]])

(defn- complete-backup-sheet
[on-success]
(let [customization-color (rf/sub [:profile/customization-color])
[checked? set-checked] (rn/use-state false)]
[:<>
[quo/drawer-top {:title (i18n/label :t/complete-backup)}]
[quo/text
{:style style/cheat-description}
(i18n/label :t/ensure-written-recovery)]
[quo/disclaimer
{:checked? checked?
:container-style {:margin-horizontal 20}
:on-change #(set-checked (not checked?))}
(i18n/label :t/written-seed-ready)]
[quo/bottom-actions
{:actions :two-actions
:button-one-label (i18n/label :t/done)
:button-one-props {:disabled? (not checked?)
:customization-color customization-color
:on-press (fn []
(rf/dispatch [:hide-bottom-sheet])
(on-success))}
:button-two-label (i18n/label :t/cancel)
:button-two-props {:type :grey
:on-press (fn []
(rf/dispatch [:hide-bottom-sheet]))}}]]))

(defn view
[]
(let [random-indices (random-selection)
quiz-index (reagent/atom 0)
incorrect-count (reagent/atom 0)
show-error? (reagent/atom false)
{:keys [seed-phrase]} (rf/sub [:wallet/create-account-new-keypair])
unmasked-seed-phrase (security/safe-unmask-data seed-phrase)
random-phrase (reagent/atom [])]
(let [random-indices (random-selection)
quiz-index (reagent/atom 0)
incorrect-count (reagent/atom 0)
show-error? (reagent/atom false)
{:keys [on-success
masked-seed-phrase]} (rf/sub [:get-screen-params])
unmasked-seed-phrase (security/safe-unmask-data masked-seed-phrase)
random-phrase (reagent/atom [])]
(fn []
(rn/use-mount
(fn []
Expand All @@ -86,10 +114,10 @@
(reset! quiz-index (inc @quiz-index)))
(reset! incorrect-count 0)
(reset! show-error? false)
(when (= @quiz-index questions-count)
(rf/dispatch [:navigate-to
:screen/wallet.keypair-name
{:workflow :new-keypair}])))
(when (and on-success (= @quiz-index questions-count))
(rf/dispatch [:show-bottom-sheet
{:content (fn [] [complete-backup-sheet
on-success])}])))
(do
(when (> @incorrect-count 0)
(rf/dispatch [:show-bottom-sheet
Expand All @@ -98,7 +126,7 @@
(reset! show-error? true))))]
[rn/view {:style {:flex 1}}
[quo/page-nav
{:icon-name :i/arrow-left
{:icon-name :i/close
:on-press #(rf/dispatch [:navigate-back])
:accessibility-label :top-bar}]
[quo/page-top
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn- backup-recovery-phrase-success
[masked-seed-phrase]
(rf/dispatch [:navigate-to :screen/confirm-backup
{:masked-seed-phrase masked-seed-phrase
:on-success #(rf/dispatch [:navigate-to :screen/wallet.keypair-name
{:workflow :new-keypair}])}]))

(defn- keypair-options
[]
[quo/action-drawer
[[{:icon :i/add
:accessibility-label :generate-new-keypair
:label (i18n/label :t/generate-new-keypair)
:on-press #(rf/dispatch [:navigate-to :screen/backup-recovery-phrase
{:on-success (fn [masked-seed-phrase]
(rf/dispatch [:wallet/store-new-seed-phrase
{:seed-phrase
masked-seed-phrase}]))}])}
{:on-success backup-recovery-phrase-success}])}
{:icon :i/seed
:accessibility-label :import-using-phrase
:label (i18n/label :t/import-using-phrase)
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/navigation/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@
:alias-id :wallet.create-account-edit-derivation-path}
:component wallet-edit-derivation-path/view}

{:name :screen/wallet.confirm-backup
{:name :screen/confirm-backup
:metrics {:track? true
:alias-id :wallet.create-account-backup-new-keypair-confirm}
:options {:insets {:top? true :bottom? true}}
Expand Down
3 changes: 3 additions & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@
"community-thumbnail-image": "Thumbnail image",
"community-thumbnail-upload": "Upload",
"community-unmuted": "Community unmuted",
"complete-backup": "Complete backup",
"complete-hardwallet-setup": "This card is now linked. You need it to sign transactions and unlock your keys",
"completed": "Completed",
"confirm": "Confirm",
Expand Down Expand Up @@ -971,6 +972,7 @@
"ens-your-your-name": "Your ENS name",
"ensure-both-devices-are-on-the-same-network": "Ensure both devices are on the same network",
"ensure-qr-code-is-in-focus-to-scan": "Ensure that the QR code is in focus to scan",
"ensure-written-recovery": "Ensure you have written down your recovery phrase and have a safe place to keep it. Remember, anyone who has your recovery phrase has access to your funds.",
"enter-12-words": "Enter the 12 words of your seed phrase, separated by single spaces",
"enter-a-private-key": "Enter a private key",
"enter-a-seed-phrase": "Enter a seed phrase",
Expand Down Expand Up @@ -2918,6 +2920,7 @@
"other": "{{count}} words"
},
"write-down-and-store-securely": "Write codes down\n & store them securely",
"written-seed-ready": "I have written down my seed recovery and ready to complete backup and remove it from device",
"wrong-address": "Wrong address",
"wrong-card": "Wrong card",
"wrong-card-text": "Tapped card does not correspond to the keys you selected",
Expand Down

0 comments on commit 628b671

Please sign in to comment.