From 628b67130422ae039d980a7d98f63c369a520a93 Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 7 Jan 2025 14:22:00 +0100 Subject: [PATCH 1/2] [#21652] The main part of a backup flow is missing at Keycard migration flow and Create User flow --- .../contexts/keycard/create/events.cljs | 9 +++- .../contexts/keycard/migrate/events.cljs | 9 +++- .../add_account/create_account/events.cljs | 13 ----- .../create_account/events_test.cljs | 9 ---- .../new_keypair/confirm_backup/view.cljs | 52 ++++++++++++++----- .../create_account/select_keypair/view.cljs | 12 +++-- src/status_im/navigation/screens.cljs | 2 +- translations/en.json | 3 ++ 8 files changed, 68 insertions(+), 41 deletions(-) diff --git a/src/status_im/contexts/keycard/create/events.cljs b/src/status_im/contexts/keycard/create/events.cljs index cabebfa8002..f22e267098b 100644 --- a/src/status_im/contexts/keycard/create/events.cljs +++ b/src/status_im/contexts/keycard/create/events.cljs @@ -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]] diff --git a/src/status_im/contexts/keycard/migrate/events.cljs b/src/status_im/contexts/keycard/migrate/events.cljs index 919854941dd..0c89aadcc9b 100644 --- a/src/status_im/contexts/keycard/migrate/events.cljs +++ b/src/status_im/contexts/keycard/migrate/events.cljs @@ -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])] @@ -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 diff --git a/src/status_im/contexts/wallet/add_account/create_account/events.cljs b/src/status_im/contexts/wallet/add_account/create_account/events.cljs index 6660b768f19..b2551d30987 100644 --- a/src/status_im/contexts/wallet/add_account/create_account/events.cljs +++ b/src/status_im/contexts/wallet/add_account/create_account/events.cljs @@ -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 diff --git a/src/status_im/contexts/wallet/add_account/create_account/events_test.cljs b/src/status_im/contexts/wallet/add_account/create_account/events_test.cljs index efdf6b39695..70d05a2ae6d 100644 --- a/src/status_im/contexts/wallet/add_account/create_account/events_test.cljs +++ b/src/status_im/contexts/wallet/add_account/create_account/events_test.cljs @@ -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" diff --git a/src/status_im/contexts/wallet/add_account/create_account/new_keypair/confirm_backup/view.cljs b/src/status_im/contexts/wallet/add_account/create_account/new_keypair/confirm_backup/view.cljs index 59349382146..97d318427fe 100644 --- a/src/status_im/contexts/wallet/add_account/create_account/new_keypair/confirm_backup/view.cljs +++ b/src/status_im/contexts/wallet/add_account/create_account/new_keypair/confirm_backup/view.cljs @@ -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 [] @@ -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 @@ -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 diff --git a/src/status_im/contexts/wallet/add_account/create_account/select_keypair/view.cljs b/src/status_im/contexts/wallet/add_account/create_account/select_keypair/view.cljs index 4a0525a4379..c9d044fcc49 100644 --- a/src/status_im/contexts/wallet/add_account/create_account/select_keypair/view.cljs +++ b/src/status_im/contexts/wallet/add_account/create_account/select_keypair/view.cljs @@ -10,6 +10,13 @@ [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 @@ -17,10 +24,7 @@ :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) diff --git a/src/status_im/navigation/screens.cljs b/src/status_im/navigation/screens.cljs index 7e6fd15aac8..f66eb87c114 100644 --- a/src/status_im/navigation/screens.cljs +++ b/src/status_im/navigation/screens.cljs @@ -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}} diff --git a/translations/en.json b/translations/en.json index 24c216a6c0a..3aa50cee39f 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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", @@ -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", @@ -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", From 3870c3b1bd34b14e912e8f393017e46dcb3f9c1a Mon Sep 17 00:00:00 2001 From: andrey Date: Thu, 9 Jan 2025 11:57:12 +0100 Subject: [PATCH 2/2] typo --- translations/en.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translations/en.json b/translations/en.json index 3aa50cee39f..9e5f5fea35b 100644 --- a/translations/en.json +++ b/translations/en.json @@ -2920,7 +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", + "written-seed-ready": "I have written down my recovery phrase 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",