[refactor] move contact.subs and utils.contacts to contact.db
functions defined in subs need to be reusable and testable independently from re-frame framework. they are moved into db namespace for that purpose Signed-off-by: yenda <eric@status.im>
This commit is contained in:
parent
eed610c46e
commit
1ba7feb439
|
@ -7,7 +7,7 @@
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
[status-im.utils.core :as utils]
|
[status-im.utils.core :as utils]
|
||||||
[status-im.utils.config :as config]
|
[status-im.utils.config :as config]
|
||||||
[status-im.utils.contacts :as utils.contacts]
|
[status-im.contact.db :as contact.db]
|
||||||
[status-im.utils.ethereum.core :as ethereum]
|
[status-im.utils.ethereum.core :as ethereum]
|
||||||
[status-im.utils.datetime :as time]
|
[status-im.utils.datetime :as time]
|
||||||
[status-im.transport.message.group-chat :as message.group-chat]
|
[status-im.transport.message.group-chat :as message.group-chat]
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
(let [chat-name' (chat.db/chat-name (get-in db [:chats chat-id]) from)
|
(let [chat-name' (chat.db/chat-name (get-in db [:chats chat-id]) from)
|
||||||
contact-name' (if-let [contact-name (get-in db [:contacts/contacts from :name])]
|
contact-name' (if-let [contact-name (get-in db [:contacts/contacts from :name])]
|
||||||
contact-name
|
contact-name
|
||||||
(:name (utils.contacts/public-key->new-contact from)))
|
(:name (contact.db/public-key->new-contact from)))
|
||||||
shown-chat-name (when-not (= chat-name' contact-name') chat-name') ; No point in repeating contact name if the chat name already contains the same name
|
shown-chat-name (when-not (= chat-name' contact-name') chat-name') ; No point in repeating contact name if the chat name already contains the same name
|
||||||
timestamp' (when-not (< (time/seconds-ago (time/to-date timestamp)) 15)
|
timestamp' (when-not (< (time/seconds-ago (time/to-date timestamp)) 15)
|
||||||
(str " @ " (time/to-short-str timestamp)))
|
(str " @ " (time/to-short-str timestamp)))
|
||||||
|
|
|
@ -1,18 +1,16 @@
|
||||||
(ns status-im.contact.core
|
(ns status-im.contact.core
|
||||||
(:require [status-im.accounts.db :as accounts.db]
|
(:require [re-frame.core :as re-frame]
|
||||||
[status-im.data-store.contacts :as contacts-store]
|
[status-im.accounts.db :as accounts.db]
|
||||||
[status-im.transport.message.protocol :as protocol]
|
|
||||||
[status-im.transport.message.contact :as message.contact]
|
|
||||||
[status-im.utils.contacts :as utils.contacts]
|
|
||||||
[status-im.utils.fx :as fx]
|
|
||||||
[re-frame.core :as re-frame]
|
|
||||||
[status-im.chat.models :as chat.models]
|
[status-im.chat.models :as chat.models]
|
||||||
|
[status-im.contact.db :as contact.db]
|
||||||
|
[status-im.data-store.contacts :as contacts-store]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
|
[status-im.transport.message.contact :as message.contact]
|
||||||
|
[status-im.transport.message.protocol :as protocol]
|
||||||
[status-im.ui.screens.add-new.new-chat.db :as new-chat.db]
|
[status-im.ui.screens.add-new.new-chat.db :as new-chat.db]
|
||||||
[status-im.ui.screens.navigation :as navigation]
|
[status-im.ui.screens.navigation :as navigation]
|
||||||
[status-im.utils.js-resources :as js-res]
|
[status-im.utils.fx :as fx]
|
||||||
[status-im.utils.utils :as utils]
|
[status-im.utils.utils :as utils]))
|
||||||
[status-im.utils.fx :as fx]))
|
|
||||||
|
|
||||||
(fx/defn load-contacts
|
(fx/defn load-contacts
|
||||||
[{:keys [db all-contacts]}]
|
[{:keys [db all-contacts]}]
|
||||||
|
@ -29,8 +27,8 @@
|
||||||
(defn build-contact [{{:keys [chats] :account/keys [account]
|
(defn build-contact [{{:keys [chats] :account/keys [account]
|
||||||
:contacts/keys [contacts]} :db} public-key]
|
:contacts/keys [contacts]} :db} public-key]
|
||||||
(cond-> (assoc (or (get contacts public-key)
|
(cond-> (assoc (or (get contacts public-key)
|
||||||
(utils.contacts/public-key->new-contact public-key))
|
(contact.db/public-key->new-contact public-key))
|
||||||
:address (utils.contacts/public-key->address public-key))
|
:address (contact.db/public-key->address public-key))
|
||||||
|
|
||||||
(= public-key (:public-key account)) (assoc :name (:name account))))
|
(= public-key (:public-key account)) (assoc :name (:name account))))
|
||||||
|
|
||||||
|
@ -110,7 +108,7 @@
|
||||||
:name name
|
:name name
|
||||||
:address (or address
|
:address (or address
|
||||||
(:address contact)
|
(:address contact)
|
||||||
(utils.contacts/public-key->address public-key))
|
(contact.db/public-key->address public-key))
|
||||||
:last-updated timestamp-ms
|
:last-updated timestamp-ms
|
||||||
;;NOTE (yenda) in case of concurrent contact request
|
;;NOTE (yenda) in case of concurrent contact request
|
||||||
:pending? (get contact :pending? true)}
|
:pending? (get contact :pending? true)}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
(ns status-im.contact.db
|
(ns status-im.contact.db
|
||||||
(:require [cljs.spec.alpha :as spec]
|
(:require [cljs.spec.alpha :as spec]
|
||||||
|
[status-im.js-dependencies :as js-dependencies]
|
||||||
|
[status-im.utils.identicon :as identicon]
|
||||||
|
[status-im.utils.gfycat.core :as gfycat]
|
||||||
|
[status-im.utils.ethereum.core :as ethereum]
|
||||||
status-im.utils.db))
|
status-im.utils.db))
|
||||||
|
|
||||||
;;;; DB
|
;;;; DB
|
||||||
|
@ -77,3 +81,59 @@
|
||||||
|
|
||||||
(spec/def :contact/new-tag string?)
|
(spec/def :contact/new-tag string?)
|
||||||
(spec/def :ui/contact (spec/keys :opt [:contact/new-tag]))
|
(spec/def :ui/contact (spec/keys :opt [:contact/new-tag]))
|
||||||
|
|
||||||
|
(defn public-key->new-contact [public-key]
|
||||||
|
{:name (gfycat/generate-gfy public-key)
|
||||||
|
:photo-path (identicon/identicon public-key)
|
||||||
|
:public-key public-key})
|
||||||
|
|
||||||
|
(defn public-key->address [public-key]
|
||||||
|
(let [length (count public-key)
|
||||||
|
normalized-key (case length
|
||||||
|
132 (subs public-key 4)
|
||||||
|
130 (subs public-key 2)
|
||||||
|
128 public-key
|
||||||
|
nil)]
|
||||||
|
(when normalized-key
|
||||||
|
(subs (.sha3 js-dependencies/Web3.prototype normalized-key #js {:encoding "hex"}) 26))))
|
||||||
|
|
||||||
|
(defn- contact-by-address [[_ contact] address]
|
||||||
|
(when (ethereum/address= (:address contact) address)
|
||||||
|
contact))
|
||||||
|
|
||||||
|
(defn find-contact-by-address [contacts address]
|
||||||
|
(some #(contact-by-address % address) contacts))
|
||||||
|
|
||||||
|
(defn sort-contacts
|
||||||
|
[contacts]
|
||||||
|
(sort (fn [c1 c2]
|
||||||
|
(let [name1 (or (:name c1) (:address c1) (:public-key c1))
|
||||||
|
name2 (or (:name c2) (:address c2) (:public-key c2))]
|
||||||
|
(compare (clojure.string/lower-case name1)
|
||||||
|
(clojure.string/lower-case name2))))
|
||||||
|
(vals contacts)))
|
||||||
|
|
||||||
|
(defn filter-dapps
|
||||||
|
[v dev-mode?]
|
||||||
|
(remove #(when-not dev-mode? (true? (:developer? %))) v))
|
||||||
|
|
||||||
|
(defn filter-group-contacts
|
||||||
|
[group-contacts contacts]
|
||||||
|
(let [group-contacts' (into #{} group-contacts)]
|
||||||
|
(filter #(group-contacts' (:public-key %)) contacts)))
|
||||||
|
|
||||||
|
(defn query-chat-contacts
|
||||||
|
[{:keys [contacts]} all-contacts query-fn]
|
||||||
|
(let [participant-set (into #{} (filter identity) contacts)]
|
||||||
|
(query-fn (comp participant-set :public-key) (vals all-contacts))))
|
||||||
|
|
||||||
|
(defn get-all-contacts-in-group-chat
|
||||||
|
[members contacts current-account]
|
||||||
|
(let [current-account-contact (-> current-account
|
||||||
|
(select-keys [:name :photo-path :public-key]))
|
||||||
|
all-contacts (assoc contacts (:public-key current-account-contact) current-account-contact)]
|
||||||
|
(->> members
|
||||||
|
(map #(or (get all-contacts %)
|
||||||
|
(public-key->new-contact %)))
|
||||||
|
(remove :dapp?)
|
||||||
|
(sort-by (comp clojure.string/lower-case :name)))))
|
||||||
|
|
|
@ -1,164 +1,154 @@
|
||||||
(ns status-im.contact.subs
|
(ns status-im.contact.subs
|
||||||
(:require [re-frame.core :refer [reg-sub subscribe]]
|
(:require [re-frame.core :as re-frame]
|
||||||
[status-im.utils.contacts :as utils.contacts]
|
[status-im.utils.identicon :as identicon]
|
||||||
[status-im.utils.identicon :as identicon]))
|
[status-im.contact.db :as contact.db]))
|
||||||
|
|
||||||
(reg-sub :get-current-contact-identity :contacts/identity)
|
(re-frame/reg-sub :get-current-contact-identity :contacts/identity)
|
||||||
|
|
||||||
(reg-sub :get-contacts :contacts/contacts)
|
(re-frame/reg-sub :get-contacts :contacts/contacts)
|
||||||
|
|
||||||
(reg-sub :get-dapps
|
(re-frame/reg-sub :get-dapps
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(:contacts/dapps db)))
|
(:contacts/dapps db)))
|
||||||
|
|
||||||
(reg-sub :get-current-contact
|
(re-frame/reg-sub
|
||||||
:<- [:get-contacts]
|
:get-current-contact
|
||||||
:<- [:get-current-contact-identity]
|
:<- [:get-contacts]
|
||||||
(fn [[contacts identity]]
|
:<- [:get-current-contact-identity]
|
||||||
(contacts identity)))
|
(fn [[contacts identity]]
|
||||||
|
(contacts identity)))
|
||||||
|
|
||||||
(reg-sub :get-current-chat-contact
|
(re-frame/reg-sub
|
||||||
:<- [:get-contacts]
|
:get-current-chat-contact
|
||||||
:<- [:get-current-chat-id]
|
:<- [:get-contacts]
|
||||||
(fn [[contacts chat-id]]
|
:<- [:get-current-chat-id]
|
||||||
(get contacts chat-id)))
|
(fn [[contacts chat-id]]
|
||||||
|
(get contacts chat-id)))
|
||||||
|
|
||||||
(defn sort-contacts [contacts]
|
(re-frame/reg-sub
|
||||||
(sort (fn [c1 c2]
|
:all-added-contacts
|
||||||
(let [name1 (or (:name c1) (:address c1) (:public-key c1))
|
:<- [:get-contacts]
|
||||||
name2 (or (:name c2) (:address c2) (:public-key c2))]
|
(fn [contacts]
|
||||||
(compare (clojure.string/lower-case name1)
|
(->> contacts
|
||||||
(clojure.string/lower-case name2))))
|
(remove (fn [[_ {:keys [pending? hide-contact?]}]]
|
||||||
(vals contacts)))
|
(or pending? hide-contact?)))
|
||||||
|
(contact.db/sort-contacts))))
|
||||||
|
|
||||||
(reg-sub :all-added-contacts
|
(re-frame/reg-sub
|
||||||
:<- [:get-contacts]
|
:all-added-people-contacts
|
||||||
(fn [contacts]
|
:<- [:all-added-contacts]
|
||||||
(->> contacts
|
(fn [contacts]
|
||||||
(remove (fn [[_ {:keys [pending? hide-contact?]}]]
|
(remove :dapp? contacts)))
|
||||||
(or pending? hide-contact?)))
|
|
||||||
(sort-contacts))))
|
|
||||||
|
|
||||||
(reg-sub :all-added-people-contacts
|
(re-frame/reg-sub
|
||||||
:<- [:all-added-contacts]
|
:all-dapps
|
||||||
(fn [contacts]
|
:<- [:get-dapps]
|
||||||
(remove :dapp? contacts)))
|
:<- [:account/account]
|
||||||
|
(fn [[dapps {:keys [dev-mode?]}]]
|
||||||
|
(map (fn [m] (update m :data
|
||||||
|
#(contact.db/filter-dapps % dev-mode?)))
|
||||||
|
dapps)))
|
||||||
|
|
||||||
(defn- filter-dapps [v dev-mode?]
|
(re-frame/reg-sub
|
||||||
(remove #(when-not dev-mode? (true? (:developer? %))) v))
|
:get-people-in-current-chat
|
||||||
|
:<- [:get-current-chat-contacts]
|
||||||
|
(fn [contacts]
|
||||||
|
(remove #(true? (:dapp? %)) contacts)))
|
||||||
|
|
||||||
(reg-sub :all-dapps
|
(re-frame/reg-sub
|
||||||
:<- [:get-dapps]
|
:get-contact-by-identity
|
||||||
:<- [:account/account]
|
:<- [:get-contacts]
|
||||||
(fn [[dapps {:keys [dev-mode?]}]]
|
:<- [:get-current-chat]
|
||||||
(map (fn [m] (update m :data #(filter-dapps % dev-mode?))) dapps)))
|
(fn [[all-contacts {:keys [contacts]}] [_ identity]]
|
||||||
|
(let [identity' (or identity (first contacts))]
|
||||||
|
(or
|
||||||
|
(get all-contacts identity')
|
||||||
|
(contact.db/public-key->new-contact identity')))))
|
||||||
|
|
||||||
(reg-sub :get-people-in-current-chat
|
(re-frame/reg-sub
|
||||||
:<- [:get-current-chat-contacts]
|
:contacts/dapps-by-name
|
||||||
(fn [contacts]
|
:<- [:all-dapps]
|
||||||
(remove #(true? (:dapp? %)) contacts)))
|
(fn [dapps]
|
||||||
|
(reduce (fn [dapps-by-name category]
|
||||||
|
(merge dapps-by-name
|
||||||
|
(reduce (fn [acc {:keys [name] :as dapp}]
|
||||||
|
(assoc acc name dapp))
|
||||||
|
{}
|
||||||
|
(:data category))))
|
||||||
|
{}
|
||||||
|
dapps)))
|
||||||
|
|
||||||
(defn filter-group-contacts [group-contacts contacts]
|
(re-frame/reg-sub
|
||||||
(let [group-contacts' (into #{} group-contacts)]
|
:get-contact-name-by-identity
|
||||||
(filter #(group-contacts' (:public-key %)) contacts)))
|
:<- [:get-contacts]
|
||||||
|
:<- [:account/account]
|
||||||
|
(fn [[contacts current-account] [_ identity]]
|
||||||
|
(let [me? (= (:public-key current-account) identity)]
|
||||||
|
(if me?
|
||||||
|
(:name current-account)
|
||||||
|
(:name (contacts identity))))))
|
||||||
|
|
||||||
(reg-sub :get-contact-by-identity
|
(re-frame/reg-sub
|
||||||
:<- [:get-contacts]
|
:query-current-chat-contacts
|
||||||
:<- [:get-current-chat]
|
:<- [:get-current-chat]
|
||||||
(fn [[all-contacts {:keys [contacts]}] [_ identity]]
|
:<- [:get-contacts]
|
||||||
(let [identity' (or identity (first contacts))]
|
(fn [[chat contacts [_ query-fn]]]
|
||||||
(or
|
(contact.db/query-chat-contacts chat contacts query-fn)))
|
||||||
(get all-contacts identity')
|
|
||||||
(utils.contacts/public-key->new-contact identity')))))
|
|
||||||
|
|
||||||
(reg-sub :contacts/dapps-by-name
|
(re-frame/reg-sub
|
||||||
:<- [:all-dapps]
|
:get-all-contacts-not-in-current-chat
|
||||||
(fn [dapps]
|
:<- [:query-current-chat-contacts remove]
|
||||||
(reduce (fn [dapps-by-name category]
|
(fn [contacts]
|
||||||
(merge dapps-by-name
|
(->> contacts
|
||||||
(reduce (fn [acc {:keys [name] :as dapp}]
|
(remove :dapp?)
|
||||||
(assoc acc name dapp))
|
(sort-by (comp clojure.string/lower-case :name)))))
|
||||||
{}
|
|
||||||
(:data category))))
|
|
||||||
{}
|
|
||||||
dapps)))
|
|
||||||
|
|
||||||
(reg-sub :get-contact-name-by-identity
|
(re-frame/reg-sub
|
||||||
:<- [:get-contacts]
|
:get-current-chat-contacts
|
||||||
:<- [:account/account]
|
:<- [:get-current-chat]
|
||||||
(fn [[contacts current-account] [_ identity]]
|
:<- [:get-contacts]
|
||||||
(let [me? (= (:public-key current-account) identity)]
|
:<- [:account/account]
|
||||||
(if me?
|
(fn [[{:keys [contacts]} all-contacts current-account]]
|
||||||
(:name current-account)
|
(contact.db/get-all-contacts-in-group-chat contacts all-contacts current-account)))
|
||||||
(:name (contacts identity))))))
|
|
||||||
|
|
||||||
(defn query-chat-contacts [[{:keys [contacts]} all-contacts] [_ query-fn]]
|
(re-frame/reg-sub
|
||||||
(let [participant-set (into #{} (filter identity) contacts)]
|
:get-contacts-by-chat
|
||||||
(query-fn (comp participant-set :public-key) (vals all-contacts))))
|
(fn [[_ _ chat-id] _]
|
||||||
|
[(re-frame/subscribe [:get-chat chat-id])
|
||||||
|
(re-frame/subscribe [:get-contacts])])
|
||||||
|
(fn [[chat all-contacts [_ query-fn]]]
|
||||||
|
(contact.db/query-chat-contacts chat all-contacts query-fn)))
|
||||||
|
|
||||||
(reg-sub :query-current-chat-contacts
|
(re-frame/reg-sub
|
||||||
:<- [:get-current-chat]
|
:get-chat-photo
|
||||||
:<- [:get-contacts]
|
(fn [[_ chat-id] _]
|
||||||
query-chat-contacts)
|
[(re-frame/subscribe [:get-chat chat-id])
|
||||||
|
(re-frame/subscribe [:get-contacts-by-chat filter chat-id])])
|
||||||
|
(fn [[chat contacts] [_ chat-id]]
|
||||||
|
(when (and chat (not (:group-chat chat)))
|
||||||
|
(cond
|
||||||
|
(:photo-path chat)
|
||||||
|
(:photo-path chat)
|
||||||
|
|
||||||
(reg-sub :get-all-contacts-not-in-current-chat
|
(pos? (count contacts))
|
||||||
:<- [:query-current-chat-contacts remove]
|
(:photo-path (first contacts))
|
||||||
(fn [contacts]
|
|
||||||
(->> contacts
|
|
||||||
(remove :dapp?)
|
|
||||||
(sort-by (comp clojure.string/lower-case :name)))))
|
|
||||||
|
|
||||||
(defn get-all-contacts-in-group-chat
|
:else
|
||||||
[members contacts current-account]
|
(identicon/identicon chat-id)))))
|
||||||
(let [current-account-contact (-> current-account
|
|
||||||
(select-keys [:name :photo-path :public-key]))
|
|
||||||
all-contacts (assoc contacts (:public-key current-account-contact) current-account-contact)]
|
|
||||||
(->> members
|
|
||||||
(map #(or (get all-contacts %)
|
|
||||||
(utils.contacts/public-key->new-contact %)))
|
|
||||||
(remove :dapp?)
|
|
||||||
(sort-by (comp clojure.string/lower-case :name)))))
|
|
||||||
|
|
||||||
(reg-sub :get-current-chat-contacts
|
(re-frame/reg-sub
|
||||||
:<- [:get-current-chat]
|
:get-contact-by-address
|
||||||
:<- [:get-contacts]
|
:<- [:get-contacts]
|
||||||
:<- [:account/account]
|
(fn [contacts [_ address]]
|
||||||
(fn [[{:keys [contacts]} all-contacts current-account]]
|
(contact.db/find-contact-by-address contacts address)))
|
||||||
(get-all-contacts-in-group-chat contacts all-contacts current-account)))
|
|
||||||
|
|
||||||
(reg-sub :get-contacts-by-chat
|
(re-frame/reg-sub
|
||||||
(fn [[_ _ chat-id] _]
|
:get-contacts-by-address
|
||||||
[(subscribe [:get-chat chat-id])
|
:<- [:get-contacts]
|
||||||
(subscribe [:get-contacts])])
|
(fn [contacts]
|
||||||
query-chat-contacts)
|
(reduce (fn [acc [_ {:keys [address] :as contact}]]
|
||||||
|
(if address
|
||||||
(reg-sub :get-chat-photo
|
(assoc acc address contact)
|
||||||
(fn [[_ chat-id] _]
|
acc))
|
||||||
[(subscribe [:get-chat chat-id])
|
{}
|
||||||
(subscribe [:get-contacts-by-chat filter chat-id])])
|
contacts)))
|
||||||
(fn [[chat contacts] [_ chat-id]]
|
|
||||||
(when (and chat (not (:group-chat chat)))
|
|
||||||
(cond
|
|
||||||
(:photo-path chat)
|
|
||||||
(:photo-path chat)
|
|
||||||
|
|
||||||
(pos? (count contacts))
|
|
||||||
(:photo-path (first contacts))
|
|
||||||
|
|
||||||
:else
|
|
||||||
(identicon/identicon chat-id)))))
|
|
||||||
|
|
||||||
(reg-sub :get-contact-by-address
|
|
||||||
:<- [:get-contacts]
|
|
||||||
(fn [contacts [_ address]]
|
|
||||||
(utils.contacts/find-contact-by-address contacts address)))
|
|
||||||
|
|
||||||
(reg-sub :get-contacts-by-address
|
|
||||||
:<- [:get-contacts]
|
|
||||||
(fn [contacts]
|
|
||||||
(reduce (fn [acc [_ {:keys [address] :as contact}]]
|
|
||||||
(if address
|
|
||||||
(assoc acc address contact)
|
|
||||||
acc))
|
|
||||||
{}
|
|
||||||
contacts)))
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
[status-im.ui.screens.desktop.main.tabs.profile.views :as profile.views]
|
[status-im.ui.screens.desktop.main.tabs.profile.views :as profile.views]
|
||||||
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
[status-im.ui.components.icons.vector-icons :as vector-icons]
|
||||||
[status-im.ui.screens.desktop.main.chat.styles :as styles]
|
[status-im.ui.screens.desktop.main.chat.styles :as styles]
|
||||||
[status-im.utils.contacts :as utils.contacts]
|
[status-im.contact.db :as contact.db]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
[status-im.ui.screens.desktop.main.chat.events :as chat.events]
|
[status-im.ui.screens.desktop.main.chat.events :as chat.events]
|
||||||
[status-im.ui.screens.chat.message.message :as chat.message]))
|
[status-im.ui.screens.chat.message.message :as chat.message]))
|
||||||
|
@ -332,7 +332,7 @@
|
||||||
(views/defview chat-profile []
|
(views/defview chat-profile []
|
||||||
(views/letsubs [identity [:get-current-contact-identity]
|
(views/letsubs [identity [:get-current-contact-identity]
|
||||||
maybe-contact [:get-current-contact]]
|
maybe-contact [:get-current-contact]]
|
||||||
(let [contact (or maybe-contact (utils.contacts/public-key->new-contact identity))
|
(let [contact (or maybe-contact (contact.db/public-key->new-contact identity))
|
||||||
{:keys [pending? public-key]} contact]
|
{:keys [pending? public-key]} contact]
|
||||||
[react/view {:style styles/chat-profile-body}
|
[react/view {:style styles/chat-profile-body}
|
||||||
[profile.views/profile-badge contact]
|
[profile.views/profile-badge contact]
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
(ns status-im.ui.screens.profile.contact.views
|
(ns status-im.ui.screens.profile.contact.views
|
||||||
(:require-macros [status-im.utils.views :refer [defview letsubs]])
|
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
|
[status-im.contact.db :as contact.db]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
[status-im.utils.contacts :as utils.contacts]
|
|
||||||
[status-im.ui.components.react :as react]
|
|
||||||
[status-im.ui.components.list.views :as list]
|
[status-im.ui.components.list.views :as list]
|
||||||
[status-im.ui.components.toolbar.view :as toolbar]
|
[status-im.ui.components.react :as react]
|
||||||
[status-im.ui.components.status-bar.view :as status-bar]
|
[status-im.ui.components.status-bar.view :as status-bar]
|
||||||
[status-im.ui.screens.profile.contact.styles :as styles]
|
[status-im.ui.components.toolbar.view :as toolbar]
|
||||||
[status-im.ui.screens.profile.components.styles :as profile.components.styles]
|
[status-im.ui.screens.profile.components.styles :as profile.components.styles]
|
||||||
[status-im.ui.screens.profile.components.views :as profile.components]))
|
[status-im.ui.screens.profile.components.views :as profile.components]
|
||||||
|
[status-im.ui.screens.profile.contact.styles :as styles])
|
||||||
|
(:require-macros [status-im.utils.views :refer [defview letsubs]]))
|
||||||
|
|
||||||
(defn profile-contact-toolbar []
|
(defn profile-contact-toolbar []
|
||||||
[toolbar/toolbar {}
|
[toolbar/toolbar {}
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
(defview profile []
|
(defview profile []
|
||||||
(letsubs [identity [:get-current-contact-identity]
|
(letsubs [identity [:get-current-contact-identity]
|
||||||
maybe-contact [:get-current-contact]]
|
maybe-contact [:get-current-contact]]
|
||||||
(let [contact (or maybe-contact (utils.contacts/public-key->new-contact identity))]
|
(let [contact (or maybe-contact (contact.db/public-key->new-contact identity))]
|
||||||
[react/view profile.components.styles/profile
|
[react/view profile.components.styles/profile
|
||||||
[status-bar/status-bar]
|
[status-bar/status-bar]
|
||||||
[profile-contact-toolbar]
|
[profile-contact-toolbar]
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
(ns status-im.ui.screens.wallet.choose-recipient.events
|
(ns status-im.ui.screens.wallet.choose-recipient.events
|
||||||
(:require [status-im.constants :as constants]
|
(:require [re-frame.core :as re-frame]
|
||||||
|
[status-im.constants :as constants]
|
||||||
|
[status-im.contact.db :as contact.db]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
[status-im.utils.ethereum.core :as ethereum]
|
[status-im.utils.ethereum.core :as ethereum]
|
||||||
[status-im.utils.ethereum.eip681 :as eip681]
|
[status-im.utils.ethereum.eip681 :as eip681]
|
||||||
[status-im.utils.handlers :as handlers]
|
|
||||||
[status-im.utils.money :as money]
|
|
||||||
[status-im.utils.ethereum.ens :as ens]
|
[status-im.utils.ethereum.ens :as ens]
|
||||||
[re-frame.core :as re-frame]
|
[status-im.utils.handlers :as handlers]
|
||||||
[status-im.utils.contacts :as utils.contacts]))
|
[status-im.utils.money :as money]))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:wallet/toggle-flashlight
|
:wallet/toggle-flashlight
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
{:db (assoc-in db [:wallet :send-transaction :camera-flashlight] toggled-state)})))
|
{:db (assoc-in db [:wallet :send-transaction :camera-flashlight] toggled-state)})))
|
||||||
|
|
||||||
(defn- find-address-name [db address]
|
(defn- find-address-name [db address]
|
||||||
(:name (utils.contacts/find-contact-by-address (:contacts/contacts db) address)))
|
(:name (contact.db/find-contact-by-address (:contacts/contacts db) address)))
|
||||||
|
|
||||||
(defn- fill-request-details [db {:keys [address name value symbol gas gasPrice public-key from-chat?]}]
|
(defn- fill-request-details [db {:keys [address name value symbol gas gasPrice public-key from-chat?]}]
|
||||||
{:pre [(not (nil? address))]}
|
{:pre [(not (nil? address))]}
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
(ns status-im.utils.contacts
|
|
||||||
(:require [status-im.js-dependencies :as js-dependencies]
|
|
||||||
[status-im.utils.identicon :as identicon]
|
|
||||||
[status-im.utils.gfycat.core :as gfycat]
|
|
||||||
[status-im.utils.ethereum.core :as ethereum]))
|
|
||||||
|
|
||||||
(defn public-key->new-contact [public-key]
|
|
||||||
{:name (gfycat/generate-gfy public-key)
|
|
||||||
:photo-path (identicon/identicon public-key)
|
|
||||||
:public-key public-key})
|
|
||||||
|
|
||||||
(defn public-key->address [public-key]
|
|
||||||
(let [length (count public-key)
|
|
||||||
normalized-key (case length
|
|
||||||
132 (subs public-key 4)
|
|
||||||
130 (subs public-key 2)
|
|
||||||
128 public-key
|
|
||||||
nil)]
|
|
||||||
(when normalized-key
|
|
||||||
(subs (.sha3 js-dependencies/Web3.prototype normalized-key #js {:encoding "hex"}) 26))))
|
|
||||||
|
|
||||||
(defn- contact-by-address [[_ contact] address]
|
|
||||||
(when (ethereum/address= (:address contact) address)
|
|
||||||
contact))
|
|
||||||
|
|
||||||
(defn find-contact-by-address [contacts address]
|
|
||||||
(some #(contact-by-address % address) contacts))
|
|
|
@ -1,7 +1,7 @@
|
||||||
(ns status-im.test.contacts.subs
|
(ns status-im.test.contacts.db
|
||||||
(:require [cljs.test :refer-macros [deftest is testing]]
|
(:require [cljs.test :refer-macros [deftest is testing]]
|
||||||
[status-im.utils.identicon :as identicon]
|
[status-im.utils.identicon :as identicon]
|
||||||
[status-im.contact.subs :as contacts-subs]))
|
[status-im.contact.db :as contact.db]))
|
||||||
|
|
||||||
(deftest contacts-subs
|
(deftest contacts-subs
|
||||||
(testing "get-all-contacts-in-group-chat"
|
(testing "get-all-contacts-in-group-chat"
|
||||||
|
@ -35,9 +35,9 @@
|
||||||
:photo-path "photo2",
|
:photo-path "photo2",
|
||||||
:public-key
|
:public-key
|
||||||
"0x048a2f8b80c60f89a91b4c1316e56f75b087f446e7b8701ceca06a40142d8efe1f5aa36bd0fee9e248060a8d5207b43ae98bef4617c18c71e66f920f324869c09f"}]
|
"0x048a2f8b80c60f89a91b4c1316e56f75b087f446e7b8701ceca06a40142d8efe1f5aa36bd0fee9e248060a8d5207b43ae98bef4617c18c71e66f920f324869c09f"}]
|
||||||
(is (= (contacts-subs/get-all-contacts-in-group-chat chat-contact-ids
|
(is (= (contact.db/get-all-contacts-in-group-chat chat-contact-ids
|
||||||
contacts
|
contacts
|
||||||
current-account)
|
current-account)
|
||||||
[{:name "Snappy Impressive Leonberger"
|
[{:name "Snappy Impressive Leonberger"
|
||||||
:photo-path "generated"
|
:photo-path "generated"
|
||||||
:public-key "0x04fcf40c526b09ff9fb22f4a5dbd08490ef9b64af700870f8a0ba2133f4251d5607ed83cd9047b8c2796576bc83fa0de23a13a4dced07654b8ff137fe744047917"}
|
:public-key "0x04fcf40c526b09ff9fb22f4a5dbd08490ef9b64af700870f8a0ba2133f4251d5607ed83cd9047b8c2796576bc83fa0de23a13a4dced07654b8ff137fe744047917"}
|
|
@ -1,6 +1,6 @@
|
||||||
(ns status-im.test.runner
|
(ns status-im.test.runner
|
||||||
(:require [doo.runner :refer-macros [doo-tests]]
|
(:require [doo.runner :refer-macros [doo-tests]]
|
||||||
[status-im.test.contacts.subs]
|
[status-im.test.contacts.db]
|
||||||
[status-im.test.data-store.chats]
|
[status-im.test.data-store.chats]
|
||||||
[status-im.test.data-store.realm.core]
|
[status-im.test.data-store.realm.core]
|
||||||
[status-im.test.extensions.core]
|
[status-im.test.extensions.core]
|
||||||
|
@ -69,8 +69,8 @@
|
||||||
(doo-tests
|
(doo-tests
|
||||||
'status-im.test.utils.async
|
'status-im.test.utils.async
|
||||||
'status-im.test.chat.db
|
'status-im.test.chat.db
|
||||||
|
'status-im.test.contacts.db
|
||||||
'status-im.test.chat.models
|
'status-im.test.chat.models
|
||||||
'status-im.test.contacts.subs
|
|
||||||
'status-im.test.init.core
|
'status-im.test.init.core
|
||||||
'status-im.test.data-store.chats
|
'status-im.test.data-store.chats
|
||||||
'status-im.test.data-store.realm.core
|
'status-im.test.data-store.realm.core
|
||||||
|
|
Loading…
Reference in New Issue