|
3 | 3 | [quo.core :as quo]
|
4 | 4 | [quo.foundations.colors :as colors]
|
5 | 5 | [react-native.core :as rn]
|
6 |
| - [reagent.core :as reagent] |
7 | 6 | [status-im.common.floating-button-page.view :as floating-button-page]
|
| 7 | + [status-im.common.validators :as validators] |
8 | 8 | [status-im.contexts.wallet.create-account.new-keypair.keypair-name.style :as style]
|
9 | 9 | [utils.i18n :as i18n]
|
10 | 10 | [utils.re-frame :as rf]))
|
11 | 11 |
|
12 | 12 | (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) |
19 | 14 |
|
| 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)}) |
20 | 19 |
|
21 | 20 | (defn view-internal
|
22 | 21 | [{: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)]])]])) |
69 | 67 | (def view (quo.theme/with-theme view-internal))
|
0 commit comments