[#20165] feat: import a missing key pair by scanning QR code (#20280)

This commit is contained in:
Mohsen 2024-06-03 10:33:52 +03:00 committed by GitHub
parent 81cb058e29
commit 541b2e0909
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 38 deletions

View File

@ -6,7 +6,7 @@
[utils.security.core :as security] [utils.security.core :as security]
[utils.transforms :as transforms])) [utils.transforms :as transforms]))
(rf/reg-fx :effects.connection-string/export-keypair (rf/reg-fx :effects.syncing/export-keypairs-keystores
(fn [{:keys [key-uid sha3-pwd keypair-key-uid on-success on-fail]}] (fn [{:keys [key-uid sha3-pwd keypair-key-uid on-success on-fail]}]
(let [config-map (transforms/clj->json {:senderConfig {:loggedInKeyUid key-uid (let [config-map (transforms/clj->json {:senderConfig {:loggedInKeyUid key-uid
:keystorePath "" :keystorePath ""
@ -23,7 +23,7 @@
"generic-error: failed to get connection string"))))) "generic-error: failed to get connection string")))))
(promesa/catch on-fail))))) (promesa/catch on-fail)))))
(rf/reg-fx :effects.connection-string/import-keypair (rf/reg-fx :effects.syncing/import-keypairs-keystores
(fn [{:keys [key-uid sha3-pwd keypairs-key-uids connection-string on-success on-fail]}] (fn [{:keys [key-uid sha3-pwd keypairs-key-uids connection-string on-success on-fail]}]
(let [config-map (transforms/clj->json {:receiverConfig (let [config-map (transforms/clj->json {:receiverConfig
{:loggedInKeyUid key-uid {:loggedInKeyUid key-uid

View File

@ -31,7 +31,7 @@
(defn get-keypair-export-connection (defn get-keypair-export-connection
[{:keys [db]} [{:keys [sha3-pwd keypair-key-uid callback]}]] [{:keys [db]} [{:keys [sha3-pwd keypair-key-uid callback]}]]
(let [key-uid (get-in db [:profile/profile :key-uid])] (let [key-uid (get-in db [:profile/profile :key-uid])]
{:fx [[:effects.connection-string/export-keypair {:fx [[:effects.syncing/export-keypairs-keystores
{:key-uid key-uid {:key-uid key-uid
:sha3-pwd sha3-pwd :sha3-pwd sha3-pwd
:keypair-key-uid keypair-key-uid :keypair-key-uid keypair-key-uid
@ -88,7 +88,7 @@
(defn connection-string-for-import-keypair (defn connection-string-for-import-keypair
[{:keys [db]} [{:keys [sha3-pwd keypairs-key-uids connection-string]}]] [{:keys [db]} [{:keys [sha3-pwd keypairs-key-uids connection-string]}]]
(let [key-uid (get-in db [:profile/profile :key-uid])] (let [key-uid (get-in db [:profile/profile :key-uid])]
{:fx [[:effects.connection-string/import-keypair {:fx [[:effects.syncing/import-keypairs-keystores
{:key-uid key-uid {:key-uid key-uid
:sha3-pwd sha3-pwd :sha3-pwd sha3-pwd
:keypairs-key-uids keypairs-key-uids :keypairs-key-uids keypairs-key-uids

View File

@ -32,7 +32,7 @@
user-key-uid "test-key-uid" user-key-uid "test-key-uid"
callback (fn [connect-string] (println "callback" connect-string))] callback (fn [connect-string] (println "callback" connect-string))]
(testing "get-keypair-export-connection" (testing "get-keypair-export-connection"
(let [expected {:fx [[:effects.connection-string/export-keypair (let [expected {:fx [[:effects.syncing/export-keypairs-keystores
{:key-uid user-key-uid {:key-uid user-key-uid
:sha3-pwd sha3-pwd :sha3-pwd sha3-pwd
:keypair-key-uid mock-key-uid :keypair-key-uid mock-key-uid
@ -74,7 +74,7 @@
user-key-uid "test-key-uid" user-key-uid "test-key-uid"
connection-string "test-connection-string"] connection-string "test-connection-string"]
(testing "connection-string-for-import-keypair" (testing "connection-string-for-import-keypair"
(let [expected {:fx [[:effects.connection-string/import-keypair (let [expected {:fx [[:effects.syncing/import-keypairs-keystores
{:key-uid user-key-uid {:key-uid user-key-uid
:sha3-pwd sha3-pwd :sha3-pwd sha3-pwd
:keypairs-key-uids [mock-key-uid] :keypairs-key-uids [mock-key-uid]

View File

@ -1,44 +1,51 @@
(ns status-im.contexts.settings.wallet.keypairs-and-accounts.actions.view (ns status-im.contexts.settings.wallet.keypairs-and-accounts.actions.view
(:require [quo.core :as quo] (:require [quo.core :as quo]
[react-native.core :as rn]
[status-im.contexts.settings.wallet.keypairs-and-accounts.remove.view :as remove-key-pair] [status-im.contexts.settings.wallet.keypairs-and-accounts.remove.view :as remove-key-pair]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn on-rename-key-pair
[key-pair]
(rf/dispatch [:open-modal :screen/settings.rename-keypair key-pair]))
(defn on-remove-key-pair
[key-pair]
(rf/dispatch [:show-bottom-sheet
{:theme :dark
:content (fn []
[remove-key-pair/view key-pair])}]))
(defn on-show-qr
[data]
(rf/dispatch [:open-modal :screen/settings.encrypted-key-pair-qr data]))
(defn view (defn view
[props key-pair] [props keypair]
(let [has-paired-device (rf/sub [:pairing/has-paired-devices])] (let [has-paired-device (rf/sub [:pairing/has-paired-devices])
missing-keypair? (= (:stored props) :missing)
on-scan-qr (rn/use-callback #(rf/dispatch [:open-modal :screen/settings.scan-keypair-qr
[(:key-uid keypair)]])
[keypair])
on-show-qr (rn/use-callback #(rf/dispatch [:open-modal
:screen/settings.encrypted-key-pair-qr
keypair])
[keypair])
on-remove-keypair (rn/use-callback #(rf/dispatch
[:show-bottom-sheet
{:theme :dark
:content (fn []
[remove-key-pair/view keypair])}])
[keypair])
on-rename-keypair (rn/use-callback #(rf/dispatch [:open-modal :screen/settings.rename-keypair
keypair])
[keypair])]
[:<> [:<>
[quo/drawer-top props] [quo/drawer-top props]
[quo/action-drawer [quo/action-drawer
[(when has-paired-device [(when has-paired-device
[{:icon :i/qr-code (if-not missing-keypair?
:accessibility-label :show-key-pr-qr [{:icon :i/qr-code
:label (i18n/label :t/show-encrypted-qr-of-key-pairs) :accessibility-label :show-key-pr-qr
:on-press #(on-show-qr key-pair)}]) :label (i18n/label :t/show-encrypted-qr-of-key-pairs)
:on-press on-show-qr}]
[{:icon :i/scan
:accessibility-label :import-by-scan-qr
:label (i18n/label :t/import-by-scanning-encrypted-qr)
:on-press on-scan-qr}]))
(when (= (:type props) :keypair) (when (= (:type props) :keypair)
(concat [{:icon :i/edit
[{:icon :i/edit :accessibility-label :rename-key-pair
:accessibility-label :rename-key-pair :label (i18n/label :t/rename-key-pair)
:label (i18n/label :t/rename-key-pair) :on-press on-rename-keypair}
:on-press #(on-rename-key-pair key-pair)}] {:icon :i/delete
[{:icon :i/delete :accessibility-label :remove-key-pair
:accessibility-label :remove-key-pair :add-divider? true
:add-divider? true :danger? true
:danger? true :label (i18n/label :t/remove-key-pair-and-derived-accounts)
:label (i18n/label :t/remove-key-pair-and-derived-accounts) :on-press on-remove-keypair}])]]]))
:on-press #(on-remove-key-pair key-pair)}]))]]]))

View File

@ -2537,6 +2537,7 @@
"import-using-phrase": "Import using recovery phrase", "import-using-phrase": "Import using recovery phrase",
"import-from-keycard": "Import from Keycard", "import-from-keycard": "Import from Keycard",
"import-private-key": "Import private key", "import-private-key": "Import private key",
"import-by-scanning-encrypted-qr": "Import by scanning encrypted QR",
"backup-recovery-phrase": "Backup recovery phrase", "backup-recovery-phrase": "Backup recovery phrase",
"backup-recovery-phrase-description": "Save in a secure place that only you control, these 12 words give access to all of your funds.", "backup-recovery-phrase-description": "Save in a secure place that only you control, these 12 words give access to all of your funds.",
"how-to-backup": "How to backup your recovery phrase", "how-to-backup": "How to backup your recovery phrase",