fix #10058 wrong domain name shown when connecting .eth

add a check on the function that adds the stateofus domain to
usernames. if the username already contains a domain, don't
concat stateofus domain to it

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2020-04-08 21:39:01 +02:00
parent e11385e350
commit a5a00e0a2c
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
3 changed files with 23 additions and 4 deletions

View File

@ -4,9 +4,22 @@
(def domain "stateofus.eth")
(defn subdomain [username]
(defn subdomain
[username]
(str username "." domain))
(defn username-with-domain
"checks if the username is a status username or a ens name
for that we check if there is a dot in the username, which
would indicate that there is already a domain name so we don't
concatenated stateofus domain to it"
[username]
(when (and (string? username)
(seq username))
(if (string/includes? username ".")
username
(subdomain username))))
(defn username [name]
(when (and name (string/ends-with? name domain))
(first (string/split name "."))))

View File

@ -361,10 +361,10 @@
(case state
:available
(i18n/label :t/ens-username-registration-confirmation
{:username (stateofus/subdomain username)})
{:username (stateofus/username-with-domain username)})
:connected-with-different-key
(i18n/label :t/ens-username-connection-confirmation
{:username (stateofus/subdomain username)})
{:username (stateofus/username-with-domain username)})
:connected
(i18n/label :t/ens-saved-title)
;;NOTE: this state can't be reached atm
@ -384,7 +384,7 @@
:connected
[react/nested-text
{:style {:font-size 15 :text-align :center}}
(stateofus/subdomain username)
(stateofus/username-with-domain username)
[{:style {:color colors/gray}}
(i18n/label :t/ens-saved)]]
;;NOTE: this state can't be reached atm

View File

@ -7,3 +7,9 @@
(is (true? (stateofus/valid-username? "andrey")))
(is (false? (stateofus/valid-username? "Andrey")))
(is (true? (stateofus/valid-username? "andrey12"))))
(deftest username-with-domain
(is (nil? (stateofus/username-with-domain nil)))
(is (= "andrey.stateofus.eth" (stateofus/username-with-domain "andrey")))
(is (= "andrey.eth" (stateofus/username-with-domain "andrey.eth")))
(is (= "andrey.stateofus.eth" (stateofus/username-with-domain "andrey.stateofus.eth"))))