[#10115] Trim address/name on adding 1-1 chat

This commit is contained in:
Roman Volosovskyi 2020-03-02 16:16:54 +02:00
parent d64ba1b540
commit c9486dc634
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
2 changed files with 22 additions and 16 deletions

View File

@ -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,9 +29,10 @@
(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))

View File

@ -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)))