From dfeec0f39f81a2585b33bb4da7db47d72f2140b9 Mon Sep 17 00:00:00 2001 From: Vitaliy Vlasov Date: Thu, 29 Aug 2019 14:30:03 +0300 Subject: [PATCH] Fix empty contact code string errors Signed-off-by: Vitaliy Vlasov --- src/status_im/ethereum/ens.cljs | 7 +++++++ src/status_im/ui/screens/add_new/new_chat/events.cljs | 3 ++- src/status_im/ui/screens/add_new/new_chat/views.cljs | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/status_im/ethereum/ens.cljs b/src/status_im/ethereum/ens.cljs index b300e51f1f..a3c46c8fea 100644 --- a/src/status_im/ethereum/ens.cljs +++ b/src/status_im/ethereum/ens.cljs @@ -127,6 +127,13 @@ [x y] (str "0x04" x y)) +(defn valid-eth-name-prefix? + [prefix] + (not + (or (string/blank? prefix) + (string/ends-with? prefix ".") + (string/includes? prefix "..")))) + (defn is-valid-eth-name? [ens-name] (and ens-name diff --git a/src/status_im/ui/screens/add_new/new_chat/events.cljs b/src/status_im/ui/screens/add_new/new_chat/events.cljs index 834745109e..2b7e4af611 100644 --- a/src/status_im/ui/screens/add_new/new_chat/events.cljs +++ b/src/status_im/ui/screens/add_new/new_chat/events.cljs @@ -20,7 +20,8 @@ (merge {:db (assoc db :contacts/new-identity new-identity :contacts/new-identity-error (db/validate-pub-key db new-identity))} - (when-not is-public-key? + (when (and (not is-public-key?) + (ens/valid-eth-name-prefix? new-identity)) (let [chain (ethereum/chain-keyword db)] {:resolve-public-key {:registry (get ens/ens-registries chain) :ens-name (if (ens/is-valid-eth-name? new-identity) diff --git a/src/status_im/ui/screens/add_new/new_chat/views.cljs b/src/status_im/ui/screens/add_new/new_chat/views.cljs index f2d3d70996..178c8d475d 100644 --- a/src/status_im/ui/screens/add_new/new_chat/views.cljs +++ b/src/status_im/ui/screens/add_new/new_chat/views.cljs @@ -24,6 +24,7 @@ (views/defview new-chat [] (views/letsubs [contacts [:contacts/active] + new-identity [:contacts/new-identity] error-message [:new-identity-error]] [react/keyboard-avoiding-view {:style {:flex 1}} [status-bar/status-bar] @@ -32,7 +33,7 @@ [react/view add-new.styles/new-chat-input-container [react/text-input {:ref (fn [v] (js/setTimeout #(reset! tw (if v "100%" "95%")) 100)) :on-change-text #(re-frame/dispatch [:new-chat/set-new-identity %]) - :on-submit-editing #(when-not error-message + :on-submit-editing #(when (and new-identity (not error-message)) (re-frame/dispatch [:contact.ui/contact-code-submitted])) :placeholder (i18n/label :t/enter-contact-code) :style (add-new.styles/input @tw)