Skip to content

Commit

Permalink
[#19921] feat: integrate remove key pair endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen-ghafouri committed May 24, 2024
1 parent e5b6fe0 commit e8e8404
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 19 deletions.
38 changes: 32 additions & 6 deletions src/status_im/contexts/settings/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@
[utils.security.core :as security]
[utils.transforms :as transforms]))

(defn- update-keypair
[keypairs key-uid update-fn]
(mapcat (fn [keypair]
(if (= (keypair :key-uid) key-uid)
(let [updated (update-fn keypair)]
(if (nil? updated) [] [updated]))
[keypair]))
keypairs))

(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)))
#(update-keypair % key-uid (fn [keypair] (assoc keypair :name name))))
:fx [[:dispatch [:navigate-back]]
[:dispatch
[:toasts/upsert
Expand Down Expand Up @@ -53,3 +57,25 @@
handle-connection)))

(rf/reg-event-fx :wallet/get-key-pair-export-connection get-key-pair-export-connection)

(rf/reg-event-fx
:wallet/remove-keypair-success
(fn [{:keys [db]} [key-uid]]
{:db (update-in db
[:wallet :keypairs]
#(update-keypair % key-uid (fn [_] nil)))
:fx [[:dispatch [:hide-bottom-sheet]]
[:dispatch
[:toasts/upsert
{:type :positive
:text (i18n/label :t/key-pair-removed)}]]]}))

(defn remove-keypair
[_ [key-uid]]
{:fx [[:json-rpc/call
[{:method "accounts_deleteKeypair"
:params [key-uid]
:on-success [:wallet/remove-keypair-success key-uid]
:on-error #(log/info "failed to remove keypair " %)}]]]})

(rf/reg-event-fx :wallet/remove-keypair remove-keypair)
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
:label (i18n/label :t/show-encrypted-qr-of-key-pairs)
:on-press #(on-show-qr key-pair)}])
(when (= (:type props) :keypair)
[{: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)}])]]]))
(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)}]))]]]))
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

(defn view
[{:keys [name key-uid]}]
(let [customization-color (rf/sub [:profile/customization-color])
on-remove (rn/use-callback #()
[key-uid])]
(let [on-remove (rn/use-callback #(rf/dispatch
[:wallet/remove-keypair key-uid])
[key-uid])]
[:<>
[quo/page-top
{:container-style style/header-container
Expand Down
1 change: 1 addition & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2583,6 +2583,7 @@
"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",
"key-pair-removed": "Key pair and derived accounts has been removed",
"goerli-testnet-toggle-confirmation": "Are you sure you want to toggle Goerli? This will log you out and you will have to login again.",
"sepolia-active": "Sepolia active",
"testnet-not-available": "Testnet not available",
Expand Down

0 comments on commit e8e8404

Please sign in to comment.