|
2 | 2 | (:require
|
3 | 3 | [quo.core :as quo]
|
4 | 4 | [react-native.core :as rn]
|
5 |
| - [reagent.core :as reagent] |
6 | 5 | [status-im.common.floating-button-page.view :as floating-button-page]
|
| 6 | + [status-im.common.validation.general :as validators] |
7 | 7 | [status-im.contexts.wallet.create-account.new-keypair.keypair-name.style :as style]
|
8 | 8 | [utils.i18n :as i18n]
|
9 | 9 | [utils.re-frame :as rf]))
|
10 | 10 |
|
11 | 11 | (def keypair-name-max-length 15)
|
| 12 | +(def keypair-name-min-length 5) |
| 13 | + |
| 14 | +(def error-messages |
| 15 | + {:length (i18n/label :t/key-name-error-length) |
| 16 | + :emoji (i18n/label :t/key-name-error-emoji) |
| 17 | + :special-char (i18n/label :t/key-name-error-special-char)}) |
| 18 | + |
| 19 | +(defn navigate-back [] (rf/dispatch [:navigate-back])) |
12 | 20 |
|
13 | 21 | (defn view
|
14 | 22 | []
|
15 |
| - (let [keypair-name (reagent/atom "")] |
16 |
| - (fn [] |
17 |
| - (let [customization-color (rf/sub [:profile/customization-color])] |
18 |
| - [rn/view {:style {:flex 1}} |
19 |
| - [floating-button-page/view |
20 |
| - {:header [quo/page-nav |
21 |
| - {:icon-name :i/arrow-left |
22 |
| - :on-press #(rf/dispatch [:navigate-back]) |
23 |
| - :accessibility-label :top-bar}] |
24 |
| - :footer [quo/bottom-actions |
25 |
| - {:actions :one-action |
26 |
| - :button-one-label (i18n/label :t/continue) |
27 |
| - :button-one-props {:disabled? (or (zero? (count @keypair-name)) |
28 |
| - (> (count @keypair-name) |
29 |
| - keypair-name-max-length)) |
30 |
| - :customization-color customization-color |
31 |
| - :on-press #(rf/dispatch [:wallet/new-keypair-continue |
32 |
| - {:keypair-name |
33 |
| - @keypair-name}])} |
34 |
| - :container-style style/bottom-action}]} |
35 |
| - [quo/text-combinations |
36 |
| - {:container-style style/header-container |
37 |
| - :title (i18n/label :t/keypair-name) |
38 |
| - :description (i18n/label :t/keypair-name-description)}] |
39 |
| - [quo/input |
40 |
| - {:container-style {:margin-horizontal 20} |
41 |
| - :placeholder (i18n/label :t/keypair-name-input-placeholder) |
42 |
| - :label (i18n/label :t/keypair-name) |
43 |
| - :char-limit keypair-name-max-length |
44 |
| - :auto-focus true |
45 |
| - :on-change-text #(reset! keypair-name %)}]]])))) |
| 23 | + (let [[keypair-name set-keypair-name] (rn/use-state "") |
| 24 | + customization-color (rf/sub [:profile/customization-color]) |
| 25 | + [error set-error] (rn/use-state false) |
| 26 | + on-change-text (rn/use-callback (fn [value] |
| 27 | + (set-keypair-name value) |
| 28 | + (cond |
| 29 | + (> (count value) keypair-name-max-length) |
| 30 | + (set-error :length) |
| 31 | + (validators/has-emojis? value) (set-error |
| 32 | + :emoji) |
| 33 | + (validators/has-special-characters? value) |
| 34 | + (set-error :special-char) |
| 35 | + :else (set-error nil)))) |
| 36 | + on-continue (rn/use-callback #(rf/dispatch [:wallet/new-keypair-continue |
| 37 | + {:keypair-name |
| 38 | + keypair-name}]) |
| 39 | + [keypair-name])] |
| 40 | + [rn/view {:style {:flex 1}} |
| 41 | + [floating-button-page/view |
| 42 | + {:header [quo/page-nav |
| 43 | + {:icon-name :i/arrow-left |
| 44 | + :on-press navigate-back |
| 45 | + :accessibility-label :top-bar}] |
| 46 | + :footer [quo/bottom-actions |
| 47 | + {:actions :one-action |
| 48 | + :button-one-label (i18n/label :t/continue) |
| 49 | + :button-one-props {:disabled? (or (pos? error) |
| 50 | + (<= (count keypair-name) |
| 51 | + keypair-name-min-length)) |
| 52 | + :customization-color customization-color |
| 53 | + :on-press on-continue} |
| 54 | + :container-style style/bottom-action}]} |
| 55 | + [quo/text-combinations |
| 56 | + {:container-style style/header-container |
| 57 | + :title (i18n/label :t/keypair-name) |
| 58 | + :description (i18n/label :t/keypair-name-description)}] |
| 59 | + [quo/input |
| 60 | + {:container-style {:margin-horizontal 20} |
| 61 | + :placeholder (i18n/label :t/keypair-name-input-placeholder) |
| 62 | + :label (i18n/label :t/keypair-name) |
| 63 | + :char-limit keypair-name-max-length |
| 64 | + :auto-focus true |
| 65 | + :on-change-text on-change-text |
| 66 | + :error error}] |
| 67 | + (when error |
| 68 | + [quo/info-message |
| 69 | + {:type :error |
| 70 | + :size :default |
| 71 | + :icon :i/info |
| 72 | + :container-style style/error-container} |
| 73 | + (get error-messages error)])]])) |
0 commit comments