Skip to content

Commit 3a1301c

Browse files
committed
review
1 parent 9764371 commit 3a1301c

File tree

7 files changed

+101
-86
lines changed

7 files changed

+101
-86
lines changed

src/quo/components/inputs/input/style.cljs

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@
134134
:align-items :flex-end})
135135

136136
(defn counter-color
137-
[current-chars char-limit variant-colors theme]
137+
[{:keys [current-chars char-limit variant-colors theme]}]
138138
{:color (if (> current-chars char-limit)
139-
(colors/theme-colors colors/danger-50 colors/danger-60 theme)
139+
(colors/resolve-color :danger theme)
140140
(:label variant-colors))})
141141

142142
(defn button

src/quo/components/inputs/input/view.cljs

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
(str current-chars "/"))]
2323
[rn/view {:style style/counter-container}
2424
[text/text
25-
{:style (style/counter-color current-chars char-limit variant-colors theme)
25+
{:style (style/counter-color {:current-chars current-chars
26+
:char-limit char-limit
27+
:variant-colors variant-colors
28+
:theme theme})
2629
:weight :regular
2730
:size :paragraph-2}
2831
count-text]])])
+27-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns status-im.common.validation.profile
22
(:require [clojure.string :as string]
3+
[status-im.common.validators :as validators]
34
[status-im.constants :as constants]
45
utils.emojilib
56
[utils.i18n :as i18n]))
@@ -12,12 +13,8 @@
1213

1314
(def common-names ["Ethereum" "Bitcoin"])
1415

15-
(defn has-emojis? [s] (boolean (re-find utils.emojilib/emoji-regex s)))
16-
1716
(defn has-common-names? [s] (pos? (count (filter #(string/includes? s %) common-names))))
1817

19-
(defn has-special-characters? [s] (not (re-find status-regex s)))
20-
2118
(defn name-too-short? [s] (< (count (string/trim (str s))) min-length))
2219

2320
(defn name-too-long? [s] (> (count (string/trim (str s))) constants/profile-name-max-length))
@@ -27,33 +24,37 @@
2724
(defn validation-name
2825
[s]
2926
(cond
30-
(string/blank? s) nil
31-
(string/ends-with? s "-eth") (i18n/label :t/ending-not-allowed {:ending "-eth"})
32-
(string/ends-with? s "_eth") (i18n/label :t/ending-not-allowed {:ending "_eth"})
33-
(string/ends-with? s ".eth") (i18n/label :t/ending-not-allowed {:ending ".eth"})
34-
(string/starts-with? s " ") (i18n/label :t/start-with-space)
35-
(string/ends-with? s " ") (i18n/label :t/ends-with-space)
36-
(has-common-names? s) (i18n/label :t/are-not-allowed {:check (i18n/label :t/common-names)})
37-
(has-emojis? s) (i18n/label :t/are-not-allowed {:check (i18n/label :t/emojis)})
38-
(has-special-characters? s) (i18n/label :t/are-not-allowed
39-
{:check (i18n/label :t/special-characters)})
40-
(name-too-short? s) (i18n/label :t/minimum-characters {:min-chars min-length})
41-
(name-too-long? s) (i18n/label :t/profile-name-is-too-long)))
27+
(string/blank? s) nil
28+
(string/ends-with? s "-eth") (i18n/label :t/ending-not-allowed {:ending "-eth"})
29+
(string/ends-with? s "_eth") (i18n/label :t/ending-not-allowed {:ending "_eth"})
30+
(string/ends-with? s ".eth") (i18n/label :t/ending-not-allowed {:ending ".eth"})
31+
(string/starts-with? s " ") (i18n/label :t/start-with-space)
32+
(string/ends-with? s " ") (i18n/label :t/ends-with-space)
33+
(has-common-names? s) (i18n/label :t/are-not-allowed
34+
{:check (i18n/label :t/common-names)})
35+
(validators/has-emojis? s) (i18n/label :t/are-not-allowed
36+
{:check (i18n/label :t/emojis)})
37+
(validators/has-special-characters? s) (i18n/label :t/are-not-allowed
38+
{:check (i18n/label :t/special-characters)})
39+
(name-too-short? s) (i18n/label :t/minimum-characters {:min-chars min-length})
40+
(name-too-long? s) (i18n/label :t/profile-name-is-too-long)))
4241

4342
(defn validation-bio
4443
[s]
4544
(cond
46-
(string/blank? s) nil
47-
(has-emojis? s) (i18n/label :t/are-not-allowed {:check (i18n/label :t/emojis)})
48-
(has-special-characters? s) (i18n/label :t/are-not-allowed
49-
{:check (i18n/label :t/special-characters)})
50-
(bio-too-long? s) (i18n/label :t/bio-is-too-long)))
45+
(string/blank? s) nil
46+
(validators/has-emojis? s) (i18n/label :t/are-not-allowed
47+
{:check (i18n/label :t/emojis)})
48+
(validators/has-special-characters? s) (i18n/label :t/are-not-allowed
49+
{:check (i18n/label :t/special-characters)})
50+
(bio-too-long? s) (i18n/label :t/bio-is-too-long)))
5151

5252
(defn validation-nickname
5353
[s]
5454
(cond
55-
(string/blank? s) nil
56-
(has-emojis? s) (i18n/label :t/are-not-allowed {:check (i18n/label :t/emojis)})
57-
(has-special-characters? s) (i18n/label :t/are-not-allowed
58-
{:check (i18n/label :t/special-characters)})
59-
(name-too-long? s) (i18n/label :t/nickname-is-too-long)))
55+
(string/blank? s) nil
56+
(validators/has-emojis? s) (i18n/label :t/are-not-allowed
57+
{:check (i18n/label :t/emojis)})
58+
(validators/has-special-characters? s) (i18n/label :t/are-not-allowed
59+
{:check (i18n/label :t/special-characters)})
60+
(name-too-long? s) (i18n/label :t/nickname-is-too-long)))

src/status_im/common/validators.cljs

+7
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@
1313
(and (string? s)
1414
(not-empty s)
1515
(boolean (re-matches constants/regx-compressed-key s))))
16+
17+
(defn has-emojis? [s] (boolean (re-find utils.emojilib/emoji-regex s)))
18+
19+
(defn has-special-characters?
20+
[s]
21+
(and (not (= s ""))
22+
(not (re-find #"^[a-zA-Z0-9\-_ ]+$" s))))

src/status_im/contexts/wallet/create_account/new_keypair/keypair_name/style.cljs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
(ns status-im.contexts.wallet.create-account.new-keypair.keypair-name.style)
1+
(ns status-im.contexts.wallet.create-account.new-keypair.keypair-name.style
2+
(:require [quo.foundations.colors :as colors]))
23

34
(def header-container
45
{:margin-horizontal 20
@@ -15,3 +16,8 @@
1516
:align-self :flex-start
1617
:margin-left 20
1718
:margin-vertical 8})
19+
20+
(defn error
21+
[theme]
22+
{:margin-left 4
23+
:color (colors/resolve-color :danger theme)})

src/status_im/contexts/wallet/create_account/new_keypair/keypair_name/view.cljs

+51-53
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,65 @@
33
[quo.core :as quo]
44
[quo.foundations.colors :as colors]
55
[react-native.core :as rn]
6-
[reagent.core :as reagent]
76
[status-im.common.floating-button-page.view :as floating-button-page]
7+
[status-im.common.validators :as validators]
88
[status-im.contexts.wallet.create-account.new-keypair.keypair-name.style :as style]
99
[utils.i18n :as i18n]
1010
[utils.re-frame :as rf]))
1111

1212
(def keypair-name-max-length 15)
13-
(defn has-emojis? [s] (boolean (re-find utils.emojilib/emoji-regex s)))
14-
(defn has-special-characters?
15-
[s]
16-
(if (empty? s)
17-
false
18-
(not (re-find #"^[a-zA-Z0-9\-_ ]+$" s))))
13+
(def keypair-name-min-length 5)
1914

15+
(def error-messages
16+
{:length (i18n/label :t/key-name-error-length)
17+
:emoji (i18n/label :t/key-name-error-emoji)
18+
:special-char (i18n/label :t/key-name-error-special-char)})
2019

2120
(defn view-internal
2221
[{:keys [theme]}]
23-
(let [keypair-name (reagent/atom "")]
24-
(fn []
25-
(let [customization-color (rf/sub [:profile/customization-color])
26-
[error? set-error?] (rn/use-state false)]
27-
[rn/view {:style {:flex 1}}
28-
[floating-button-page/view
29-
{:header [quo/page-nav
30-
{:icon-name :i/arrow-left
31-
:on-press #(rf/dispatch [:navigate-back])
32-
:accessibility-label :top-bar}]
33-
:footer [quo/bottom-actions
34-
{:actions :one-action
35-
:button-one-label (i18n/label :t/continue)
36-
:button-one-props {:disabled? (or (pos? error?)
37-
(< (count @keypair-name) 4))
38-
:customization-color customization-color
39-
:on-press #(rf/dispatch [:wallet/new-keypair-continue
40-
{:keypair-name
41-
@keypair-name}])}
42-
:container-style style/bottom-action}]}
43-
[quo/text-combinations
44-
{:container-style style/header-container
45-
:title (i18n/label :t/keypair-name)
46-
:description (i18n/label :t/keypair-name-description)}]
47-
[quo/input
48-
{:container-style {:margin-horizontal 20}
49-
:placeholder (i18n/label :t/keypair-name-input-placeholder)
50-
:label (i18n/label :t/keypair-name)
51-
:char-limit keypair-name-max-length
52-
:auto-focus true
53-
:on-change-text (fn [value]
54-
(reset! keypair-name value)
55-
(cond
56-
(> (count value) keypair-name-max-length) (set-error? 1)
57-
(has-emojis? value) (set-error? 2)
58-
(has-special-characters? value) (set-error? 3)
59-
:else (set-error? nil)))
60-
:error? error?}]
61-
(when error?
62-
[rn/view
63-
{:style style/error-container}
64-
[quo/icon :i/info {:color (colors/theme-colors colors/danger-50 colors/danger-60 theme)}]
65-
[quo/text
66-
{:style {:margin-left 4
67-
:color (colors/theme-colors colors/danger-50 colors/danger-60 theme)}}
68-
(i18n/label (keyword (str "t/key-name-error-" error?)))]])]]))))
22+
(let [[keypair-name set-keypair-name] (rn/use-state "")
23+
customization-color (rf/sub [:profile/customization-color])
24+
[error set-error] (rn/use-state false)]
25+
[rn/view {:style {:flex 1}}
26+
[floating-button-page/view
27+
{:header [quo/page-nav
28+
{:icon-name :i/arrow-left
29+
:on-press #(rf/dispatch [:navigate-back])
30+
:accessibility-label :top-bar}]
31+
:footer [quo/bottom-actions
32+
{:actions :one-action
33+
:button-one-label (i18n/label :t/continue)
34+
:button-one-props {:disabled? (or (pos? error)
35+
(<= (count keypair-name)
36+
keypair-name-min-length))
37+
:customization-color customization-color
38+
:on-press #(rf/dispatch [:wallet/new-keypair-continue
39+
{:keypair-name
40+
keypair-name}])}
41+
:container-style style/bottom-action}]}
42+
[quo/text-combinations
43+
{:container-style style/header-container
44+
:title (i18n/label :t/keypair-name)
45+
:description (i18n/label :t/keypair-name-description)}]
46+
[quo/input
47+
{:container-style {:margin-horizontal 20}
48+
:placeholder (i18n/label :t/keypair-name-input-placeholder)
49+
:label (i18n/label :t/keypair-name)
50+
:char-limit keypair-name-max-length
51+
:auto-focus true
52+
:on-change-text (fn [value]
53+
(set-keypair-name value)
54+
(cond
55+
(> (count value) keypair-name-max-length) (set-error :length)
56+
(validators/has-emojis? value) (set-error :emoji)
57+
(validators/has-special-characters? value) (set-error :special-char)
58+
:else (set-error nil)))
59+
:error error}]
60+
(when error
61+
[rn/view
62+
{:style style/error-container}
63+
[quo/icon :i/info {:color (colors/resolve-color :danger theme)}]
64+
[quo/text
65+
{:style (style/error theme)}
66+
(get error-messages error)]])]]))
6967
(def view (quo.theme/with-theme view-internal))

translations/en.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -2562,7 +2562,7 @@
25622562
"one": "1 address",
25632563
"other": "{{count}} addresses"
25642564
},
2565-
"key-name-error-1": "Key name too long",
2566-
"key-name-error-2": "Emojis are not allowed",
2567-
"key-name-error-3": "Special characters are not allowed",
2565+
"key-name-error-length": "Key name too long",
2566+
"key-name-error-emoji": "Emojis are not allowed",
2567+
"key-name-error-special-char": "Special characters are not allowed",
25682568
}

0 commit comments

Comments
 (0)