Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keycard - Import a seed phrase into a new Keycard #21947

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/quo/components/onboarding/small_option_card/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@
button-label]])

(defn small-option-card
[{:keys [variant title subtitle button-label image max-height on-press accessibility-label button-type]
[{:keys [variant title subtitle button-label image max-height on-press accessibility-label
button-type container-style]
:or {variant :main accessibility-label :small-option-card}}]
(let [main-variant? (= variant :main)
card-component (if main-variant? main-variant icon-variant)
card-height (cond
(not main-variant?) style/icon-variant-height
max-height (min max-height style/main-variant-height)
:else style/main-variant-height)]
[rn/view {:style (style/card card-height)}
[rn/view {:style (merge (style/card card-height) container-style)}
[card-component
{:title title
:subtitle subtitle
Expand Down
7 changes: 7 additions & 0 deletions src/status_im/contexts/keycard/create/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@
{:pin pin
:on-success #(rf/dispatch [:keycard.login/recover-profile-and-login %])
:on-failure #(rf/dispatch [:keycard/on-action-with-pin-error %])}]]}))))

(rf/reg-event-fx :keycard/create.seed-phrase-entered
(fn [{:keys [db]} [key-uid masked-seed-phrase]]
(if (contains? (:profile/profiles-overview db) key-uid)
{:fx [[:dispatch [:onboarding/multiaccount-already-exists key-uid]]]}
{:db (assoc-in db [:keycard :create :masked-phrase] masked-seed-phrase)
:fx [[:dispatch [:keycard/create.create-or-enter-pin]]]})))
35 changes: 21 additions & 14 deletions src/status_im/contexts/keycard/empty/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,27 @@
{:title (i18n/label :t/keycard-empty)
:description :text
:description-text (i18n/label :t/what-to-do)}]
[rn/view {:style {:padding-horizontal 28 :padding-top 20}}
[quo/small-option-card
{:variant :main
:title (i18n/label :t/create-new-profile)
:subtitle (i18n/label :t/new-key-pair-keycard)
:button-label (i18n/label :t/lets-go)
:accessibility-label :create-new-profile-keycard
:image (resources/get-image :keycard-buy)
:button-type :primary
:on-press #(rf/dispatch [:keycard/create.get-phrase])}]]
[quo/information-box
{:type :default
:style {:margin-top 32 :margin-horizontal 28}}
(i18n/label :t/add-key-pair-desktop)]])
[quo/small-option-card
{:variant :main
:title (i18n/label :t/create-new-profile)
:subtitle (i18n/label :t/new-key-pair-keycard)
:button-label (i18n/label :t/lets-go)
:accessibility-label :create-new-profile-keycard
:container-style {:margin-horizontal 20 :margin-top 8}
:image (resources/get-image :keycard-buy)
:button-type :primary
:on-press #(rf/dispatch [:keycard/create.get-phrase])}]
[quo/small-option-card
{:variant :icon
:title (i18n/label :t/import-recovery-phrase-to-keycard)
:subtitle (i18n/label :t/store-key-pair-on-keycard)
:accessibility-label :import-recovery-phrase-to-keycard
:container-style {:margin 20}
:image (resources/get-image :use-keycard)
:on-press #(rf/dispatch [:open-modal :screen/use-recovery-phrase-dark
{:on-success (fn [{:keys [key-uid phrase]}]
(rf/dispatch [:keycard/create.seed-phrase-entered
key-uid phrase]))}])}]])

(defn view
[]
Expand Down
22 changes: 14 additions & 8 deletions src/status_im/contexts/onboarding/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,19 @@
[:navigate-to-within-stack [:screen/onboarding.enable-biometrics from-screen]]
[:onboarding/create-account-and-login])]]})))

(rf/reg-event-fx
:onboarding/multiaccount-already-exists
(fn [_ [key-uid]]
{:fx [[:effects.utils/show-confirmation
{:title (i18n/label :t/multiaccount-exists-title)
:content (i18n/label :t/multiaccount-exists-content)
:confirm-button-text (i18n/label :t/unlock)
:on-accept (fn []
(re-frame/dispatch [:pop-to-root :screen/profile.profiles])
;; Note - Profile selection is not working
(re-frame/dispatch [:profile/profile-selected key-uid]))
:on-cancel #(re-frame/dispatch [:pop-to-root :screen/profile.profiles])}]]}))

(rf/reg-event-fx
:onboarding/seed-phrase-validated
(fn [{:keys [db]} [seed-phrase key-uid]]
Expand All @@ -115,14 +128,7 @@
:onboarding/navigated-to-enter-seed-phrase-from-screen
:screen/onboarding.create-profile)]
(if (contains? (:profile/profiles-overview db) key-uid)
{:fx [[:effects.utils/show-confirmation
{:title (i18n/label :t/multiaccount-exists-title)
:content (i18n/label :t/multiaccount-exists-content)
:confirm-button-text (i18n/label :t/unlock)
:on-accept (fn []
(re-frame/dispatch [:pop-to-root :screen/profile.profiles])
(re-frame/dispatch [:profile/profile-selected key-uid]))
:on-cancel #(re-frame/dispatch [:pop-to-root :multiaccounts])}]]}
Parveshdhull marked this conversation as resolved.
Show resolved Hide resolved
{:fx [[:dispatch [:onboarding/multiaccount-already-exists key-uid]]]}
{:db (-> db
(assoc-in [:onboarding/profile :seed-phrase] seed-phrase)
(assoc-in [:onboarding/profile :key-uid] key-uid)
Expand Down
3 changes: 2 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"add-custom-token": "Add custom token",
"add-eth": "Add ETH",
"add-favourite": "Add favourite",
"add-key-pair-desktop": "To add existing key pair to the Keycard please use Status Desktop. If you'd like this feature on mobile, feel free to upvote them.",
"add-mailserver": "Add Status node",
"add-me-to-your-contacts": "Please add me to your contacts",
"add-members": "Add members",
Expand Down Expand Up @@ -1227,6 +1226,7 @@
"import-private-key": "Import private key",
"import-private-key-info": "New addresses cannot be derived from an account imported from a private key. Import using a seed phrase if you wish to derive addresses.",
"import-profile-key-pair": "Import profile key pair",
"import-recovery-phrase-to-keycard": "Import recovery phrase to Keycard",
"import-to-use-derived-accounts": "Import to use derived accounts",
"import-using-phrase": "Import using recovery phrase",
"in": "in",
Expand Down Expand Up @@ -2519,6 +2519,7 @@
"sticker-market": "Sticker market",
"storage": "Storage",
"store-confirmations": "Store confirmations",
"store-key-pair-on-keycard": "Store your existing key pair on Keycard",
"store-your-asets-on-keycard": "Store your assets on Keycard",
"strength-divider-okay-label": "Okay",
"strength-divider-strong-label": "Strong",
Expand Down