diff --git a/src/status_im/contexts/settings/wallet/events.cljs b/src/status_im/contexts/settings/wallet/events.cljs index 08b171eb1316..f88cbfbcf7f6 100644 --- a/src/status_im/contexts/settings/wallet/events.cljs +++ b/src/status_im/contexts/settings/wallet/events.cljs @@ -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 @@ -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) diff --git a/src/status_im/contexts/settings/wallet/keypairs_and_accounts/actions/view.cljs b/src/status_im/contexts/settings/wallet/keypairs_and_accounts/actions/view.cljs index 9a770939b699..717c9b70ae6f 100644 --- a/src/status_im/contexts/settings/wallet/keypairs_and_accounts/actions/view.cljs +++ b/src/status_im/contexts/settings/wallet/keypairs_and_accounts/actions/view.cljs @@ -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)}]))]]])) diff --git a/src/status_im/contexts/settings/wallet/keypairs_and_accounts/remove/view.cljs b/src/status_im/contexts/settings/wallet/keypairs_and_accounts/remove/view.cljs index 69dc004b7e41..f47a1d8694eb 100644 --- a/src/status_im/contexts/settings/wallet/keypairs_and_accounts/remove/view.cljs +++ b/src/status_im/contexts/settings/wallet/keypairs_and_accounts/remove/view.cljs @@ -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 diff --git a/translations/en.json b/translations/en.json index 844d34691b39..cca6e2f1e254 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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",