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 14, 2024
1 parent 51a9474 commit 2003e5b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 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 @@ -4,17 +4,21 @@
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(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 All @@ -30,3 +34,25 @@
:on-error #(log/info "failed to rename keypair " %)}]]]})

(rf/reg-event-fx :wallet/rename-keypair rename-keypair)

(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 @@ -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 @@ -2575,6 +2575,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.",
"bridged-to": "Bridged to {{network}}",
"slide-to-bridge": "Slide to bridge",
Expand Down

0 comments on commit 2003e5b

Please sign in to comment.