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 fc46269866..adf2b3fa91 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 @@ -7,7 +7,8 @@ [status-im.ui.screens.add-new.new-chat.db :as db] [status-im.utils.handlers :as handlers] [status-im.ethereum.stateofus :as stateofus] - [status-im.utils.random :as random])) + [status-im.utils.random :as random] + [status-im.utils.utils :as utils])) (defn- ens-name-parse [contact-identity] (when (string? contact-identity) @@ -28,25 +29,26 @@ (handlers/register-handler-fx :new-chat/set-new-identity - (fn [{db :db} [_ new-identity new-ens-name id]] + (fn [{db :db} [_ new-identity-raw new-ens-name id]] (when (or (not id) (= id @resolve-last-id)) - (let [is-public-key? (and (string? new-identity) + (let [new-identity (utils/safe-trim new-identity-raw) + is-public-key? (and (string? new-identity) (string/starts-with? new-identity "0x")) - is-ens? (and (not is-public-key?) - (ens/valid-eth-name-prefix? new-identity)) - error (db/validate-pub-key db new-identity)] + is-ens? (and (not is-public-key?) + (ens/valid-eth-name-prefix? new-identity)) + error (db/validate-pub-key db new-identity)] (merge {:db (assoc db :contacts/new-identity {:public-key new-identity - :state (cond is-ens? - :searching - (and (string/blank? new-identity) (not new-ens-name)) - :empty - error - :error - :else - :valid) - :error error + :state (cond is-ens? + :searching + (and (string/blank? new-identity) (not new-ens-name)) + :empty + error + :error + :else + :valid) + :error error :ens-name (ens-name-parse new-ens-name)})} (when is-ens? (reset! resolve-last-id (random/id)) @@ -57,4 +59,4 @@ :cb #(re-frame/dispatch [:new-chat/set-new-identity % new-identity - @resolve-last-id])}}))))))) \ No newline at end of file + @resolve-last-id])}}))))))) diff --git a/src/status_im/utils/utils.cljs b/src/status_im/utils/utils.cljs index 8d9ac4bc2e..2953bff0ac 100644 --- a/src/status_im/utils/utils.cljs +++ b/src/status_im/utils/utils.cljs @@ -135,3 +135,7 @@ (if (> (count decimal-part) places) (gstring/format (str "%." places "f") amount) (or (str amount) 0)))) + +(defn safe-trim [s] + (when (string? s) + (string/trim s)))