From a5a00e0a2c4bc7e5c70272cc7b29c0373c0a553a Mon Sep 17 00:00:00 2001 From: yenda Date: Wed, 8 Apr 2020 21:39:01 +0200 Subject: [PATCH] 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 --- src/status_im/ethereum/stateofus.cljs | 15 ++++++++++++++- src/status_im/ui/screens/ens/views.cljs | 6 +++--- test/cljs/status_im/test/ethereum/stateofus.cljs | 6 ++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/status_im/ethereum/stateofus.cljs b/src/status_im/ethereum/stateofus.cljs index 41a4e34bbf..f5fd0576ae 100644 --- a/src/status_im/ethereum/stateofus.cljs +++ b/src/status_im/ethereum/stateofus.cljs @@ -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 ".")))) diff --git a/src/status_im/ui/screens/ens/views.cljs b/src/status_im/ui/screens/ens/views.cljs index 97ddd6d062..030ec96ed8 100644 --- a/src/status_im/ui/screens/ens/views.cljs +++ b/src/status_im/ui/screens/ens/views.cljs @@ -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 diff --git a/test/cljs/status_im/test/ethereum/stateofus.cljs b/test/cljs/status_im/test/ethereum/stateofus.cljs index c7fae598f3..cb51b62309 100644 --- a/test/cljs/status_im/test/ethereum/stateofus.cljs +++ b/test/cljs/status_im/test/ethereum/stateofus.cljs @@ -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"))))