user can add contact by ens username

This commit is contained in:
Eric Dvorsak 2018-08-07 03:02:38 +02:00
parent c25b6ec630
commit 96ac6eb83f
No known key found for this signature in database
GPG Key ID: 932AC1CE5F05DE0C
10 changed files with 46 additions and 19 deletions

View File

@ -295,7 +295,7 @@
:copy-qr "Copy code"
:qr-code-public-key-hint "Share this code to \nstart chatting"
:enter-address "Enter address"
:enter-contact-code "Enter contact code"
:enter-contact-code "Enter contact code or username"
:more "more"
;;group-settings
@ -362,7 +362,7 @@
:specify-name "Specify a name"
:address-explication "Your public key is used to generate your address on Ethereum and is a series of numbers and letters. You can find it easily in your profile"
:unable-to-read-this-code "Unable to read this code"
:use-valid-contact-code "Please scan a valid contact code"
:use-valid-contact-code "Please enter or scan a valid contact code or username"
:enter-valid-public-key "Please enter a valid public key or scan a QR code"
:contact-already-added "The contact has already been added"
:can-not-add-yourself "You can't add yourself"

View File

@ -4,7 +4,7 @@
[cljs.spec.alpha :as spec]
[clojure.string :as string]))
(defn- validate-pub-key [whisper-identity {:keys [address public-key]}]
(defn validate-pub-key [whisper-identity {:keys [address public-key]}]
(cond
(string/blank? whisper-identity)
(i18n/label :t/use-valid-contact-code)

View File

@ -0,0 +1,30 @@
(ns status-im.ui.screens.add-new.new-chat.events
(:require [re-frame.core :as re-frame]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.ui.screens.add-new.new-chat.db :as db]
[status-im.utils.ethereum.stateofus :as stateofus]
[status-im.utils.ethereum.ens :as ens]
[status-im.utils.ethereum.core :as ethereum]))
(re-frame/reg-fx
:resolve-whisper-identity
(fn [{:keys [web3 registry ens-name cb]}]
(println registry ens-name)
(stateofus/text web3 registry ens-name cb)))
(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 new-identity (:account/account db))]
(if (stateofus/is-stateofus-name? new-identity)
(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 new-identity
:cb #(re-frame/dispatch [:new-chat/set-new-identity %])}})
{:db (assoc db
:contacts/new-identity new-identity
:contacts/new-identity-error new-identity-error)}))))

View File

@ -1,10 +1,6 @@
(ns status-im.ui.screens.add-new.new-chat.subs
(:require [re-frame.core :as re-frame]
[status-im.ui.screens.add-new.new-chat.db :as db]))
(:require [re-frame.core :as re-frame]))
(re-frame/reg-sub
:new-contact-error-message
:<- [:get :contacts/new-identity]
:<- [:get-current-account]
(fn [[new-identity account]]
(db/validate-pub-key new-identity account)))
(re-frame/reg-sub :new-identity-error
(fn [db _]
(get db :contacts/new-identity-error nil)))

View File

@ -20,13 +20,13 @@
(views/defview new-chat []
(views/letsubs [contacts [:all-added-people-contacts]
error-message [:new-contact-error-message]]
error-message [:new-identity-error]]
[react/keyboard-avoiding-view open-dapp.styles/main-container
[status-bar/status-bar]
[toolbar.view/simple-toolbar (i18n/label :t/new-chat)]
[react/view add-new.styles/new-chat-container
[react/view add-new.styles/new-chat-input-container
[react/text-input {:on-change-text #(re-frame/dispatch [:set :contacts/new-identity %])
[react/text-input {:on-change-text #(re-frame/dispatch [:new-chat/set-new-identity %])
:on-submit-editing #(when-not error-message
(re-frame/dispatch [:add-contact-handler]))
:placeholder (i18n/label :t/enter-contact-code)

View File

@ -70,7 +70,7 @@
(spec/def :contacts/contacts (spec/nilable (spec/map-of :global/not-empty-string :contact/contact)))
;public key of new contact during adding this new contact
(spec/def :contacts/new-identity (spec/nilable string?))
(spec/def :contacts/new-public-key-error (spec/nilable string?))
(spec/def :contacts/new-identity-error (spec/nilable string?))
;on showing this contact's profile (andrey: better to move into profile ns)
(spec/def :contacts/identity (spec/nilable :global/not-empty-string))
(spec/def :contacts/list-ui-props (spec/nilable (allowed-keys :opt-un [:contact-list-ui/edit?])))

View File

@ -174,7 +174,7 @@
[:contacts/contacts
:contacts/dapps
:contacts/new-identity
:contacts/new-public-key-error
:contacts/new-identity-error
:contacts/identity
:contacts/ui-props
:contacts/list-ui-props

View File

@ -7,6 +7,7 @@
status-im.ui.screens.accounts.login.events
status-im.ui.screens.accounts.recover.events
[status-im.ui.screens.contacts.events :as contacts]
status-im.ui.screens.add-new.new-chat.events
status-im.ui.screens.group.chat-settings.events
status-im.ui.screens.group.events
[status-im.ui.screens.navigation :as navigation]

View File

@ -11,7 +11,7 @@
;; this is the addresses of ens registries for the different networks
(def ens-registries
{:mainnet "0x314159265dd8dbb310642f98f50c066173c1259b"
:ropsten "0x112234455c3a32fd11230c42e7bccd4a84e02010"
:testnet "0x112234455c3a32fd11230c42e7bccd4a84e02010"
:rinkeby "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"})
(def default-namehash "0000000000000000000000000000000000000000000000000000000000000000")

View File

@ -28,7 +28,7 @@
:data (str "0x59d1d43c"
(subs (ens/namehash ens-name) 2)
"0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000d7374617475734163636f756e7400000000000000000000000000000000000000")}
(fn [_ text] (cb (ethereum/hex->string (subs text 130 214)))))))
(fn [_ text] (cb (ethereum/hex->string (subs text 130 394)))))))
#_(addr (:web3 @re-frame.db/app-db) "0x112234455c3a32fd11230c42e7bccd4a84e02010" "test.stateofus.eth" println)
#_(text (:web3 @re-frame.db/app-db) "0x112234455c3a32fd11230c42e7bccd4a84e02010" "test.stateofus.eth" println)
#_(addr (:web3 @re-frame.db/app-db) "0x112234455c3a32fd11230c42e7bccd4a84e02010" "erictest.stateofus.eth" println)
#_(text (:web3 @re-frame.db/app-db) "0x112234455c3a32fd11230c42e7bccd4a84e02010" "erictest.stateofus.eth" println)