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 13, 2024
1 parent 42a0908 commit eb0e7df
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 11 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)
20 changes: 20 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,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}])))))
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 @@ -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)
Expand All @@ -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
Expand Down
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
3 changes: 2 additions & 1 deletion src/status_im/subs/wallet/wallet.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 eb0e7df

Please sign in to comment.