Skip to content

Commit

Permalink
fix #10058 wrong domain name shown when connecting .eth
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
yenda committed Apr 15, 2020
1 parent e11385e commit a5a00e0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
15 changes: 14 additions & 1 deletion src/status_im/ethereum/stateofus.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "."))))
Expand Down
6 changes: 3 additions & 3 deletions src/status_im/ui/screens/ens/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/cljs/status_im/test/ethereum/stateofus.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))))

0 comments on commit a5a00e0

Please sign in to comment.