Skip to content

Commit ae976e2

Browse files
committed
Added extensions loading panel
Signed-off-by: Julien Eluard <[email protected]>
1 parent f82285b commit ae976e2

File tree

36 files changed

+548
-87
lines changed

36 files changed

+548
-87
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ DEBUG_WEBVIEW=1
1414
INSTABUG_SURVEYS=1
1515
GROUP_CHATS_ENABLED=0
1616
CACHED_WEBVIEWS_ENABLED=1
17+
EXTENSIONS=1

.env.e2e

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ POW_TIME=1
99
DEFAULT_NETWORK=testnet_rpc
1010
INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
1111
DEBUG_WEBVIEW=1
12-
GROUP_CHATS_ENABLED=1
12+
GROUP_CHATS_ENABLED=1
13+
EXTENSIONS=0

.env.jenkins

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ DEBUG_WEBVIEW=1
1313
GROUP_CHATS_ENABLED=0
1414
MAINNET_WARNING_ENABLED=1
1515
CACHED_WEBVIEWS_ENABLED=1
16+
EXTENSIONS=0

.env.nightly

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
1212
DEBUG_WEBVIEW=1
1313
GROUP_CHATS_ENABLED=0
1414
MAINNET_WARNING_ENABLED=1
15+
EXTENSIONS=1

.env.nightly.staging.fleet

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ DEBUG_WEBVIEW=1
1313
INSTABUG_SURVEYS=1
1414
GROUP_CHATS_ENABLED=0
1515
MAINNET_WARNING_ENABLED=1
16+
EXTENSIONS=0

.env.prod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ TESTFAIRY_TOKEN=969f6c921cb435cea1d41d1ea3f5b247d6026d55
1313
INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
1414
DEBUG_WEBVIEW=0
1515
GROUP_CHATS_ENABLED=0
16-
MAINNET_WARNING_ENABLED=1
16+
MAINNET_WARNING_ENABLED=1
17+
EXTENSIONS=0

deps.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
com.andrewmcveigh/cljs-time {:mvn/version "0.5.2"}
1111
com.taoensso/timbre {:mvn/version "4.10.0"}
1212
hickory {:mvn/version "0.7.1"}
13-
com.cognitect/transit-cljs {:mvn/version "0.8.248"}}
13+
com.cognitect/transit-cljs {:mvn/version "0.8.248"}
14+
status-im/pluto {:mvn/version "iteration-2-SNAPSHOT"}}
1415

1516
:aliases
1617
{:dev {:extra-deps

project.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
[com.andrewmcveigh/cljs-time "0.5.2"]
1111
[com.taoensso/timbre "4.10.0"]
1212
[hickory "0.7.1"]
13-
[com.cognitect/transit-cljs "0.8.248"]]
13+
[com.cognitect/transit-cljs "0.8.248"]
14+
[status-im/pluto "iteration-2-SNAPSHOT"]]
1415
:plugins [[lein-cljsbuild "1.1.7"]
1516
[lein-re-frisk "0.5.8"]
1617
[lein-cljfmt "0.5.7"]

src/status_im/chat/commands/core.cljs

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
(ns status-im.chat.commands.core
2-
(:require [clojure.set :as set]
2+
(:require [re-frame.core :as re-frame]
3+
[clojure.set :as set]
34
[clojure.string :as string]
5+
[pluto.host :as host]
46
[status-im.constants :as constants]
57
[status-im.chat.constants :as chat-constants]
68
[status-im.chat.commands.protocol :as protocol]
79
[status-im.chat.commands.impl.transactions :as transactions]
810
[status-im.chat.models :as chat-model]
911
[status-im.chat.models.input :as input-model]
1012
[status-im.chat.models.message :as message-model]
13+
[status-im.utils.handlers :as handlers]
1114
[status-im.utils.handlers-macro :as handlers-macro]))
1215

1316
(def register
@@ -80,7 +83,7 @@
8083
(defn index-commands
8184
"Takes collecton of things implementing the command protocol, and
8285
correctly indexes them by their composite ids and access scopes."
83-
[commands {:keys [db]}]
86+
[commands]
8487
(let [id->command (reduce (fn [acc command]
8588
(assoc acc (command-id command)
8689
{:type command
@@ -100,9 +103,66 @@
100103
access-scopes)))
101104
{}
102105
id->command)]
103-
{:db (assoc db
104-
:id->command id->command
105-
:access-scope->command-id access-scope->command-id)}))
106+
{:id->command id->command
107+
:access-scope->command-id access-scope->command-id}))
108+
109+
(defn load-commands
110+
"Takes collection of things implementing the command protocol and db,
111+
correctly indexes them and adds them to db in a way that preserves existing commands"
112+
[commands {:keys [db]}]
113+
(let [{:keys [id->command access-scope->command-id]} (index-commands commands)]
114+
{:db (-> db
115+
(update :id->command merge id->command)
116+
(update :access-scope->command-id #(merge-with (fnil into #{}) % access-scope->command-id)))}))
117+
118+
(defn remove-command
119+
"Remove command form db, correctly updating all indexes"
120+
[command {:keys [db]}]
121+
(let [id (command-id command)]
122+
{:db (-> db
123+
(update :id->command dissoc id)
124+
(update :access-scope->command-id (fn [access-scope->command-id]
125+
(reduce (fn [acc [scope command-ids-set]]
126+
(if (command-ids-set id)
127+
(if (= 1 (count command-ids-set))
128+
acc
129+
(assoc acc scope (disj command-ids-set id)))
130+
(assoc acc scope command-ids-set)))
131+
{}
132+
access-scope->command-id))))}))
133+
134+
(def command-hook
135+
"Hook for extensions"
136+
(reify host/AppHook
137+
(id [_] :commands)
138+
(properties [_] {:scope #{:personal-chats :public-chats}
139+
:description :string
140+
:short-preview :view
141+
:preview :view
142+
:parameters [{:id :keyword
143+
:type {:one-of #{:text :phone :password :number}}
144+
:placeholder :string
145+
:suggestions? :component}]})
146+
(hook-in [_ id {:keys [description scope parameters preview short-preview]} cofx]
147+
(let [new-command (reify protocol/Command
148+
(id [_] (name id))
149+
(scope [_] scope)
150+
(description [_] description)
151+
(parameters [_] parameters)
152+
(validate [_ _ _])
153+
(on-send [_ _ _])
154+
(on-receive [_ _ _])
155+
(short-preview [_ props] (short-preview props))
156+
(preview [_ props] (preview props)))]
157+
(load-commands [new-command] cofx)))
158+
(unhook [_ id {:keys [scope]} {:keys [db] :as cofx}]
159+
(remove-command (get-in db [:id->command [(name id) scope] :type]) cofx))))
160+
161+
(handlers/register-handler-fx
162+
:load-commands
163+
[re-frame/trim-v]
164+
(fn [cofx [commands]]
165+
(load-commands commands cofx)))
106166

107167
(defn chat-commands
108168
"Takes `id->command`, `access-scope->command-id` and `chat` parameters and returns

src/status_im/chat/commands/impl/transactions.cljs

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
[status-im.ui.components.chat-preview :as chat-preview]
1313
[status-im.ui.components.list.views :as list]
1414
[status-im.ui.components.animation :as animation]
15+
[status-im.ui.components.svgimage :as svgimage]
1516
[status-im.i18n :as i18n]
1617
[status-im.constants :as constants]
1718
[status-im.utils.ethereum.core :as ethereum]
@@ -40,21 +41,40 @@
4041
#_[react/text {:style transactions-styles/asset-balance}
4142
(str (money/internal->formatted amount symbol decimals))]]]))
4243

44+
(defn- render-nft-asset [selected-event-creator]
45+
(fn [{:keys [name symbol amount] :as asset}]
46+
[react/touchable-highlight
47+
{:on-press #(re-frame/dispatch (selected-event-creator (clojure.core/name symbol)))}
48+
[react/view transactions-styles/asset-container
49+
[react/view transactions-styles/asset-main
50+
[react/image {:source (-> asset :icon :source)
51+
:style transactions-styles/asset-icon}]
52+
[react/text {:style transactions-styles/asset-symbol} name]]
53+
[react/text {:style transactions-styles/nft-asset-amount} (money/to-fixed amount)]]]))
54+
4355
(def assets-separator [react/view transactions-styles/asset-separator])
4456

45-
(defview choose-asset [selected-event-creator]
57+
(defview choose-asset [nft? selected-event-creator]
4658
(letsubs [assets [:wallet/visible-assets-with-amount]]
4759
[react/view
48-
[list/flat-list {:data (filter #(not (:nft? %)) assets)
60+
[list/flat-list {:data (filter #(if nft?
61+
(:nft? %)
62+
(not (:nft? %)))
63+
assets)
4964
:key-fn (comp name :symbol)
50-
:render-fn (render-asset selected-event-creator)
65+
:render-fn (if nft?
66+
(render-nft-asset selected-event-creator)
67+
(render-asset selected-event-creator))
5168
:enableEmptySections true
5269
:separator assets-separator
5370
:keyboardShouldPersistTaps :always
5471
:bounces false}]]))
5572

5673
(defn choose-asset-suggestion [selected-event-creator]
57-
[choose-asset selected-event-creator])
74+
[choose-asset false selected-event-creator])
75+
76+
(defn choose-nft-asset-suggestion [selected-event-creator]
77+
[choose-asset true selected-event-creator])
5878

5979
(defn personal-send-request-short-preview
6080
[label-key {:keys [content]}]
@@ -77,6 +97,32 @@
7797
:type :number
7898
:placeholder "Amount"}])
7999

100+
(defview choose-nft-token [selected-event-creator]
101+
(letsubs [{:keys [input-params]} [:selected-chat-command]
102+
collectibles [:collectibles]]
103+
(let [collectible-tokens (get collectibles (keyword (:symbol input-params)))]
104+
[react/view {:flex-direction :row
105+
:align-items :center
106+
:padding-vertical 11}
107+
(map
108+
(fn [[id {:keys [name image_url]}]]
109+
[react/touchable-highlight
110+
{:key id
111+
:on-press #(re-frame/dispatch (selected-event-creator (str id)))}
112+
[react/view {:flex-direction :column
113+
:align-items :center
114+
:margin-left 10
115+
:border-radius 2
116+
:border-width 1
117+
:border-color colors/gray}
118+
[svgimage/svgimage {:style transactions-styles/nft-token-icon
119+
:source {:uri image_url}}]
120+
[react/text {} name]]])
121+
collectible-tokens)])))
122+
123+
(defn choose-nft-token-suggestion [selected-event-creator]
124+
[choose-nft-token selected-event-creator])
125+
80126
;;TODO(goranjovic): currently we only allow tokens which are enabled in Manage assets here
81127
;; because balances are only fetched for them. Revisit this decision with regard to battery/network consequences
82128
;; if we were to update all balances.

0 commit comments

Comments
 (0)