[#19921] feat: remove key pair action (#20002)

This commit is contained in:
Mohsen 2024-05-27 15:58:39 +03:00 committed by GitHub
parent 711bcb2507
commit de71df811b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 125 additions and 25 deletions

View File

@ -78,7 +78,8 @@
(str description " · " (i18n/label :t/on-device))])
(defn- context-tag-subtitle
[{:keys [context-tag-type community-logo community-name account-name emoji customization-color
[{:keys [context-tag-type context icon community-logo community-name account-name emoji
customization-color
full-name profile-picture]}]
(let [tag-type (or context-tag-type :account)]
[rn/view
@ -94,7 +95,9 @@
:size 24
:customization-color customization-color
:profile-picture profile-picture
:full-name full-name}]]))
:full-name full-name
:context context
:icon icon}]]))
(defn- description-subtitle
[{:keys [theme blur? description]}]
@ -106,7 +109,8 @@
(defn- subtitle
[{:keys [type theme blur? stored networks description community-name community-logo
context-tag-type account-name emoji customization-color full-name profile-picture]}]
context-tag-type account-name emoji customization-color full-name profile-picture context
icon]}]
(cond
(= :keypair type)
[keypair-subtitle
@ -136,7 +140,9 @@
:emoji emoji
:customization-color customization-color
:profile-picture profile-picture
:full-name full-name}]
:full-name full-name
:context context
:icon icon}]
(and (not= :label type) description)
[description-subtitle
@ -198,7 +204,8 @@
[{:keys [title title-icon type description blur? community-name community-logo button-icon
account-name emoji context-tag-type button-type container-style
on-button-press on-button-long-press profile-picture stored networks label full-name
button-disabled? account-avatar-emoji account-avatar-type customization-color icon-avatar]}]
button-disabled? account-avatar-emoji account-avatar-type customization-color icon-avatar
context icon]}]
(let [theme (quo.theme/use-theme)]
[rn/view {:style (merge style/container container-style)}
(when (left-image-supported-types type)
@ -232,7 +239,9 @@
:account-name account-name
:emoji emoji
:full-name full-name
:profile-picture profile-picture}]]
:profile-picture profile-picture
:context context
:icon icon}]]
[right-icon
{:theme theme
:type type

View File

@ -70,9 +70,9 @@
:type => :neutral/:negative/:positive
"
[{:keys [type icon title text action undo-duration undo-on-press container-style user]
[{:keys [type icon title text action undo-duration undo-on-press container-style theme user]
:or {type :neutral icon :i/placeholder}}]
(let [theme (quo.theme/use-theme)
(let [theme (or theme (quo.theme/use-theme))
icon-name (case type
:positive (if (= theme :light)
:i/correct

View File

@ -8,22 +8,28 @@
[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)
(if-let [updated (update-fn keypair)]
[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
{:type :positive
:text (i18n/label :t/key-pair-name-updated)}]]]}))
{:type :positive
:theme :dark
:text (i18n/label :t/key-pair-name-updated)}]]]}))
(defn rename-keypair
[_ [{:keys [key-uid keypair-name]}]]
@ -53,3 +59,26 @@
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
:theme :dark
: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)

View File

@ -1,18 +1,26 @@
(ns status-im.contexts.settings.wallet.keypairs-and-accounts.actions.view
(:require [quo.core :as quo]
[status-im.contexts.settings.wallet.keypairs-and-accounts.remove.view :as remove-key-pair]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn on-rename-request
[data]
(rf/dispatch [:open-modal :screen/settings.rename-keypair data]))
(defn on-rename-key-pair
[key-pair]
(rf/dispatch [:open-modal :screen/settings.rename-keypair key-pair]))
(defn on-remove-key-pair
[key-pair]
(rf/dispatch [:show-bottom-sheet
{:theme :dark
:content (fn []
[remove-key-pair/view key-pair])}]))
(defn on-show-qr
[data]
(rf/dispatch [:open-modal :screen/settings.encrypted-key-pair-qr data]))
(defn view
[props data]
[props key-pair]
(let [has-paired-device (rf/sub [:pairing/has-paired-devices])]
[:<>
[quo/drawer-top props]
@ -21,9 +29,16 @@
[{:icon :i/qr-code
:accessibility-label :show-key-pr-qr
:label (i18n/label :t/show-encrypted-qr-of-key-pairs)
:on-press #(on-show-qr data)}])
: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-request data)}])]]]))
(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)}]))]]]))

View File

@ -0,0 +1,7 @@
(ns status-im.contexts.settings.wallet.keypairs-and-accounts.remove.style)
(def header-container
{:margin-bottom 8})
(def content
{:margin-horizontal 20})

View File

@ -0,0 +1,36 @@
(ns status-im.contexts.settings.wallet.keypairs-and-accounts.remove.view
(:require [quo.core :as quo]
[quo.foundations.colors :as colors]
[react-native.core :as rn]
[status-im.common.standard-authentication.core :as standard-auth]
[status-im.contexts.settings.wallet.keypairs-and-accounts.remove.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn view
[{:keys [name key-uid]}]
(let [on-remove (rn/use-callback #(rf/dispatch
[:wallet/remove-keypair key-uid])
[key-uid])]
[:<>
[quo/drawer-top
{:container-style style/header-container
:title (i18n/label :t/remove-key-pair-and-derived-accounts)
:type :context-tag
:context-tag-type :icon
:context name
:icon :i/seed-phrase}]
[rn/view {:style style/content}
[quo/text
{:style {:margin-top 4}
:weight :regular
:size :paragraph-1}
(i18n/label :t/the-key-pair-and-derived-accounts-will-be-removed)]
[standard-auth/slide-button
{:size :size-48
:track-text (i18n/label :t/slide-to-remove-key-pair)
:container-style {:margin-top 34}
:customization-color colors/danger-50
:on-auth-success on-remove
:auth-button-label (i18n/label :t/confirm)}]]]))

View File

@ -1259,6 +1259,8 @@
"remove-network": "Remove network",
"remove-token": "Remove token",
"removed": "removed",
"remove-key-pair-and-derived-accounts": "Remove key pair and derived accounts",
"the-key-pair-and-derived-accounts-will-be-removed": "The key pair and derived accounts will be removed from all of your synced devices. Make sure you have a backup of your keys or seed phrase before proceeding.",
"rename-key-pair": "Rename key pair",
"repeat-pin": "Repeat new 6-digit passcode",
"repeat-puk": "Repeat new 12-digit PUK",
@ -1975,6 +1977,7 @@
"slide-to-request-to-join": "Slide to request to join",
"slide-to-reveal-code": "Slide to reveal code",
"slide-to-create-account": "Slide to create account",
"slide-to-remove-key-pair": "Slide to remove key pair",
"slide-to-reveal-qr-code": "Slide to reveal QR code",
"minimum-received": "Minimum received",
"powered-by-paraswap": "Powered by Paraswap",
@ -2581,6 +2584,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",