[fix] fix ens name resolution

the app was previously letting the user create a chat with a contact
if a name typed in the input returned a valid public key at some point
because the field wasn't cleaned up with latter typing

Signed-off-by: Eric Dvorsak <eric@status.im>
This commit is contained in:
Eric Dvorsak 2018-10-26 20:50:14 +02:00
parent c348342590
commit b293fb11e3
No known key found for this signature in database
GPG Key ID: 32D08503358DB921
1 changed files with 14 additions and 14 deletions

View File

@ -15,17 +15,17 @@
(handlers/register-handler-fx
:new-chat/set-new-identity
(fn [{{:keys [web3 network network-status] :as db} :db} [_ new-identity]]
(let [new-identity-error (db/validate-pub-key db new-identity)]
(if (and (string? new-identity)
(string/starts-with? new-identity "0x"))
{:db (assoc db
:contacts/new-identity new-identity
:contacts/new-identity-error new-identity-error)}
(let [network (get-in db [:account/account :networks network])
chain (ethereum/network->chain-keyword network)]
{:resolve-whisper-identity {:web3 web3
:registry (get ens/ens-registries chain)
:ens-name (if (ens/is-valid-eth-name? new-identity)
new-identity
(str new-identity ".stateofus.eth"))
:cb #(re-frame/dispatch [:new-chat/set-new-identity %])}})))))
(let [is-public-key? (and (string? new-identity)
(string/starts-with? new-identity "0x"))]
(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?
(let [network (get-in db [:account/account :networks network])
chain (ethereum/network->chain-keyword network)]
{:resolve-whisper-identity {:web3 web3
:registry (get ens/ens-registries chain)
:ens-name (if (ens/is-valid-eth-name? new-identity)
new-identity
(str new-identity ".stateofus.eth"))
:cb #(re-frame/dispatch [:new-chat/set-new-identity %])}}))))))