Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
cammellos committed Oct 11, 2019
1 parent e30a547 commit cf2b2ef
Show file tree
Hide file tree
Showing 20 changed files with 133 additions and 70 deletions.
6 changes: 3 additions & 3 deletions env/dev/env/config.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns env.config)

(def figwheel-urls {:android "ws://localhost:3449/figwheel-ws",
:ios "ws://192.168.0.9:3449/figwheel-ws",
(def figwheel-urls {:android "ws://10.0.3.2:3449/figwheel-ws",
:ios "ws://192.168.58.1:3449/figwheel-ws",
:desktop "ws://localhost:3449/figwheel-ws"}
)
)
17 changes: 17 additions & 0 deletions src/status_im/contact/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,20 @@
(assoc :tribute-to-talk (or tribute-to-talk
{:disabled? true})))]
{:db (assoc-in db [:contacts/contacts public-key] contact)}))

(defn add-ens-names [contacts names]
(reduce-kv (fn [acc public-key-keyword {:keys [verified error]}]
(let [public-key (str "0x" (name public-key-keyword))
contact (contact.db/public-key->contact contacts public-key)]

(if verified
(assoc acc public-key (assoc contact :verified true))
(assoc acc public-key contact))))
(or contacts {})
names))

(fx/defn names-verified
{:events [:contacts/ens-names-verified]}
[{:keys [db]} names]
{:db (update db :contacts add-ens-names names)})

14 changes: 9 additions & 5 deletions src/status_im/contact/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
(spec/def :contact/last-online (spec/nilable int?))
(spec/def :contact/last-updated (spec/nilable int?))
(spec/def :contact/name (spec/nilable string?))
(spec/def :contact/ens-verified (spec/nilable boolean?))
(spec/def :contact/ens-verified-at (spec/nilable int?))
(spec/def :contact/public-key :global/not-empty-string)
(spec/def :contact/photo-path (spec/nilable string?))

Expand Down Expand Up @@ -63,11 +65,13 @@
(spec/def :ui/contact (spec/keys :opt [:contact/new-tag]))

(defn public-key->new-contact [public-key]
{:name (gfycat/generate-gfy public-key)
:address (ethereum/public-key->address public-key)
:identicon (identicon/identicon public-key)
:public-key public-key
:system-tags #{}})
(let [alias (gfycat/generate-gfy public-key)]
{:alias alias
:name alias
:address (ethereum/public-key->address public-key)
:identicon (identicon/identicon public-key)
:public-key public-key
:system-tags #{}}))

(defn public-key->contact
[contacts public-key]
Expand Down
4 changes: 4 additions & 0 deletions src/status_im/data_store/contacts.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
:photoPath :photo-path
:deviceInfo :device-info
:tributeToTalk :tribute-to-talk
:ensVerifiedAt :ens-verified-at
:ensVerified :ens-verified
:systemTags :system-tags
:lastUpdated :last-updated})))

Expand All @@ -42,6 +44,8 @@
(update :tribute-to-talk types/serialize)
(update :system-tags #(mapv str %))
(clojure.set/rename-keys {:public-key :id
:ens-verified :ensVerified
:ens-verified-at :ensVerifiedAt
:photo-path :photoPath
:device-info :deviceInfo
:tribute-to-talk :tributeToTalk
Expand Down
18 changes: 18 additions & 0 deletions src/status_im/ens/core.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns status-im.ens.core
(:require [clojure.string :as string]
[re-frame.core :as re-frame]
[taoensso.timbre :as log]
[status-im.multiaccounts.update.core :as multiaccounts.update]
[status-im.ethereum.abi-spec :as abi-spec]
[status-im.ethereum.contracts :as contracts]
Expand All @@ -10,6 +11,7 @@
[status-im.ethereum.stateofus :as stateofus]
[status-im.ui.screens.navigation :as navigation]
[status-im.utils.fx :as fx]
[status-im.ethereum.json-rpc :as json-rpc]
[status-im.utils.money :as money]
[status-im.signing.core :as signing]
[status-im.ethereum.eip55 :as eip55])
Expand Down Expand Up @@ -176,3 +178,19 @@
(fx/merge cofx
{:db (assoc-in db [:ens/registration :registering?] true)}
(navigation/navigate-to-cofx :ens-register {})))

(defn verify-names [names]
(json-rpc/call {:method "shhext_verifyENSNames"
:params [names]
:on-success #(re-frame/dispatch [:contacts/ens-names-verified %])
:on-failure #(log/error "failed to resolve ens names" % names)}))

(re-frame/reg-fx
::verify-names
(fn [names]
(verify-names (distinct names))))

(fx/defn verify-names-from-message [cofx {:keys [content]} signature]
(when (:name content)
{::verify-names [{:name (:name content)
:publicKey (subs signature 2)}]}))
1 change: 1 addition & 0 deletions src/status_im/ethereum/json_rpc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
;;TODO not used anywhere?
"shhext_deleteChat" {}
"shhext_saveContact" {}
"shhext_verifyENSNames" {}
"status_chats" {}
"wallet_getTransfers" {}
"wallet_getTokensBalances" {}
Expand Down
19 changes: 11 additions & 8 deletions src/status_im/multiaccounts/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@

(defn displayed-name
"Use preferred name, name or alias in that order"
[{:keys [name preferred-name alias public-key]}]
(let [name (or preferred-name
name
alias)]
(if (ens/is-valid-eth-name? name)
(let [username (stateofus/username name)]
(str "@" (or username name)))
(or name (gfycat/generate-gfy public-key)))))
[{:keys [name preferred-name alias public-key ens-verified]}]
(let [ens-name (or preferred-name
name)]
;; Preferred name is our own?
;; otherwise we make sure is verified
(if (or preferred-name
(and ens-verified
name))
(let [username (stateofus/username ens-name)]
(str "@" (or username ens-name)))
(or alias (gfycat/generate-gfy public-key)))))

(defn displayed-photo
"If a photo-path is set use it, otherwise fallback on identicon or generate"
Expand Down
5 changes: 3 additions & 2 deletions src/status_im/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,11 +1482,12 @@
(fn [[contacts current-multiaccount] [_ identity]]
(let [me? (= (:public-key current-multiaccount) identity)]
(if me?
{:username (:name current-multiaccount)
{:ens-name (:name current-multiaccount)
:alias (gfycat/generate-gfy identity)}
(let [contact (or (contacts identity)
(contact.db/public-key->new-contact identity))]
{:username (:name contact)
{:ens-name (when (:ens-verified contact)
(:name contact))
:alias (or (:alias contact)
(gfycat/generate-gfy identity))})))))

Expand Down
11 changes: 11 additions & 0 deletions src/status_im/transport/impl/receive.cljs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
(ns status-im.transport.impl.receive
(:require [status-im.group-chats.core :as group-chats]
[status-im.contact.core :as contact]
[status-im.utils.fx :as fx]
[status-im.ens.core :as ens]
[status-im.pairing.core :as pairing]
[status-im.transport.message.contact :as transport.contact]
[status-im.transport.message.group-chat :as transport.group-chat]
[status-im.transport.message.pairing :as transport.pairing]
[status-im.transport.message.core :as transport.message]

[status-im.transport.message.protocol :as protocol]))

(extend-type transport.group-chat/GroupMembershipUpdate
Expand Down Expand Up @@ -37,3 +41,10 @@
protocol/StatusMessage
(receive [this _ signature timestamp cofx]
(pairing/handle-pair-installation cofx this timestamp signature)))

(extend-type protocol/Message
protocol/StatusMessage
(receive [this chat-id signature timestamp cofx]
(fx/merge cofx
(transport.message/receive-transit-message this chat-id signature timestamp)
(ens/verify-names-from-message this signature))))
24 changes: 24 additions & 0 deletions src/status_im/transport/message/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[status-im.transport.message.protocol :as protocol]
[status-im.transport.message.transit :as transit]
[status-im.transport.utils :as transport.utils]
[status-im.tribute-to-talk.whitelist :as whitelist]
[status-im.utils.config :as config]
[status-im.utils.fx :as fx]
[taoensso.timbre :as log]
Expand Down Expand Up @@ -180,3 +181,26 @@
:params [confirmations]
:on-success #(log/debug "successfully confirmed messages")
:on-failure #(log/error "failed to confirm messages" %)}))))

(fx/defn receive-transit-message [cofx message chat-id signature timestamp]
(let [received-message-fx {:chat-received-message/add-fx
[(assoc (into {} message)
:message-id
(or (get-in cofx [:metadata :messageId])
(transport.utils/message-id
signature
(.-payload (:js-obj cofx))))
:chat-id chat-id
:whisper-timestamp timestamp
:raw-payload-hash (ethereum/sha3
(.-payload (:js-obj cofx)))
:alias (get-in cofx [:metadata :author :alias])
:identicon (get-in cofx [:metadata :author :identicon])
:from signature
:metadata (:metadata cofx)
:js-obj (:js-obj cofx))]}]
(whitelist/filter-message cofx
received-message-fx
(:message-type message)
(get-in message [:content :tribute-transaction])
signature)))
22 changes: 0 additions & 22 deletions src/status_im/transport/message/protocol.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,6 @@
(when (pairing.utils/has-paired-installations? cofx)
(send-direct-message current-public-key nil this))
(send-with-pubkey params)))))
(receive [this chat-id signature timestamp cofx]
(let [received-message-fx {:chat-received-message/add-fx
[(assoc (into {} this)
:message-id
(or (get-in cofx [:metadata :messageId])
(transport.utils/message-id
signature
(.-payload (:js-obj cofx))))
:chat-id chat-id
:whisper-timestamp timestamp
:raw-payload-hash (ethereum/sha3
(.-payload (:js-obj cofx)))
:alias (get-in cofx [:metadata :author :alias])
:identicon (get-in cofx [:metadata :author :identicon])
:from signature
:metadata (:metadata cofx)
:js-obj (:js-obj cofx))]}]
(whitelist/filter-message cofx
received-message-fx
message-type
(get-in this [:content :tribute-transaction])
signature)))
(validate [this]
(if (spec/valid? :message/message this)
this
Expand Down
4 changes: 2 additions & 2 deletions src/status_im/ui/screens/chat/input/input.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@
:color colors/gray}]]])))

(defview reply-message [from alias message-text]
(letsubs [{:keys [username]} [:contacts/contact-name-by-identity from]
(letsubs [{:keys [ens-name]} [:contacts/contact-name-by-identity from]
current-public-key [:multiaccount/public-key]]
[react/scroll-view {:style style/reply-message-content}
[react/view {:style style/reply-message-to-container}
[vector-icons/tiny-icon :tiny-icons/tiny-reply {:container-style style/reply-icon
:width 20
:color colors/gray}]
(chat-utils/format-reply-author from alias username current-public-key style/reply-message-author)]
(chat-utils/format-reply-author from alias ens-name current-public-key style/reply-message-author)]
[react/text {:style (assoc (message-style/style-message-text false) :font-size 14) :number-of-lines 3} message-text]]))

(defview reply-message-view []
Expand Down
11 changes: 6 additions & 5 deletions src/status_im/ui/screens/chat/message/message.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
content content-type]])

(defview quoted-message [{:keys [from text]} outgoing current-public-key]
(letsubs [{:keys [username alias]} [:contacts/contact-name-by-identity from]]
(letsubs [{:keys [ens-name alias]} [:contacts/contact-name-by-identity from]]
[react/view {:style (style/quoted-message-container outgoing)}
[react/view {:style style/quoted-message-author-container}
[vector-icons/tiny-icon :tiny-icons/tiny-reply {:color (if outgoing colors/white-transparent colors/gray)}]
(chat.utils/format-reply-author from alias username current-public-key (partial style/quoted-message-author outgoing))]
(chat.utils/format-reply-author from alias ens-name current-public-key (partial style/quoted-message-author outgoing))]

[react/text {:style (style/quoted-message-text outgoing)
:number-of-lines 5}
Expand Down Expand Up @@ -196,8 +196,9 @@
(:command content))
[command-status content]))))

(defview message-author-name [alias name]
(chat.utils/format-author alias style/message-author-name name))
(defview message-author-name [from alias]
(letsubs [{:keys [ens-name]} [:contacts/contact-name-by-identity from]]
(chat.utils/format-author alias style/message-author-name ens-name)))

(defn message-body
[{:keys [last-in-group?
Expand All @@ -219,7 +220,7 @@
[react/view (style/group-message-view outgoing display-photo?)
(when display-username?
[react/touchable-opacity {:on-press #(re-frame/dispatch [:chat.ui/show-profile from])}
[message-author-name alias (:name content)]])
[message-author-name from alias]])
[react/view {:style (style/timestamp-content-wrapper outgoing)}
child]]]
[react/view (style/delivery-status outgoing)
Expand Down
3 changes: 1 addition & 2 deletions src/status_im/ui/screens/chat/styles/message/message.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,7 @@
:padding-left 12
:padding-right 16
:margin-right 12
:text-align-vertical :center
:color colors/gray})
:text-align-vertical :center})

(defn quoted-message-container [outgoing]
{:margin-bottom 6
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/ui/screens/chat/utils.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

(defn format-author [alias style name]
(let [additional-styles (style false)]
(if (ens/is-valid-eth-name? name)
(if name
[react/text {:style (merge {:color colors/blue :font-size 13 :font-weight "500"} additional-styles)}
(str "@" (or (stateofus/username name) name))]
[react/text {:style (merge {:color colors/gray :font-size 12 :font-weight "400"} additional-styles)}
Expand Down
16 changes: 8 additions & 8 deletions src/status_im/ui/screens/desktop/main/chat/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@
:height 24}}]]]))

(views/defview message-author-name [{:keys [from]}]
(views/letsubs [{:keys [username]} [:contacts/contact-name-by-identity from]]
(views/letsubs [{:keys [ens-name alias]} [:contacts/contact-name-by-identity from]]
[react/view {:flex-direction :row}
(when username
[react/text {:style styles/author} username])
(when ens-name
[react/text {:style styles/author} ens-name])
[react/text {:style styles/author-generated}
(str (when username "") (gfycat/generate-gfy from))]]))
(str (when ens-name "") alias)]]))

(views/defview member-photo [from]
(views/letsubs [current-public-key [:multiaccount/public-key]
Expand All @@ -85,14 +85,14 @@
:style styles/photo-style}]]]]]))

(views/defview quoted-message [{:keys [from text]} outgoing current-public-key]
(views/letsubs [{:keys [username alias]} [:contacts/contact-name-by-identity from]]
(views/letsubs [{:keys [ens-name alias]} [:contacts/contact-name-by-identity from]]
[react/view {:style styles/quoted-message-container}
[react/view {:style styles/quoted-message-author-container}
[vector-icons/tiny-icon :tiny-icons/tiny-reply {:style (styles/reply-icon outgoing)
:width 16
:height 16
:container-style (when outgoing {:opacity 0.4})}]
(chat-utils/format-reply-author from alias username current-public-key (partial message.style/quoted-message-author outgoing))]
(chat-utils/format-reply-author from alias ens-name current-public-key (partial message.style/quoted-message-author outgoing))]
[react/text {:style (message.style/quoted-message-text outgoing)
:number-of-lines 5}
(core-utils/truncate-str text constants/chars-collapse-threshold)]]))
Expand Down Expand Up @@ -271,10 +271,10 @@
[vector-icons/icon :main-icons/arrow-left {:style (styles/send-icon-arrow inactive?)}]]])))

(views/defview reply-message [from alias message-text]
(views/letsubs [{:keys [username]} [:contacts/contact-name-by-identity from]
(views/letsubs [{:keys [ens-name]} [:contacts/contact-name-by-identity from]
current-public-key [:multiaccount/public-key]]
[react/view {:style styles/reply-content-container}
(chat-utils/format-reply-author from alias username current-public-key styles/reply-content-author)
(chat-utils/format-reply-author from alias ens-name current-public-key styles/reply-content-author)
[react/text {:style styles/reply-content-message} message-text]]))

(views/defview reply-member-photo [from]
Expand Down
1 change: 1 addition & 0 deletions src/status_im/utils/fx.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
:filters/load-filters
:pairing/set-installation-metadata
:status-im.data-store.messages/save-message
:status-im.ens.core/verify-names
:shh/send-direct-message
:shh/remove-filter
:shh/generate-sym-key-from-password
Expand Down
6 changes: 3 additions & 3 deletions status-go-version.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"_comment": "DO NOT EDIT THIS FILE BY HAND. USE 'scripts/update-status-go.sh <tag>' instead",
"owner": "status-im",
"repo": "status-go",
"version": "v0.34.0-beta.0",
"commit-sha1": "94228bce2ee6a7a5f62917e28247a22c37b6699b",
"src-sha256": "0f62yh94vn6k4gqa50r3gxzscqabmgc047sng291g5wp6d755fmr"
"version": "dd882389a4e257e934370980c56d67287ca62ebf",
"commit-sha1": "dd882389a4e257e934370980c56d67287ca62ebf",
"src-sha256": "1074zsbfjxkilv9g3aijr7xbjyqzlmy9f64gnp1mnja17bxwdv06"
}
1 change: 1 addition & 0 deletions test/cljs/status_im/test/contacts/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
current-multiaccount)
[{:name "generated"
:identicon "generated"
:alias "generated"
:admin? true
:address "71adb0644e2b590e37dafdfea8bd58f0c7668c7f"
:public-key "0x04fcf40c526b09ff9fb22f4a5dbd08490ef9b64af700870f8a0ba2133f4251d5607ed83cd9047b8c2796576bc83fa0de23a13a4dced07654b8ff137fe744047917"
Expand Down
Loading

0 comments on commit cf2b2ef

Please sign in to comment.