Skip to content

Commit

Permalink
[#19917] feat: integrate rename keypair rpc call
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen-ghafouri committed May 9, 2024
1 parent 979217e commit d04db52
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
32 changes: 32 additions & 0 deletions src/status_im/contexts/settings/wallet/events.cljs
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 17 additions & 0 deletions src/status_im/contexts/settings/wallet/events_test.cljs
Original file line number Diff line number Diff line change
@@ -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)))))
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/status_im/contexts/wallet/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]})
1 change: 1 addition & 0 deletions src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d04db52

Please sign in to comment.