-
Notifications
You must be signed in to change notification settings - Fork 987
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into milad/17321-about-tab-collectible-page
- Loading branch information
Showing
21 changed files
with
448 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(ns status-im.common.validation.profile | ||
(:require [clojure.string :as string] | ||
[utils.i18n :as i18n])) | ||
|
||
;; NOTE - validation should match with Desktop | ||
;; https://github.com/status-im/status-desktop/blob/2ba96803168461088346bf5030df750cb226df4c/ui/imports/utils/Constants.qml#L468 | ||
(def min-length 5) | ||
(def max-length 24) | ||
|
||
(def emoji-regex | ||
#"(\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])") | ||
|
||
(def status-regex #"^[a-zA-Z0-9\-_ ]+$") | ||
|
||
(def common-names ["Ethereum" "Bitcoin"]) | ||
|
||
(defn has-emojis? [s] (boolean (re-find emoji-regex s))) | ||
|
||
(defn has-common-names? [s] (pos? (count (filter #(string/includes? s %) common-names)))) | ||
|
||
(defn has-special-characters? [s] (not (re-find status-regex s))) | ||
|
||
(defn name-too-short? [s] (< (count (string/trim (str s))) min-length)) | ||
|
||
(defn name-too-long? [s] (> (count (string/trim (str s))) max-length)) | ||
|
||
(defn validation-name | ||
[s] | ||
(cond | ||
(or (= s nil) (= s "")) nil | ||
(string/ends-with? s "-eth") (i18n/label :t/ending-not-allowed {:ending "-eth"}) | ||
(string/ends-with? s "_eth") (i18n/label :t/ending-not-allowed {:ending "_eth"}) | ||
(string/ends-with? s ".eth") (i18n/label :t/ending-not-allowed {:ending ".eth"}) | ||
(string/starts-with? s " ") (i18n/label :t/start-with-space) | ||
(string/ends-with? s " ") (i18n/label :t/ends-with-space) | ||
(has-common-names? s) (i18n/label :t/are-not-allowed {:check (i18n/label :t/common-names)}) | ||
(has-emojis? s) (i18n/label :t/are-not-allowed {:check (i18n/label :t/emojis)}) | ||
(has-special-characters? s) (i18n/label :t/are-not-allowed | ||
{:check (i18n/label :t/special-characters)}) | ||
(name-too-short? s) (i18n/label :t/minimum-characters {:min-chars min-length}) | ||
(name-too-long? s) (i18n/label :t/profile-name-is-too-long))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
(ns status-im.common.validation.profile-test | ||
(:require | ||
[cljs.test :refer-macros [deftest are]] | ||
[status-im.common.validation.profile :as profile-validator] | ||
[utils.i18n :as i18n])) | ||
|
||
(deftest has-emojis-test | ||
(are [arg expected] | ||
(expected (profile-validator/has-emojis? arg)) | ||
"Hello 😊" true? | ||
"Hello" false?)) | ||
|
||
(deftest has-common-names-test | ||
(are [arg expected] | ||
(expected (profile-validator/has-common-names? arg)) | ||
"Ethereum" true? | ||
"Hello" false?)) | ||
|
||
(deftest has-special-characters-test | ||
(are [arg expected] | ||
(expected (profile-validator/has-special-characters? arg)) | ||
"@name" true? | ||
"name" false?)) | ||
|
||
(deftest name-too-short-test | ||
(are [arg expected] | ||
(expected (profile-validator/name-too-short? arg)) | ||
"abc" true? | ||
"abcdef" false?)) | ||
|
||
(deftest name-too-long-test | ||
(are [arg expected] | ||
(expected (profile-validator/name-too-long? arg)) | ||
(apply str (repeat 25 "a")) true? | ||
"abcdef" false?)) | ||
|
||
(deftest validation-name-test | ||
(are [arg expected] | ||
(= (profile-validator/validation-name arg) expected) | ||
nil nil | ||
"" nil | ||
"@name" (i18n/label :t/are-not-allowed | ||
{:check (i18n/label :t/special-characters)}) | ||
"name-eth" (i18n/label :t/ending-not-allowed {:ending "-eth"}) | ||
"name_eth" (i18n/label :t/ending-not-allowed {:ending "_eth"}) | ||
"name.eth" (i18n/label :t/ending-not-allowed {:ending ".eth"}) | ||
" name" (i18n/label :t/start-with-space) | ||
"name " (i18n/label :t/ends-with-space) | ||
"Ethereum" (i18n/label :t/are-not-allowed {:check (i18n/label :t/common-names)}) | ||
"Hello 😊" (i18n/label :t/are-not-allowed {:check (i18n/label :t/emojis)}) | ||
"abc" (i18n/label :t/minimum-characters {:min-chars 5}) | ||
(apply str (repeat 25 "a")) (i18n/label :t/profile-name-is-too-long))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(ns status-im.contexts.profile.edit.header.view | ||
(:require [quo.core :as quo] | ||
[react-native.core :as rn] | ||
[status-im.common.not-implemented :as not-implemented] | ||
[status-im.contexts.profile.edit.style :as style] | ||
[status-im.contexts.profile.utils :as profile.utils] | ||
[utils.i18n :as i18n] | ||
[utils.re-frame :as rf])) | ||
|
||
(defn view | ||
[] | ||
(let [profile (rf/sub [:profile/profile-with-image]) | ||
full-name (profile.utils/displayed-name profile) | ||
profile-picture (profile.utils/photo profile)] | ||
[rn/view | ||
{:key :edit-profile | ||
:style style/screen-container} | ||
[quo/text-combinations {:title (i18n/label :t/edit-profile)}] | ||
[rn/view style/avatar-wrapper | ||
[quo/user-avatar | ||
{:full-name full-name | ||
:profile-picture profile-picture | ||
:status-indicator? false | ||
:ring? true | ||
:size :big}] | ||
[quo/button | ||
{:on-press not-implemented/alert | ||
:container-style style/camera-button | ||
:icon-only? true | ||
:type :grey | ||
:background :photo | ||
:size 32} | ||
:i/camera]]])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
(ns status-im.contexts.profile.edit.list-items | ||
(:require [quo.foundations.colors :as colors] | ||
[status-im.common.not-implemented :as not-implemented] | ||
[status-im.contexts.profile.edit.style :as style] | ||
[status-im.contexts.profile.utils :as profile.utils] | ||
[utils.i18n :as i18n] | ||
[utils.re-frame :as rf])) | ||
|
||
(defn items | ||
[theme] | ||
(let [profile (rf/sub [:profile/profile-with-image]) | ||
customization-color (rf/sub [:profile/customization-color]) | ||
full-name (profile.utils/displayed-name profile)] | ||
[{:label (i18n/label :t/profile) | ||
:items [{:title (i18n/label :t/name) | ||
:on-press #(rf/dispatch [:open-modal :edit-name]) | ||
:blur? true | ||
:label :text | ||
:label-props full-name | ||
:action :arrow | ||
:container-style style/item-container} | ||
{:title (i18n/label :t/bio) | ||
:on-press not-implemented/alert | ||
:blur? true | ||
:action :arrow | ||
:container-style style/item-container} | ||
{:title (i18n/label :t/accent-colour) | ||
:on-press not-implemented/alert | ||
:label :color | ||
:label-props (colors/resolve-color customization-color theme) | ||
:blur? true | ||
:action :arrow | ||
:container-style style/item-container}]} | ||
|
||
{:label (i18n/label :t/showcase) | ||
:items [{:title (i18n/label :t/communities) | ||
:on-press not-implemented/alert | ||
:blur? true | ||
:action :arrow | ||
:container-style style/item-container} | ||
{:title (i18n/label :t/accounts) | ||
:on-press not-implemented/alert | ||
:blur? true | ||
:action :arrow | ||
:container-style style/item-container} | ||
{:title (i18n/label :t/collectibles) | ||
:on-press not-implemented/alert | ||
:blur? true | ||
:action :arrow | ||
:container-style style/item-container} | ||
{:title (i18n/label :t/assets) | ||
:on-press not-implemented/alert | ||
:blur? true | ||
:action :arrow | ||
:container-style style/item-container}]} | ||
|
||
{:label (i18n/label :t/on-the-web) | ||
:items [{:title (i18n/label :t/links) | ||
:on-press not-implemented/alert | ||
:blur? true | ||
:action :arrow | ||
:container-style style/item-container}]}])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
(ns status-im.contexts.profile.edit.name.events | ||
(:require [utils.i18n :as i18n] | ||
[utils.re-frame :as rf])) | ||
|
||
(defn edit-profile-name | ||
[{:keys [db]} [name]] | ||
{:db (assoc-in db [:profile/profile :display-name] name) | ||
:fx [[:json-rpc/call | ||
[{:method "wakuext_setDisplayName" | ||
:params [name] | ||
:on-success (fn [] | ||
(rf/dispatch [:navigate-back]) | ||
(rf/dispatch [:toasts/upsert | ||
{:type :positive | ||
:theme :dark | ||
:text (i18n/label :t/name-updated)}]))}]]]}) | ||
|
||
(rf/reg-event-fx :profile/edit-name edit-profile-name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(ns status-im.contexts.profile.edit.name.events-test | ||
(:require [cljs.test :refer [deftest is]] | ||
matcher-combinators.test | ||
[status-im.contexts.profile.edit.name.events :as sut])) | ||
|
||
(deftest edit-name-test | ||
(let [new-name "John Doe" | ||
cofx {:db {:profile/profile {:display-name "Old name"}}} | ||
expected {:db {:profile/profile {:display-name new-name}} | ||
:fx [[:json-rpc/call | ||
[{:method "wakuext_setDisplayName" | ||
:params [name] | ||
:on-success fn?}]]]}] | ||
(is (match? expected | ||
(sut/edit-profile-name cofx [new-name]))))) |
Oops, something went wrong.