[#10115] Trim address/name on adding 1-1 chat
This commit is contained in:
parent
d64ba1b540
commit
c9486dc634
|
@ -7,7 +7,8 @@
|
||||||
[status-im.ui.screens.add-new.new-chat.db :as db]
|
[status-im.ui.screens.add-new.new-chat.db :as db]
|
||||||
[status-im.utils.handlers :as handlers]
|
[status-im.utils.handlers :as handlers]
|
||||||
[status-im.ethereum.stateofus :as stateofus]
|
[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]
|
(defn- ens-name-parse [contact-identity]
|
||||||
(when (string? contact-identity)
|
(when (string? contact-identity)
|
||||||
|
@ -28,25 +29,26 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:new-chat/set-new-identity
|
: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))
|
(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"))
|
(string/starts-with? new-identity "0x"))
|
||||||
is-ens? (and (not is-public-key?)
|
is-ens? (and (not is-public-key?)
|
||||||
(ens/valid-eth-name-prefix? new-identity))
|
(ens/valid-eth-name-prefix? new-identity))
|
||||||
error (db/validate-pub-key db new-identity)]
|
error (db/validate-pub-key db new-identity)]
|
||||||
(merge {:db (assoc db
|
(merge {:db (assoc db
|
||||||
:contacts/new-identity
|
:contacts/new-identity
|
||||||
{:public-key new-identity
|
{:public-key new-identity
|
||||||
:state (cond is-ens?
|
:state (cond is-ens?
|
||||||
:searching
|
:searching
|
||||||
(and (string/blank? new-identity) (not new-ens-name))
|
(and (string/blank? new-identity) (not new-ens-name))
|
||||||
:empty
|
:empty
|
||||||
error
|
error
|
||||||
:error
|
:error
|
||||||
:else
|
:else
|
||||||
:valid)
|
:valid)
|
||||||
:error error
|
:error error
|
||||||
:ens-name (ens-name-parse new-ens-name)})}
|
:ens-name (ens-name-parse new-ens-name)})}
|
||||||
(when is-ens?
|
(when is-ens?
|
||||||
(reset! resolve-last-id (random/id))
|
(reset! resolve-last-id (random/id))
|
||||||
|
@ -57,4 +59,4 @@
|
||||||
:cb #(re-frame/dispatch [:new-chat/set-new-identity
|
:cb #(re-frame/dispatch [:new-chat/set-new-identity
|
||||||
%
|
%
|
||||||
new-identity
|
new-identity
|
||||||
@resolve-last-id])}})))))))
|
@resolve-last-id])}})))))))
|
||||||
|
|
|
@ -135,3 +135,7 @@
|
||||||
(if (> (count decimal-part) places)
|
(if (> (count decimal-part) places)
|
||||||
(gstring/format (str "%." places "f") amount)
|
(gstring/format (str "%." places "f") amount)
|
||||||
(or (str amount) 0))))
|
(or (str amount) 0))))
|
||||||
|
|
||||||
|
(defn safe-trim [s]
|
||||||
|
(when (string? s)
|
||||||
|
(string/trim s)))
|
||||||
|
|
Loading…
Reference in New Issue