Skip to content

Commit

Permalink
Keycard - Import a seed phrase into a new Keycard
Browse files Browse the repository at this point in the history
  • Loading branch information
Parveshdhull committed Jan 19, 2025
1 parent 64fb344 commit 83260f4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 25 deletions.
2 changes: 1 addition & 1 deletion shadow-cljs.edn
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
:after-load-async status-im.setup.hot-reload/reload
:build-notify status-im.setup.hot-reload/build-notify
:preloads [;; The official recommendation is to
;; load the debugger preload first.
user
flow-storm.api
dev.re-frisk-preload
status-im.setup.schema-preload
Expand Down
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]
[{:keys [variant title subtitle button-label image max-height on-press accessibility-label
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)
{:dispatch [:onboarding/multiaccount-already-exists key-uid]}
{:db (assoc-in db [:keycard :create :masked-phrase] masked-seed-phrase)
:dispatch [:keycard/create.create-or-enter-pin]})))
35 changes: 22 additions & 13 deletions src/status_im/contexts/keycard/empty/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@
{: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)
: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)
: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 [:navigate-to-within-stack
[:screen/onboarding.enter-seed-phrase
:screen/keycard.empty-create]
{: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])}]]}
{: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 @@ -57,7 +57,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 @@ -1214,6 +1213,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 @@ -2489,6 +2489,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

0 comments on commit 83260f4

Please sign in to comment.