From d04db52a09da0c0847e340a3a18f46777f6484b2 Mon Sep 17 00:00:00 2001 From: Mohsen Date: Thu, 9 May 2024 11:17:20 +0300 Subject: [PATCH] [#19917] feat: integrate rename keypair rpc call --- .../contexts/settings/wallet/events.cljs | 32 +++++++++++++++++++ .../contexts/settings/wallet/events_test.cljs | 17 ++++++++++ .../keypairs_and_accounts/rename/view.cljs | 14 ++++---- .../wallet/keypairs_and_accounts/view.cljs | 3 +- src/status_im/contexts/wallet/db.cljs | 5 ++- src/status_im/contexts/wallet/events.cljs | 1 + translations/en.json | 1 + 7 files changed, 65 insertions(+), 8 deletions(-) create mode 100644 src/status_im/contexts/settings/wallet/events.cljs create mode 100644 src/status_im/contexts/settings/wallet/events_test.cljs diff --git a/src/status_im/contexts/settings/wallet/events.cljs b/src/status_im/contexts/settings/wallet/events.cljs new file mode 100644 index 000000000000..234f97a7276c --- /dev/null +++ b/src/status_im/contexts/settings/wallet/events.cljs @@ -0,0 +1,32 @@ +(ns status-im.contexts.settings.wallet.events + (:require + [taoensso.timbre :as log] + [utils.i18n :as i18n] + [utils.re-frame :as rf])) + +(rf/reg-event-fx + :wallet/rename-keypair-success + (fn [{:keys [db]} [key-uid name]] + {:db (update-in db + [:wallet :keypairs] + (fn [keypairs] + (map (fn [keypair] + (if (= (keypair :key-uid) key-uid) + (assoc keypair :name name) + keypair)) + keypairs))) + :fx [[:dispatch [:navigate-back]] + [:dispatch + [:toasts/upsert + {:type :positive + :text (i18n/label :t/key-pair-name-updated)}]]]})) + +(defn rename-keypair + [_ [{:keys [key-uid keypair-name]}]] + {:fx [[:json-rpc/call + [{:method "accounts_updateKeypairName" + :params [key-uid keypair-name] + :on-success [:wallet/rename-keypair-success key-uid keypair-name] + :on-error #(log/info "failed to rename keypair " %)}]]]}) + +(rf/reg-event-fx :wallet/rename-keypair rename-keypair) diff --git a/src/status_im/contexts/settings/wallet/events_test.cljs b/src/status_im/contexts/settings/wallet/events_test.cljs new file mode 100644 index 000000000000..2e2db2b8a5f7 --- /dev/null +++ b/src/status_im/contexts/settings/wallet/events_test.cljs @@ -0,0 +1,17 @@ +(ns status-im.contexts.settings.wallet.events-test + (:require + [cljs.test :refer-macros [deftest is testing]] + matcher-combinators.test + [status-im.contexts.settings.wallet.events :as events] + [status-im.contexts.wallet.db :as db])) + +(deftest rename-keypair + (testing "rename-keypair" + (let [db {:wallet {}} + expected-db {:wallet db/defaults} + effects (events/rename-keypair + {:db db} + {:key-uid "0xfef454bb492ee4677594f8e05921c84f336fa811deb99b8d922477cc87a38b98" + :keypair-name "Key pair 2"}) + result-db (:db effects)] + (is (match? result-db expected-db))))) diff --git a/src/status_im/contexts/settings/wallet/keypairs_and_accounts/rename/view.cljs b/src/status_im/contexts/settings/wallet/keypairs_and_accounts/rename/view.cljs index a99610464e68..a7397220c97e 100644 --- a/src/status_im/contexts/settings/wallet/keypairs_and_accounts/rename/view.cljs +++ b/src/status_im/contexts/settings/wallet/keypairs_and_accounts/rename/view.cljs @@ -14,7 +14,7 @@ (defn view [] - (let [{:keys [name]} (rf/sub [:get-screen-params]) + (let [{:keys [name key-uid]} (rf/sub [:get-screen-params]) customization-color (rf/sub [:profile/customization-color]) [unsaved-keypair-name set-unsaved-keypair-name] (rn/use-state name) [error-msg set-error-msg] (rn/use-state nil) @@ -34,10 +34,12 @@ (validate-keypair-name text))) on-clear (rn/use-callback (fn [] (on-change-text ""))) - on-continue (rn/use-callback #(rf/dispatch - [:wallet/edit-keypair-name - unsaved-keypair-name]) - [unsaved-keypair-name])] + on-save (rn/use-callback #(rf/dispatch + [:wallet/rename-keypair + {:key-uid key-uid + :keypair-name + unsaved-keypair-name}]) + [unsaved-keypair-name key-uid])] [floating-button-page/view {:header [quo/page-nav {:icon-name :i/close @@ -50,7 +52,7 @@ (string/blank? unsaved-keypair-name) (not (string/blank? error-msg))) :customization-color customization-color - :on-press on-continue} + :on-press on-save} :container-style style/bottom-action}]} [quo/page-top {:container-style style/header-container diff --git a/src/status_im/contexts/settings/wallet/keypairs_and_accounts/view.cljs b/src/status_im/contexts/settings/wallet/keypairs_and_accounts/view.cljs index bea467c0ec1f..40110b2c0d71 100644 --- a/src/status_im/contexts/settings/wallet/keypairs_and_accounts/view.cljs +++ b/src/status_im/contexts/settings/wallet/keypairs_and_accounts/view.cljs @@ -58,7 +58,8 @@ :customization-color customization-color :profile-picture profile-picture} {:type :keypair - :icon-avatar :i/seed})) item)) + :icon-avatar :i/seed})) + item)) [customization-color default-keypair? name profile-picture shortened-key theme])] [quo/keypair diff --git a/src/status_im/contexts/wallet/db.cljs b/src/status_im/contexts/wallet/db.cljs index 6d98804f13b3..d9f0be704f46 100644 --- a/src/status_im/contexts/wallet/db.cljs +++ b/src/status_im/contexts/wallet/db.cljs @@ -6,4 +6,7 @@ :selected-networks (set constants/default-network-names)}) (def defaults - {:ui {:network-filter network-filter-defaults}}) + {:ui {:network-filter network-filter-defaults} + :keypairs [{:key-uid "0xfef454bb492ee4677594f8e05921c84f336fa811deb99b8d922477cc87a38b98" + :name "Key pair 1" + :type "seed"}]}) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 680e71713335..ec11f17fa0c8 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -4,6 +4,7 @@ [clojure.string :as string] [react-native.platform :as platform] [status-im.constants :as constants] + [status-im.contexts.settings.wallet.events] [status-im.contexts.wallet.common.utils.networks :as network-utils] [status-im.contexts.wallet.data-store :as data-store] [status-im.contexts.wallet.db :as db] diff --git a/translations/en.json b/translations/en.json index 8ae47b78805f..1a654b84c100 100644 --- a/translations/en.json +++ b/translations/en.json @@ -2571,6 +2571,7 @@ "keypair-name": "Key pair name", "keypair-name-description": "Name key pair for your own personal reference", "keypair-name-input-placeholder": "Collectibles account, Old vault....", + "key-pair-name-updated": "Key pair name updated", "goerli-testnet-toggle-confirmation": "Are you sure you want to toggle Goerli? This will log you out and you will have to login again.", "bridged-to": "Bridged to {{network}}", "slide-to-bridge": "Slide to bridge",