Skip to content

Commit

Permalink
[#19917] feat: rename keypair from wallet settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsen-ghafouri committed May 8, 2024
1 parent 6c0c307 commit f064210
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 14 deletions.
Binary file added resources/images/icons2/12x12/seed-phrase@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/icons2/12x12/seed-phrase@3x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/status_im/common/validation/keypair.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(ns status-im.common.validation.keypair
(:require [clojure.string :as string]
[status-im.common.validation.general :as validators]
[status-im.constants :as constants]
utils.emojilib
[utils.i18n :as i18n]))

(defn keypair-too-short? [s] (< (count (string/trim (str s))) constants/keypair-name-min-length))
(defn keypair-too-long? [s] (> (count (string/trim (str s))) constants/keypair-name-max-length))

(defn validation-keypair-name
[s]
(cond
(string/blank? s) nil
(validators/has-emojis? s) (i18n/label :t/key-name-error-emoji)
(validators/has-special-characters? s) (i18n/label :t/key-name-error-special-char)
(keypair-too-short? s) (i18n/label :t/your-key-pair-name-is-too-short)
(keypair-too-long? s) (i18n/label :t/your-key-pair-name-is-too-long)))
27 changes: 27 additions & 0 deletions src/status_im/common/validation/keypair_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns status-im.common.validation.keypair-test
(:require
[cljs.test :refer-macros [deftest are]]
[status-im.common.validation.keypair :as keypair-validator]
[utils.i18n :as i18n]))

(deftest keypair-name-too-short-test
(are [arg expected]
(expected (keypair-validator/keypair-too-short? arg))
"abc" true?
"abcdef" false?))

(deftest keypair-name-too-long-test
(are [arg expected]
(expected (keypair-validator/keypair-too-long? arg))
(apply str (repeat 25 "a")) true?
"abcdef" false?))

(deftest validation-keypair-name-test
(are [arg expected]
(= (keypair-validator/validation-keypair-name arg) expected)
nil nil
"" nil
"name !" (i18n/label :t/key-name-error-special-char)
"Hello 😊" (i18n/label :t/key-name-error-emoji)
"abc" (i18n/label :t/key-name-error-length)
(apply str (repeat 25 "a")) (i18n/label :t/key-name-error-length)))
3 changes: 3 additions & 0 deletions src/status_im/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
(def ^:const contact-request-message-state-declined 3)
(def ^:const contact-request-message-max-length 280)

(def ^:const keypair-name-max-length 20)
(def ^:const keypair-name-min-length 5)

(def request-to-join-pending-state 1)

(def reactions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
(ns status-im.contexts.settings.wallet.keypairs-and-accounts.actions.view
(:require [quo.core :as quo]))
(:require [quo.core :as quo]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn on-rename-request
[data]
(rf/dispatch [:open-modal :screen/settings.rename-keypair data]))

(defn view
[props]
[quo/drawer-top
(merge props {:blur? true})])
[props data]
[:<>
[quo/drawer-top
(merge props {:blur? true})]
[quo/action-drawer
[(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)}])]]])
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(ns status-im.contexts.settings.wallet.keypairs-and-accounts.rename.style)

(def header-container
{:margin-bottom 8})

(def bottom-action
{:margin-horizontal -20})

(def error-container
{:margin-left 20
:margin-vertical 8})
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
(ns status-im.contexts.settings.wallet.keypairs-and-accounts.rename.view
(:require [clojure.string :as string]
[quo.core :as quo]
[react-native.core :as rn]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.common.validation.keypair :as keypair-validator]
[status-im.constants :as constants]
[status-im.contexts.settings.wallet.keypairs-and-accounts.rename.style :as style]
[utils.debounce :as debounce]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn navigation-back [] (rf/dispatch [:navigate-back]))

(defn view
[]
(let [{:keys [name]} (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)
[typing? set-typing?] (rn/use-state false)
validate-keypair-name (rn/use-callback
(debounce/debounce
(fn [name]
(set-error-msg
(keypair-validator/validation-keypair-name
name))
(set-typing? false))
300))
on-change-text (rn/use-callback (fn [text]
(set-typing? true)
(set-unsaved-keypair-name
text)
(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])]
[floating-button-page/view
{:header [quo/page-nav
{:icon-name :i/close
:on-press navigation-back
:accessibility-label :top-bar}]
:footer [quo/bottom-actions
{:actions :one-action
:button-one-label (i18n/label :t/save)
:button-one-props {:disabled? (or typing?
(string/blank? unsaved-keypair-name)
(not (string/blank? error-msg)))
:customization-color customization-color
:on-press on-continue}
:container-style style/bottom-action}]}
[quo/page-top
{:container-style style/header-container
:title (i18n/label :t/rename-key-pair)
:description :context-tag
:context-tag {:type :icon
:size 24
:context name
:icon :i/seed-phrase}}]
[quo/input
{:container-style {:margin-horizontal 20}
:placeholder (i18n/label :t/keypair-name-input-placeholder)
:label (i18n/label :t/keypair-name)
:default-value unsaved-keypair-name
:char-limit constants/keypair-name-max-length
:max-length constants/keypair-name-max-length
:auto-focus true
:clearable? (not (string/blank? unsaved-keypair-name))
:on-clear on-clear
:on-change-text on-change-text
:error? (not (string/blank? error-msg))}]
(when-not (string/blank? error-msg)
[quo/info-message
{:type :error
:size :default
:icon :i/info
:container-style style/error-container}
error-msg])]))

Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@

(defn on-options-press
[{:keys [theme]
:as props}]
:as props} data]
(rf/dispatch [:show-bottom-sheet
{:content (fn [] [actions/view props])
{:content (fn [] [actions/view props data])
:theme theme}]))

(defn- keypair
Expand All @@ -58,7 +58,8 @@
:customization-color customization-color
:profile-picture profile-picture}
{:type :keypair
:icon-avatar :i/seed}))))
:icon-avatar :i/seed}))
item))
[customization-color default-keypair? details profile-picture theme])]
[quo/keypair
{:blur? false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
[react-native.core :as rn]
[status-im.common.floating-button-page.view :as floating-button-page]
[status-im.common.validation.general :as validators]
[status-im.constants :as constants]
[status-im.contexts.wallet.add-account.create-account.new-keypair.keypair-name.style :as style]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(def keypair-name-max-length 15)
(def keypair-name-min-length 5)

(def error-messages
{:length (i18n/label :t/key-name-error-length)
:emoji (i18n/label :t/key-name-error-emoji)
Expand All @@ -26,7 +24,8 @@
on-change-text (rn/use-callback (fn [value]
(set-keypair-name value)
(cond
(> (count value) keypair-name-max-length)
(> (count value)
constants/keypair-name-max-length)
(set-error :length)
(validators/has-emojis? value) (set-error
:emoji)
Expand All @@ -48,9 +47,9 @@
:button-one-label (i18n/label :t/continue)
:button-one-props {:disabled? (or (pos? error)
(< (count keypair-name)
keypair-name-min-length)
constants/keypair-name-min-length)
(> (count keypair-name)
keypair-name-max-length))
constants/keypair-name-max-length))
:customization-color customization-color
:on-press on-continue}
:container-style style/bottom-action}]}
Expand All @@ -62,7 +61,7 @@
{:container-style {:margin-horizontal 20}
:placeholder (i18n/label :t/keypair-name-input-placeholder)
:label (i18n/label :t/keypair-name)
:char-limit keypair-name-max-length
:char-limit constants/keypair-name-max-length
:auto-focus true
:on-change-text on-change-text
:error error}]
Expand Down
5 changes: 5 additions & 0 deletions src/status_im/navigation/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
[status-im.contexts.profile.settings.screens.messages.view :as settings.messages]
[status-im.contexts.profile.settings.screens.password.view :as settings-password]
[status-im.contexts.profile.settings.view :as settings]
[status-im.contexts.settings.wallet.keypairs-and-accounts.rename.view :as keypair-rename]
[status-im.contexts.settings.wallet.keypairs-and-accounts.view :as keypairs-and-accounts]
[status-im.contexts.settings.wallet.saved-addresses.view :as saved-addresses-settings]
[status-im.contexts.settings.wallet.wallet-options.view :as wallet-options]
Expand Down Expand Up @@ -494,6 +495,10 @@
:options options/transparent-modal-screen-options
:component wallet-options/view}

{:name :screen/settings.rename-keypair
:options (assoc options/dark-screen :sheet? true)
:component keypair-rename/view}

{:name :screen/settings.saved-addresses
:options options/transparent-modal-screen-options
:component saved-addresses-settings/view}
Expand Down
3 changes: 3 additions & 0 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@
"remove-network": "Remove network",
"remove-token": "Remove token",
"removed": "removed",
"rename-key-pair": "Rename key pair",
"repeat-pin": "Repeat new 6-digit passcode",
"repeat-puk": "Repeat new 12-digit PUK",
"report-bug-email-template": "1. Issue Description\n{{description}}\n\n\n2. Steps to reproduce\n{{steps}}\n\n\n3. Attach screenshots that can demo the problem, please\n",
Expand Down Expand Up @@ -2575,6 +2576,8 @@
"other": "{{count}} addresses"
},
"max": "Max: {{number}}",
"your-key-pair-name-is-too-long": "Your key pair name is too long",
"your-key-pair-name-is-too-short": "Your key pair name is too short",
"key-name-error-length": "Key name too long",
"key-name-error-emoji": "Emojis are not allowed",
"key-name-error-special-char": "Special characters are not allowed",
Expand Down

0 comments on commit f064210

Please sign in to comment.