From 9f0fb417137b7258bca9ff29c171694d795d47d9 Mon Sep 17 00:00:00 2001 From: flexsurfer Date: Wed, 13 Nov 2024 11:15:14 +0100 Subject: [PATCH] [#21587] Unsupported light theme on Keycard profile key pair migration (#21588) [#21586] Keycard migration crashes the app on Android [#21601] Keycard is not empty screen appears at the wrong place of migration flow --- .../contexts/keycard/migrate/events.cljs | 22 +-- .../profile/backup_recovery_phrase/view.cljs | 37 ++--- .../add_account/create_account/events.cljs | 6 +- .../new_keypair/confirm_backup/view.cljs | 137 +++++++++--------- .../create_account/select_keypair/view.cljs | 7 +- src/status_im/navigation/screens.cljs | 50 +++++-- 6 files changed, 146 insertions(+), 113 deletions(-) diff --git a/src/status_im/contexts/keycard/migrate/events.cljs b/src/status_im/contexts/keycard/migrate/events.cljs index cea2c1a41b..919854941d 100644 --- a/src/status_im/contexts/keycard/migrate/events.cljs +++ b/src/status_im/contexts/keycard/migrate/events.cljs @@ -71,19 +71,21 @@ (rf/reg-event-fx :keycard/migration.get-phrase (fn [{:keys [db]}] - {:db (assoc-in db [:keycard :migration] nil) - :fx [[:dispatch [:navigate-back]] - (if (string/blank? (get-in db [:profile/profile :mnemonic])) - [:dispatch - [:open-modal :screen/use-recovery-phrase - {:on-success #(rf/dispatch [:keycard/migration.phrase-entered %])}]] - [:dispatch - [:open-modal :screen/backup-recovery-phrase - {:on-success #(rf/dispatch [:keycard/migration.phrase-backed-up %])}]])]})) + (let [mnemonic (get-in db [:profile/profile :mnemonic])] + {:db (assoc-in db [:keycard :migration] nil) + :fx [[:dispatch [:navigate-back]] + (if (string/blank? mnemonic) + [:dispatch + [:open-modal :screen/use-recovery-phrase-dark + {: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]) + :masked-seed-phrase (security/mask-data mnemonic)}]])]}))) (rf/reg-event-fx :keycard/migration.phrase-entered (fn [{:keys [db]} [{:keys [phrase]}]] - {:db (assoc-in db [:keycard :migration :masked-phrase] (security/mask-data phrase)) + {:db (assoc-in db [:keycard :migration :masked-phrase] phrase) :fx [[:dispatch [:navigate-back]] [:dispatch [:open-modal :screen/keycard.authorise diff --git a/src/status_im/contexts/profile/backup_recovery_phrase/view.cljs b/src/status_im/contexts/profile/backup_recovery_phrase/view.cljs index 16bd6ca835..c71ed1eb98 100644 --- a/src/status_im/contexts/profile/backup_recovery_phrase/view.cljs +++ b/src/status_im/contexts/profile/backup_recovery_phrase/view.cljs @@ -44,24 +44,28 @@ (defn view [] - (let [step-labels [:t/backup-step-1 :t/backup-step-2 :t/backup-step-3 - :t/backup-step-4] - checked? (reagent/atom - {:0 false - :1 false - :2 false - :3 false}) - revealed? (reagent/atom false) - customization-color (rf/sub [:profile/customization-color]) - {:keys [on-success]} (rf/sub [:get-screen-params]) - seed-phrase (reagent/atom []) - random-phrase (reagent/atom [])] + (let [step-labels [:t/backup-step-1 :t/backup-step-2 :t/backup-step-3 + :t/backup-step-4] + checked? (reagent/atom + {:0 false + :1 false + :2 false + :3 false}) + revealed? (reagent/atom false) + customization-color (rf/sub [:profile/customization-color]) + {:keys [on-success masked-seed-phrase]} (rf/sub [:get-screen-params]) + seed-phrase (reagent/atom (if masked-seed-phrase + (-> + (security/safe-unmask-data + masked-seed-phrase) + (string/split #"\s")) + []))] (fn [] (let [theme (quo.theme/use-theme)] (rn/use-mount (fn [] - (native-module/get-random-mnemonic #(reset! seed-phrase (string/split % #"\s"))) - (native-module/get-random-mnemonic #(reset! random-phrase (string/split % #"\s"))))) + (when-not masked-seed-phrase + (native-module/get-random-mnemonic #(reset! seed-phrase (string/split % #"\s")))))) [rn/view {:style {:flex 1}} [quo/page-nav {:icon-name :i/close @@ -106,10 +110,7 @@ :button-one-label (i18n/label :t/i-have-written) :button-one-props {:disabled? (some false? (vals @checked?)) :customization-color customization-color - :on-press #(on-success {:masked-seed-phrase - (security/mask-data - @seed-phrase) - :random-phrase @random-phrase})}}] + :on-press #(on-success (security/mask-data @seed-phrase))}}] [quo/text {:size :paragraph-2 :style (style/description-text theme)} 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 1695e49f56..50f1e6e011 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 @@ -30,12 +30,12 @@ (rf/reg-event-fx :wallet/confirm-account-origin confirm-account-origin) (defn store-new-seed-phrase - [{:keys [db]} [{:keys [seed-phrase random-phrase]}]] + [{:keys [db]} [{:keys [seed-phrase]}]] {:db (update-in db [:wallet :ui :create-account :new-keypair] assoc - :seed-phrase seed-phrase - :random-phrase random-phrase) + :seed-phrase + seed-phrase) :fx [[:dispatch-later [{:ms 20 :dispatch [:navigate-to :screen/wallet.confirm-backup]}]]]}) 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 70111dddcf..5934938214 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 @@ -1,5 +1,7 @@ (ns status-im.contexts.wallet.add-account.create-account.new-keypair.confirm-backup.view (:require + [clojure.string :as string] + [native-module.core :as native-module] [quo.core :as quo] [react-native.core :as rn] [reagent.core :as reagent] @@ -61,72 +63,77 @@ (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 random-phrase]} (rf/sub [:wallet/create-account-new-keypair]) - unmasked-seed-phrase (security/safe-unmask-data seed-phrase)] + (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 [])] (fn [] - (let [current-word-index (get random-indices - (min @quiz-index (dec questions-count))) - current-word (get unmasked-seed-phrase current-word-index) - [options-row-0 options-row-1] (random-words-with-string random-phrase current-word) - on-button-press (fn [word] - (if (= word current-word) - (do - (when (< @quiz-index questions-count) - (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}]))) - (do - (when (> @incorrect-count 0) - (rf/dispatch [:show-bottom-sheet - {:content cheat-warning}])) - (reset! incorrect-count (inc @incorrect-count)) - (reset! show-error? true))))] - [rn/view {:style {:flex 1}} - [quo/page-nav - {:icon-name :i/arrow-left - :on-press #(rf/dispatch [:navigate-back]) - :accessibility-label :top-bar}] - [quo/page-top - {:title (i18n/label :t/confirm-backup) - :description :text - :description-text (i18n/label :t/confirm-the-position)}] - [rn/flat-list - {:data random-indices - :render-fn (fn [num index] - [quo/quiz-item - {:state (cond - (and (= @quiz-index index) - (pos? @incorrect-count) - @show-error?) - :error + (rn/use-mount + (fn [] + (native-module/get-random-mnemonic #(reset! random-phrase (string/split % #"\s"))))) + (when-not (empty? @random-phrase) + (let [current-word-index (get random-indices + (min @quiz-index (dec questions-count))) + current-word (get unmasked-seed-phrase current-word-index) + [options-row-0 options-row-1] (random-words-with-string @random-phrase current-word) + on-button-press (fn [word] + (if (= word current-word) + (do + (when (< @quiz-index questions-count) + (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}]))) + (do + (when (> @incorrect-count 0) + (rf/dispatch [:show-bottom-sheet + {:content cheat-warning}])) + (reset! incorrect-count (inc @incorrect-count)) + (reset! show-error? true))))] + [rn/view {:style {:flex 1}} + [quo/page-nav + {:icon-name :i/arrow-left + :on-press #(rf/dispatch [:navigate-back]) + :accessibility-label :top-bar}] + [quo/page-top + {:title (i18n/label :t/confirm-backup) + :description :text + :description-text (i18n/label :t/confirm-the-position)}] + [rn/flat-list + {:data random-indices + :render-fn (fn [num index] + [quo/quiz-item + {:state (cond + (and (= @quiz-index index) + (pos? @incorrect-count) + @show-error?) + :error - (= @quiz-index index) - :empty + (= @quiz-index index) + :empty - (> @quiz-index index) - :success + (> @quiz-index index) + :success - :else - :disabled) - :word (get unmasked-seed-phrase num) - :number (inc num) - :on-press #(when (= @quiz-index index) - (reset! show-error? false))}]) - :separator [rn/view {:style {:height 8}}] - :content-container-style {:padding-horizontal 20}}] - [rn/view {:style style/buttons-container} - [buttons-row - {:on-press on-button-press - :margin-bottom 12 - :options options-row-0}] - [buttons-row - {:on-press on-button-press - :options options-row-1}]]])))) + :else + :disabled) + :word (get unmasked-seed-phrase num) + :number (inc num) + :on-press #(when (= @quiz-index index) + (reset! show-error? false))}]) + :separator [rn/view {:style {:height 8}}] + :content-container-style {:padding-horizontal 20}}] + [rn/view {:style style/buttons-container} + [buttons-row + {:on-press on-button-press + :margin-bottom 12 + :options options-row-0}] + [buttons-row + {:on-press on-button-press + :options options-row-1}]]]))))) 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 eb598d6d89..fd9c32fbdc 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 @@ -17,11 +17,10 @@ :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 [{:keys [masked-seed-phrase random-phrase]}] + {:on-success (fn [masked-seed-phrase] (rf/dispatch [:wallet/store-new-seed-phrase - {:seed-phrase masked-seed-phrase - :random-phrase - random-phrase}]))}])} + {:seed-phrase + masked-seed-phrase}]))}])} {: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 3499167c4c..65f5c4cbf9 100644 --- a/src/status_im/navigation/screens.cljs +++ b/src/status_im/navigation/screens.cljs @@ -318,7 +318,8 @@ {:name :screen/settings.keycard :metrics {:track? :true :alias-id :settings.keycard} - :options {:insets {:top? true :bottom? true}} + :options {:theme :dark + :insets {:top? true :bottom? true}} :component settings.keycard/view} {:name :edit-profile @@ -873,37 +874,44 @@ (def keycard-screens [{:name :screen/keycard.check :metrics {:track? :true} - :options {:insets {:top? true :bottom? true}} + :options {:theme :dark + :insets {:top? true :bottom? true}} :component keycard.check/view} {:name :screen/keycard.empty :metrics {:track? :true} - :options {:insets {:top? true :bottom? true}} + :options {:theme :dark + :insets {:top? true :bottom? true}} :component keycard.empty/view} {:name :screen/keycard.error :metrics {:track? :true} - :options {:insets {:top? true :bottom? true}} + :options {:theme :dark + :insets {:top? true :bottom? true}} :component keycard.error/view} {:name :screen/keycard.not-keycard :metrics {:track? :true} - :options {:insets {:top? true :bottom? true}} + :options {:theme :dark + :insets {:top? true :bottom? true}} :component keycard.not-keycard/view} {:name :screen/keycard.authorise :metrics {:track? :true} - :options {:insets {:top? true :bottom? true}} + :options {:theme :dark + :insets {:top? true :bottom? true}} :component keycard.authorise/view} {:name :screen/keycard.migrate :metrics {:track? :true} - :options {:insets {:top? true :bottom? true}} + :options {:theme :dark + :insets {:top? true :bottom? true}} :component keycard.migrate/view} {:name :screen/keycard.re-encrypting :metrics {:track? :true} - :options {:insets {:top? true :bottom? true} + :options {:theme :dark + :insets {:top? true :bottom? true} :popGesture false :hardwareBackButton {:dismissModalOnPress false :popStackOnPress false}} @@ -911,7 +919,8 @@ {:name :screen/keycard.migrate.success :metrics {:track? :true} - :options {:insets {:top? true :bottom? true} + :options {:theme :dark + :insets {:top? true :bottom? true} :popGesture false :hardwareBackButton {:dismissModalOnPress false :popStackOnPress false}} @@ -919,7 +928,8 @@ {:name :screen/keycard.migrate.fail :metrics {:track? :true} - :options {:insets {:top? true :bottom? true} + :options {:theme :dark + :insets {:top? true :bottom? true} :popGesture false :hardwareBackButton {:dismissModalOnPress false :popStackOnPress false}} @@ -927,17 +937,20 @@ {:name :screen/keycard.pin.create :metrics {:track? :true} - :options {:insets {:top? true :bottom? true}} + :options {:theme :dark + :insets {:top? true :bottom? true}} :component keycard.pin.create/view} {:name :screen/keycard.pin.enter :metrics {:track? :true} - :options {:insets {:top? true :bottom? true}} + :options {:theme :dark + :insets {:top? true :bottom? true}} :component keycard.pin.enter/view} {:name :screen/keycard.profile-keys :metrics {:track? :true} - :options {:insets {:top? true :bottom? true}} + :options {:theme :dark + :insets {:top? true :bottom? true}} :component keycard.migrate.profile-keys/view}]) (defn screens @@ -1009,10 +1022,21 @@ :options {:insets {:top? true :bottom? true}} :component backup-recovery-phrase/view} + {:name :screen/backup-recovery-phrase-dark + :metrics {:track? true} + :options {:theme :dark + :insets {:top? true :bottom? true}} + :component backup-recovery-phrase/view} + {:name :screen/use-recovery-phrase :metrics {:track? true} :component enter-seed-phrase/view} + {:name :screen/use-recovery-phrase-dark + :metrics {:track? true} + :options {:theme :dark} + :component enter-seed-phrase/view} + {:name :screen/profile.profiles :metrics {:track? true :alias-id :app.profiles}