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 00000000000..234f97a7276 --- /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 00000000000..c37b7452bcd --- /dev/null +++ b/src/status_im/contexts/settings/wallet/events_test.cljs @@ -0,0 +1,20 @@ +(ns status-im.contexts.settings.wallet.events-test + (:require + [cljs.test :refer-macros [deftest is]] + matcher-combinators.test + [status-im.contexts.settings.wallet.events :as sut])) + +(def key-uid "0xfef454bb492ee4677594f8e05921c84f336fa811deb99b8d922477cc87a38b98") + +(deftest rename-keypair-test + (let [new-keypair-name "key pair new" + cofx {:db {}} + expected {:fx [[:json-rpc/call + [{:method "accounts_updateKeypairName" + :params [key-uid new-keypair-name] + :on-success [:wallet/rename-keypair-success key-uid new-keypair-name] + :on-error fn?}]]]}] + (is (match? expected + (sut/rename-keypair cofx + [{:key-uid key-uid + :keypair-name new-keypair-name}]))))) 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 a99610464e6..a7397220c97 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 53fba8cf3a0..070c53f679b 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 @@ -15,14 +15,15 @@ (defn on-options-press [{:keys [theme] - :as props}] + :as props} keypair] (rf/dispatch [:show-bottom-sheet - {:content (fn [] [actions/view props]) + {:content (fn [] [actions/view props keypair]) :theme theme}])) (defn- keypair [{keypair-type :type - :keys [accounts name]} + :keys [accounts name] + :as item} _ _ {:keys [profile-picture compressed-key customization-color]}] (let [theme (quo.theme/use-theme) @@ -42,7 +43,8 @@ :profile-picture profile-picture) (not default-keypair?) (assoc :type :keypair - :icon-avatar :i/seed)))) + :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/events.cljs b/src/status_im/contexts/wallet/events.cljs index 3ee4328c9cf..107b31a4274 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/src/status_im/subs/wallet/wallet.cljs b/src/status_im/subs/wallet/wallet.cljs index fb50234188e..6fd98d73fa1 100644 --- a/src/status_im/subs/wallet/wallet.cljs +++ b/src/status_im/subs/wallet/wallet.cljs @@ -183,9 +183,10 @@ :<- [:wallet/keypairs] (fn [keypairs [_ format-options]] (->> keypairs - (map (fn [{:keys [accounts name type]}] + (map (fn [{:keys [accounts name type key-uid]}] {:type (keyword type) :name name + :key-uid key-uid :accounts (format-settings-keypair-accounts accounts format-options)}))))) (rf/reg-sub diff --git a/translations/en.json b/translations/en.json index 80f65d9abdb..ea9f57a78ab 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",