From 541b2e0909f7407cce58b124191dce03fd07a2bc Mon Sep 17 00:00:00 2001 From: Mohsen Date: Mon, 3 Jun 2024 10:33:52 +0300 Subject: [PATCH] [#20165] feat: import a missing key pair by scanning QR code (#20280) --- .../contexts/settings/wallet/effects.cljs | 4 +- .../contexts/settings/wallet/events.cljs | 4 +- .../contexts/settings/wallet/events_test.cljs | 4 +- .../keypairs_and_accounts/actions/view.cljs | 71 ++++++++++--------- translations/en.json | 1 + 5 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/status_im/contexts/settings/wallet/effects.cljs b/src/status_im/contexts/settings/wallet/effects.cljs index 221feea3b4c..3ed7219e000 100644 --- a/src/status_im/contexts/settings/wallet/effects.cljs +++ b/src/status_im/contexts/settings/wallet/effects.cljs @@ -6,7 +6,7 @@ [utils.security.core :as security] [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]}] (let [config-map (transforms/clj->json {:senderConfig {:loggedInKeyUid key-uid :keystorePath "" @@ -23,7 +23,7 @@ "generic-error: failed to get connection string"))))) (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]}] (let [config-map (transforms/clj->json {:receiverConfig {:loggedInKeyUid key-uid diff --git a/src/status_im/contexts/settings/wallet/events.cljs b/src/status_im/contexts/settings/wallet/events.cljs index c03e2dd40b9..834d3142893 100644 --- a/src/status_im/contexts/settings/wallet/events.cljs +++ b/src/status_im/contexts/settings/wallet/events.cljs @@ -31,7 +31,7 @@ (defn get-keypair-export-connection [{:keys [db]} [{:keys [sha3-pwd keypair-key-uid callback]}]] (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 :sha3-pwd sha3-pwd :keypair-key-uid keypair-key-uid @@ -88,7 +88,7 @@ (defn connection-string-for-import-keypair [{:keys [db]} [{:keys [sha3-pwd keypairs-key-uids connection-string]}]] (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 :sha3-pwd sha3-pwd :keypairs-key-uids keypairs-key-uids diff --git a/src/status_im/contexts/settings/wallet/events_test.cljs b/src/status_im/contexts/settings/wallet/events_test.cljs index f74b20e7c26..978c6e3df0d 100644 --- a/src/status_im/contexts/settings/wallet/events_test.cljs +++ b/src/status_im/contexts/settings/wallet/events_test.cljs @@ -32,7 +32,7 @@ user-key-uid "test-key-uid" callback (fn [connect-string] (println "callback" connect-string))] (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 :sha3-pwd sha3-pwd :keypair-key-uid mock-key-uid @@ -74,7 +74,7 @@ user-key-uid "test-key-uid" connection-string "test-connection-string"] (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 :sha3-pwd sha3-pwd :keypairs-key-uids [mock-key-uid] diff --git a/src/status_im/contexts/settings/wallet/keypairs_and_accounts/actions/view.cljs b/src/status_im/contexts/settings/wallet/keypairs_and_accounts/actions/view.cljs index 717c9b70ae6..9faeb0f161c 100644 --- a/src/status_im/contexts/settings/wallet/keypairs_and_accounts/actions/view.cljs +++ b/src/status_im/contexts/settings/wallet/keypairs_and_accounts/actions/view.cljs @@ -1,44 +1,51 @@ (ns status-im.contexts.settings.wallet.keypairs-and-accounts.actions.view (:require [quo.core :as quo] + [react-native.core :as rn] [status-im.contexts.settings.wallet.keypairs-and-accounts.remove.view :as remove-key-pair] [utils.i18n :as i18n] [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 - [props key-pair] - (let [has-paired-device (rf/sub [:pairing/has-paired-devices])] + [props keypair] + (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/action-drawer [(when has-paired-device - [{:icon :i/qr-code - :accessibility-label :show-key-pr-qr - :label (i18n/label :t/show-encrypted-qr-of-key-pairs) - :on-press #(on-show-qr key-pair)}]) + (if-not missing-keypair? + [{:icon :i/qr-code + :accessibility-label :show-key-pr-qr + :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) - (concat - [{:icon :i/edit - :accessibility-label :rename-key-pair - :label (i18n/label :t/rename-key-pair) - :on-press #(on-rename-key-pair key-pair)}] - [{:icon :i/delete - :accessibility-label :remove-key-pair - :add-divider? true - :danger? true - :label (i18n/label :t/remove-key-pair-and-derived-accounts) - :on-press #(on-remove-key-pair key-pair)}]))]]])) + [{:icon :i/edit + :accessibility-label :rename-key-pair + :label (i18n/label :t/rename-key-pair) + :on-press on-rename-keypair} + {:icon :i/delete + :accessibility-label :remove-key-pair + :add-divider? true + :danger? true + :label (i18n/label :t/remove-key-pair-and-derived-accounts) + :on-press on-remove-keypair}])]]])) diff --git a/translations/en.json b/translations/en.json index a0ac7ae660f..3e12c7fe146 100644 --- a/translations/en.json +++ b/translations/en.json @@ -2537,6 +2537,7 @@ "import-using-phrase": "Import using recovery phrase", "import-from-keycard": "Import from Keycard", "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-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",