Default contacts (#580)
This commit is contained in:
parent
3936c05ecd
commit
0e190c624b
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
|
@ -0,0 +1,24 @@
|
|||
I18n.translations = {
|
||||
en: {
|
||||
browse_title: 'Browser',
|
||||
browse_description: 'Launch the browser'
|
||||
}
|
||||
};
|
||||
|
||||
status.command({
|
||||
name: "browse",
|
||||
title: I18n.t('browse_title'),
|
||||
description: I18n.t('browse_description'),
|
||||
color: "#ffa500",
|
||||
fullscreen: true,
|
||||
suggestionsTrigger: 'on-send',
|
||||
params: [{
|
||||
name: "url",
|
||||
suggestions: function(params, context) {
|
||||
return {webViewUrl: "dapp-url"};
|
||||
},
|
||||
type: status.types.TEXT
|
||||
}]
|
||||
});
|
||||
|
||||
status.autorun("browse");
|
|
@ -0,0 +1,13 @@
|
|||
[
|
||||
{"id": "wallet",
|
||||
"name": "Wallet",
|
||||
"photo-path": "icon_wallet_avatar",
|
||||
"add-chat?": true,
|
||||
"dapp?": true},
|
||||
|
||||
{"id": "dapp-auction-house",
|
||||
"name": "Auction House",
|
||||
"photo-path": "contacts://auction-house",
|
||||
"dapp?": true,
|
||||
"dapp-url": "http://auctionhouse.dappbench.com"}
|
||||
]
|
|
@ -37,7 +37,6 @@
|
|||
status-im.chat.handlers.faucet
|
||||
[cljs.core.async :as a]
|
||||
status-im.chat.handlers.webview-bridge
|
||||
status-im.chat.handlers.wallet-chat
|
||||
status-im.chat.handlers.console
|
||||
[taoensso.timbre :as log]
|
||||
[tailrecursion.priority-map :refer [priority-map-by]]))
|
||||
|
@ -343,7 +342,7 @@
|
|||
;TODO: check if its new account / signup status / create console chat
|
||||
(register-handler :initialize-chats
|
||||
[(after #(dispatch [:load-unviewed-messages!]))
|
||||
(after #(dispatch [:init-wallet-chat]))]
|
||||
(after #(dispatch [:load-default-contacts!]))]
|
||||
((enrich initialize-chats) load-chats!))
|
||||
|
||||
(defmethod nav/preload-data! :chat
|
||||
|
@ -399,9 +398,7 @@
|
|||
:group-chat false
|
||||
:is-active true
|
||||
:timestamp (.getTime (js/Date.))
|
||||
:contacts [{:identity chat-id}]
|
||||
:dapp-url nil
|
||||
:dapp-hash nil}
|
||||
:contacts [{:identity chat-id}]}
|
||||
chat)))
|
||||
|
||||
(defn add-new-chat
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
(ns status-im.chat.handlers.wallet-chat
|
||||
(:require [re-frame.core :refer [after enrich path dispatch]]
|
||||
[status-im.utils.handlers :refer [register-handler] :as u]
|
||||
[status-im.constants :refer [wallet-chat-id]]
|
||||
[clojure.string :as s]))
|
||||
|
||||
(def dapp-contact
|
||||
{:whisper-identity wallet-chat-id
|
||||
:name (s/capitalize wallet-chat-id)
|
||||
:dapp? true
|
||||
:photo-path :icon_wallet_avatar})
|
||||
|
||||
|
||||
(register-handler :init-wallet-chat
|
||||
(u/side-effect!
|
||||
(fn [{:keys [chats]}]
|
||||
(when-not (chats wallet-chat-id)
|
||||
(dispatch [:add-chat
|
||||
wallet-chat-id
|
||||
{:name "Wallet"
|
||||
:dapp-url "http://192.168.1.125:3450"}])
|
||||
(dispatch [:add-contacts [dapp-contact]])))))
|
||||
|
|
@ -173,9 +173,6 @@
|
|||
(def console-chat
|
||||
{:chat-id console-chat-id
|
||||
:name (s/capitalize console-chat-id)
|
||||
; todo remove/change dapp config fot console
|
||||
:dapp-url "http://localhost:8185/resources"
|
||||
:dapp-hash 858845357
|
||||
:color default-chat-color
|
||||
:group-chat false
|
||||
:is-active true
|
||||
|
@ -189,4 +186,7 @@
|
|||
{:whisper-identity console-chat-id
|
||||
:name (s/capitalize console-chat-id)
|
||||
:photo-path console-chat-id
|
||||
:dapp? true})
|
||||
:dapp? true
|
||||
; todo remove/change dapp config fot console
|
||||
:dapp-url "http://localhost:8185/resources"
|
||||
:dapp-hash 858845357})
|
||||
|
|
|
@ -42,13 +42,17 @@
|
|||
:else nil)))
|
||||
|
||||
(defn suggestions-handler!
|
||||
[db [{:keys [chat-id]} {:keys [result]}]]
|
||||
[{:keys [contacts] :as db} [{:keys [chat-id]} {:keys [result]}]]
|
||||
(let [{:keys [markup webViewUrl]} (:returned result)
|
||||
hiccup (generate-hiccup markup)]
|
||||
{:keys [dapp? dapp-url]} (get contacts chat-id)
|
||||
hiccup (generate-hiccup markup)
|
||||
web-view-url (if (and (= webViewUrl "dapp-url") dapp? dapp-url)
|
||||
dapp-url
|
||||
webViewUrl)]
|
||||
(-> db
|
||||
(assoc-in [:suggestions chat-id] hiccup)
|
||||
(assoc-in [:web-view-url chat-id] webViewUrl)
|
||||
(assoc-in [:has-suggestions? chat-id] (or hiccup webViewUrl)))))
|
||||
(assoc-in [:web-view-url chat-id] web-view-url)
|
||||
(assoc-in [:has-suggestions? chat-id] (or hiccup web-view-url)))))
|
||||
|
||||
(defn suggestions-events-handler!
|
||||
[{:keys [current-chat-id] :as db} [[n data]]]
|
||||
|
|
|
@ -16,26 +16,32 @@
|
|||
(def commands-js "commands.js")
|
||||
|
||||
(defn load-commands!
|
||||
[{:keys [current-chat-id]} [identity]]
|
||||
(dispatch [::fetch-commands! (or identity current-chat-id)])
|
||||
[{:keys [current-chat-id contacts]} [identity]]
|
||||
(let [identity (or identity current-chat-id)
|
||||
contact (or (get contacts identity)
|
||||
{:whisper-identity identity})]
|
||||
(dispatch [::fetch-commands! contact]))
|
||||
;; todo uncomment
|
||||
#_(if-let [{:keys [file]} (commands/get-by-chat-id identity)]
|
||||
(dispatch [::parse-commands! identity file])
|
||||
(dispatch [::fetch-commands! identity])))
|
||||
|
||||
(defn fetch-commands!
|
||||
[db [identity]]
|
||||
[db [{:keys [whisper-identity dapp? dapp-url]}]]
|
||||
(when true
|
||||
;-let [url (get-in db [:chats identity :dapp-url])]
|
||||
(cond
|
||||
(= console-chat-id identity)
|
||||
(dispatch [::validate-hash identity js-res/console-js])
|
||||
(= console-chat-id whisper-identity)
|
||||
(dispatch [::validate-hash whisper-identity js-res/console-js])
|
||||
|
||||
(= wallet-chat-id identity)
|
||||
(dispatch [::validate-hash identity js-res/wallet-js])
|
||||
(= wallet-chat-id whisper-identity)
|
||||
(dispatch [::validate-hash whisper-identity js-res/wallet-js])
|
||||
|
||||
(and dapp? dapp-url)
|
||||
(dispatch [::validate-hash whisper-identity js-res/dapp-js])
|
||||
|
||||
:else
|
||||
(dispatch [::validate-hash identity js-res/commands-js])
|
||||
(dispatch [::validate-hash whisper-identity js-res/commands-js])
|
||||
#_(http-get (s/join "/" [url commands-js])
|
||||
|
||||
#(dispatch [::validate-hash identity %])
|
||||
|
@ -49,7 +55,7 @@
|
|||
|
||||
(defn get-hash-by-identity
|
||||
[db identity]
|
||||
(get-in db [:chats identity :dapp-hash]))
|
||||
(get-in db [:contacts identity :dapp-hash]))
|
||||
|
||||
(defn get-hash-by-file
|
||||
[file]
|
||||
|
@ -157,3 +163,20 @@
|
|||
(reg-handler ::clear-commands-callbacks
|
||||
(fn [db [chat-id]]
|
||||
(assoc-in db [::commands-callbacks chat-id] nil)))
|
||||
|
||||
(reg-handler :load-default-contacts!
|
||||
(u/side-effect!
|
||||
(fn [{:keys [chats]}]
|
||||
(let [contacts (json->clj js-res/default-contacts-js)]
|
||||
(doseq [{:keys [id name photo-path public-key add-chat?
|
||||
dapp? dapp-url dapp-hash] :as contact} contacts]
|
||||
(when-not (chats id)
|
||||
(when add-chat?
|
||||
(dispatch [:add-chat id {:name name}]))
|
||||
(dispatch [:add-contacts [{:whisper-identity id
|
||||
:name name
|
||||
:photo-path photo-path
|
||||
:public-key public-key
|
||||
:dapp? dapp?
|
||||
:dapp-url dapp-url
|
||||
:dapp-hash dapp-hash}]])))))))
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
text
|
||||
image
|
||||
icon]]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.components.icons.custom-icons :refer [oct-icon]]
|
||||
[status-im.components.chat-icon.styles :as st]
|
||||
[status-im.components.styles :refer [default-chat-color]]
|
||||
[status-im.resources :as resources]
|
||||
[status-im.constants :refer [console-chat-id]]
|
||||
[clojure.string :as s]))
|
||||
|
||||
|
@ -17,9 +19,14 @@
|
|||
(first name)]])
|
||||
|
||||
(defn chat-icon [photo-path {:keys [size]}]
|
||||
[image {:source {:uri photo-path}
|
||||
(let [photo (if (s/starts-with? photo-path "contacts://")
|
||||
(->> (s/replace photo-path #"contacts://" "")
|
||||
(keyword)
|
||||
(get resources/contacts))
|
||||
{:uri photo-path})]
|
||||
[image {:source photo
|
||||
:style (merge st/default-image-style
|
||||
(st/image-style size))}])
|
||||
(st/image-style size))}]))
|
||||
|
||||
(defn dapp-badge [styles]
|
||||
[view (:online-view-wrapper styles)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
(ns status-im.contacts.default-contacts
|
||||
(:require [status-im.constants :refer [wallet-chat-id]]
|
||||
[clojure.string :as s]))
|
||||
|
||||
(def contacts
|
||||
[{:whisper-identity wallet-chat-id
|
||||
:name (s/capitalize wallet-chat-id)
|
||||
:photo-path :icon_wallet_avatar
|
||||
:dapp? true
|
||||
:add-chat? true}
|
||||
|
||||
{:whisper-identity "dapp-auction"
|
||||
:name "Auction House"
|
||||
:photo-path "http://auctionhouse.dappbench.com/images/auctionhouse.png"
|
||||
:dapp? true
|
||||
:dapp-url "http://auctionhouse.dappbench.com"}
|
||||
])
|
|
@ -274,4 +274,3 @@
|
|||
0 (dispatch [:remove-contact contact])
|
||||
:default))
|
||||
:cancel-text (label :t/cancel)}))))
|
||||
|
||||
|
|
|
@ -16,10 +16,6 @@
|
|||
:timestamp :int
|
||||
:contacts {:type :list
|
||||
:objectType :chat-contact}
|
||||
:dapp-url {:type :string
|
||||
:optional true}
|
||||
:dapp-hash {:type :int
|
||||
:optional true}
|
||||
:removed-at {:type :int
|
||||
:optional true}
|
||||
:removed-from-at {:type :int
|
||||
|
|
|
@ -16,7 +16,11 @@
|
|||
:private-key {:type :string
|
||||
:optional true}
|
||||
:dapp? {:type :bool
|
||||
:default false}}})
|
||||
:default false}
|
||||
:dapp-url {:type :string
|
||||
:optional true}
|
||||
:dapp-hash {:type :int
|
||||
:optional true}}})
|
||||
|
||||
(defn migration [old-realm new-realm]
|
||||
(log/debug "migrating contact schema"))
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
(dispatch [:initialize-db])
|
||||
(dispatch [:load-accounts])
|
||||
(dispatch [:init-console-chat])
|
||||
(dispatch [:init-wallet-chat])
|
||||
(dispatch [:load-default-contacts!])
|
||||
(dispatch [:load-commands! console-chat-id])
|
||||
(dispatch [:load-commands!]))))
|
||||
|
||||
|
|
|
@ -17,3 +17,6 @@
|
|||
(def smile (js/require "./images/smile.png"))
|
||||
(def trash-icon (js/require "./images/trash.png"))
|
||||
(def v (js/require "./images/v.png"))
|
||||
|
||||
(def contacts
|
||||
{:auction-house (js/require "./images/contacts/auction-house.png")})
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
(ns ^:figwheel-always status-im.utils.js-resources
|
||||
(:require-macros [status-im.utils.slurp :refer [slurp]]))
|
||||
|
||||
(def default-contacts-js (slurp "resources/default_contacts.json"))
|
||||
|
||||
(def commands-js (slurp "resources/commands.js"))
|
||||
(def console-js (slurp "resources/console.js"))
|
||||
(def status-js (slurp "resources/status.js"))
|
||||
(def wallet-js (str commands-js (slurp "resources/wallet.js")))
|
||||
(def dapp-js (str (slurp "resources/dapp.js")))
|
||||
|
||||
(def webview-js (slurp "resources/webview.js"))
|
||||
(def web3 (str "if (typeof Web3 == 'undefined') {"
|
||||
(slurp "resources/web3.0_16_0.min.js")
|
||||
|
|
Loading…
Reference in New Issue