diff --git a/images/contacts/auction-house.png b/images/contacts/auction-house.png new file mode 100644 index 0000000000..59eebce404 Binary files /dev/null and b/images/contacts/auction-house.png differ diff --git a/resources/dapp.js b/resources/dapp.js new file mode 100644 index 0000000000..994e2e25ba --- /dev/null +++ b/resources/dapp.js @@ -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"); diff --git a/resources/default_contacts.json b/resources/default_contacts.json new file mode 100644 index 0000000000..5d00c85c85 --- /dev/null +++ b/resources/default_contacts.json @@ -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"} +] diff --git a/src/status_im/chat/handlers.cljs b/src/status_im/chat/handlers.cljs index de626315fc..d109b939a4 100644 --- a/src/status_im/chat/handlers.cljs +++ b/src/status_im/chat/handlers.cljs @@ -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 diff --git a/src/status_im/chat/handlers/wallet_chat.cljs b/src/status_im/chat/handlers/wallet_chat.cljs deleted file mode 100644 index 5df90b2807..0000000000 --- a/src/status_im/chat/handlers/wallet_chat.cljs +++ /dev/null @@ -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]]))))) - diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index 0fd5e55b7c..960f189c94 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -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}) diff --git a/src/status_im/commands/handlers/jail.cljs b/src/status_im/commands/handlers/jail.cljs index ee533bb21b..3dcbf5ecd8 100644 --- a/src/status_im/commands/handlers/jail.cljs +++ b/src/status_im/commands/handlers/jail.cljs @@ -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]]] diff --git a/src/status_im/commands/handlers/loading.cljs b/src/status_im/commands/handlers/loading.cljs index da4c62afa1..fd8a85d2d8 100644 --- a/src/status_im/commands/handlers/loading.cljs +++ b/src/status_im/commands/handlers/loading.cljs @@ -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}]]))))))) diff --git a/src/status_im/components/chat_icon/screen.cljs b/src/status_im/components/chat_icon/screen.cljs index fd45fac910..8e4797da40 100644 --- a/src/status_im/components/chat_icon/screen.cljs +++ b/src/status_im/components/chat_icon/screen.cljs @@ -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} - :style (merge st/default-image-style - (st/image-style size))}]) + (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))}])) (defn dapp-badge [styles] [view (:online-view-wrapper styles) diff --git a/src/status_im/contacts/default_contacts.cljs b/src/status_im/contacts/default_contacts.cljs new file mode 100644 index 0000000000..dc6e976f9d --- /dev/null +++ b/src/status_im/contacts/default_contacts.cljs @@ -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"} + ]) diff --git a/src/status_im/contacts/handlers.cljs b/src/status_im/contacts/handlers.cljs index 718d8dfe0a..f91038e9ba 100644 --- a/src/status_im/contacts/handlers.cljs +++ b/src/status_im/contacts/handlers.cljs @@ -274,4 +274,3 @@ 0 (dispatch [:remove-contact contact]) :default)) :cancel-text (label :t/cancel)})))) - diff --git a/src/status_im/data_store/realm/schemas/account/v1/chat.cljs b/src/status_im/data_store/realm/schemas/account/v1/chat.cljs index 15468bd5e9..6223b65c64 100644 --- a/src/status_im/data_store/realm/schemas/account/v1/chat.cljs +++ b/src/status_im/data_store/realm/schemas/account/v1/chat.cljs @@ -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 diff --git a/src/status_im/data_store/realm/schemas/account/v1/contact.cljs b/src/status_im/data_store/realm/schemas/account/v1/contact.cljs index 3f8e176f88..d49edcbf74 100644 --- a/src/status_im/data_store/realm/schemas/account/v1/contact.cljs +++ b/src/status_im/data_store/realm/schemas/account/v1/contact.cljs @@ -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")) diff --git a/src/status_im/handlers.cljs b/src/status_im/handlers.cljs index 3d05f1a7fb..ad13fa24c4 100644 --- a/src/status_im/handlers.cljs +++ b/src/status_im/handlers.cljs @@ -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!])))) diff --git a/src/status_im/resources.cljs b/src/status_im/resources.cljs index 4b49c06d0e..c7e574dd4e 100644 --- a/src/status_im/resources.cljs +++ b/src/status_im/resources.cljs @@ -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")}) diff --git a/src/status_im/utils/js_resources.cljs b/src/status_im/utils/js_resources.cljs index 7e380e730b..ec162d86ef 100644 --- a/src/status_im/utils/js_resources.cljs +++ b/src/status_im/utils/js_resources.cljs @@ -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")