Moved to newer pluto

Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
Julien Eluard 2018-09-25 17:10:52 +02:00
parent 02cb5dc8d4
commit 00ed5bc883
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
17 changed files with 86 additions and 107 deletions

View File

@ -10,5 +10,5 @@ DEFAULT_NETWORK=testnet_rpc
INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=1
GROUP_CHATS_ENABLED=0
EXTENSIONS=0
EXTENSIONS=1
PFS_ENCRYPTION_ENABLED=0

View File

@ -14,5 +14,5 @@ DEBUG_WEBVIEW=1
GROUP_CHATS_ENABLED=1
MAINNET_WARNING_ENABLED=1
CACHED_WEBVIEWS_ENABLED=1
EXTENSIONS=0
EXTENSIONS=1
PFS_ENCRYPTION_ENABLED=0

View File

@ -13,5 +13,5 @@ DEBUG_WEBVIEW=1
INSTABUG_SURVEYS=1
GROUP_CHATS_ENABLED=0
MAINNET_WARNING_ENABLED=1
EXTENSIONS=0
EXTENSIONS=1
PFS_ENCRYPTION_ENABLED=0

View File

@ -14,5 +14,5 @@ INSTABUG_TOKEN=758630ed52864cbad9c5eeeac596c60c
DEBUG_WEBVIEW=0
GROUP_CHATS_ENABLED=0
MAINNET_WARNING_ENABLED=1
EXTENSIONS=0
EXTENSIONS=1
PFS_ENCRYPTION_ENABLED=0

View File

@ -11,7 +11,7 @@
com.taoensso/timbre {:mvn/version "4.10.0"}
hickory {:mvn/version "0.7.1"}
com.cognitect/transit-cljs {:mvn/version "0.8.248"}
status-im/pluto {:mvn/version "iteration-2-SNAPSHOT"}
status-im/pluto {:mvn/version "iteration-3-SNAPSHOT"}
mvxcvi/alphabase {:mvn/version "1.0.0"}
rasom/cljs-react-navigation {:mvn/version "0.1.4"}}

View File

@ -11,7 +11,7 @@
[com.taoensso/timbre "4.10.0"]
[hickory "0.7.1"]
[com.cognitect/transit-cljs "0.8.248"]
[status-im/pluto "iteration-2-SNAPSHOT"]
[status-im/pluto "iteration-3-SNAPSHOT"]
[mvxcvi/alphabase "1.0.0"]
[rasom/cljs-react-navigation "0.1.4"]]
:plugins [[lein-cljsbuild "1.1.7"]

View File

@ -1,7 +1,7 @@
(ns status-im.chat.commands.core
(:require [re-frame.core :as re-frame]
[clojure.set :as set]
[pluto.host :as host]
[pluto.reader.hooks :as hooks]
[status-im.constants :as constants]
[status-im.chat.constants :as chat-constants]
[status-im.chat.commands.protocol :as protocol]
@ -129,30 +129,30 @@
(def command-hook
"Hook for extensions"
(reify host/AppHook
(id [_] :commands)
(properties [_] {:scope #{:personal-chats :public-chats}
:description :string
:short-preview :view
:preview :view
:parameters [{:id :keyword
:type {:one-of #{:text :phone :password :number}}
:placeholder :string
:suggestions? :component}]})
(hook-in [_ id {:keys [description scope parameters preview short-preview]} cofx]
(let [new-command (reify protocol/Command
(id [_] (name id))
(scope [_] scope)
(description [_] description)
(parameters [_] parameters)
(validate [_ _ _])
(on-send [_ _ _])
(on-receive [_ _ _])
(short-preview [_ props] (short-preview props))
(preview [_ props] (preview props)))]
(load-commands [new-command] cofx)))
(unhook [_ id {:keys [scope]} {:keys [db] :as cofx}]
(remove-command (get-in db [:id->command [(name id) scope] :type]) cofx))))
{:properties
{:scope #{:personal-chats :public-chats}
:short-preview :view
:preview :view
:parameters [{:id :keyword
:type {:one-of #{:text :phone :password :number}}
:placeholder :string
:suggestions :view}]}
:hook
(reify hooks/Hook
(hook-in [_ id {:keys [description scope parameters preview short-preview]} cofx]
(let [new-command (reify protocol/Command
(id [_] (name id))
(scope [_] scope)
(description [_] description)
(parameters [_] parameters)
(validate [_ _ _])
(on-send [_ _ _])
(on-receive [_ _ _])
(short-preview [_ props] (short-preview props))
(preview [_ props] (preview props)))]
(load-commands cofx [new-command])))
(unhook [_ id {:keys [scope]} {:keys [db] :as cofx}]
(remove-command (get-in db [:id->command [(name id) scope] :type]) cofx)))})
(handlers/register-handler-fx
:load-commands

View File

@ -4,5 +4,5 @@
(re-frame/reg-sub
:get-collectible-token
:<- [:collectibles]
(fn [collectibles [_ nft-symbol token-id]]
(get-in collectibles [(keyword nft-symbol) (js/parseInt token-id)])))
(fn [collectibles [_ {:keys [symbol token]}]]
(get-in collectibles [(keyword symbol) (js/parseInt token)])))

View File

@ -21,7 +21,7 @@
"Ordered sequence of command parameter templates, where each parameter
is defined as map consisting of mandatory `:id`, `:title` and `:type` keys,
and optional `:suggestions` field.
When used, `:suggestions` containes reference to any generic helper component
When used, `:suggestions` contains reference to any generic helper component
rendering suggestions for the argument (input code will handle when and where
to render it)")
(validate [this parameters cofx]

View File

@ -1,7 +1,45 @@
(ns status-im.extensions.core
(:require [clojure.string :as string]))
(:require [clojure.string :as string]
[pluto.reader :as reader]
[pluto.registry :as registry]
[pluto.storages :as storages]
[status-im.chat.commands.core :as commands]
[status-im.chat.commands.impl.transactions :as transactions]
[status-im.ui.components.react :as react]))
(defn url->storage-details [s]
(def components
{'view {:value react/view}
'text {:value react/text}
'nft-token {:value transactions/nft-token}
'send-status {:value transactions/send-status}
'asset-selector {:value transactions/choose-nft-asset-suggestion}
'token-selector {:value transactions/choose-nft-token-suggestion}})
(def app-hooks #{commands/command-hook})
(def capacities
(reduce (fn [capacities hook]
(assoc-in capacities [:hooks :commands] hook))
{:components components
:queries {'get-collectible-token {:value :get-collectible-token}}
:events {}}
app-hooks))
(defn read-extension [o]
(-> o :value first :content reader/read))
(defn parse [{:keys [data] :as m}]
(try
(let [{:keys [errors] :as extension-data} (reader/parse {:capacities capacities} data)]
(when errors
(println "Failed to parse status extensions" errors))
extension-data)
(catch :default e (println "EXC" e))))
(defn url->uri [s]
(when s
(let [[_ type id] (string/split s #".*[:/]([a-z]*)@(.*)")]
[(keyword type) id])))
(string/replace s "https://get.status.im/extension/" "")))
(defn load-from [url f]
(when-let [uri (url->uri url)]
(storages/fetch uri f)))

View File

@ -1,52 +0,0 @@
(ns status-im.extensions.registry
(:require [pluto.reader :as reader]
[pluto.registry :as registry]
[pluto.host :as host]
[pluto.storage :as storage]
[pluto.storage.gist :as gist]
[status-im.extensions.core :as extension]
[status-im.chat.commands.core :as commands]
[status-im.chat.commands.impl.transactions :as transactions]
[status-im.ui.components.react :as react]))
(def components
{'view react/view
'text react/text
'nft-token transactions/nft-token
'send-status transactions/send-status
'asset-selector transactions/choose-nft-asset-suggestion
'token-selector transactions/choose-nft-token-suggestion})
(def app-hooks #{commands/command-hook})
(def capacities
(reduce (fn [capacities hook]
(assoc-in capacities [:hooks (host/id hook)] hook))
{:components components
:queries #{:get-in :get-collectible-token}
:events #{:set-in}
:permissions {:read {:include-paths #{[:chats #".*"]}}
:write {:include-paths #{}}}}
app-hooks))
(defn parse [{:keys [data]}]
(try
(let [{:keys [errors] :as extension-data} (reader/parse {:capacities capacities} data)]
(when errors
(println "Failed to parse status extensions" errors))
extension-data)
(catch :default e (println "EXC" e))))
(def storages
{:gist (gist/GistStorage.)})
(defn read-extension [o]
(-> o :value first :content reader/read))
(defn load-from [url f]
(let [[type id] (extension/url->storage-details url)
storage (get storages type)]
(when (and storage id)
(storage/fetch storage
{:value id}
#(f %)))))

View File

@ -9,7 +9,7 @@
status-im.web3.events
status-im.ui.screens.add-new.new-chat.navigation
status-im.ui.screens.profile.events
status-im.ui.screens.extensions.events
status-im.ui.screens.extensions.add.events
status-im.ui.screens.wallet.events
status-im.ui.screens.wallet.collectibles.events
status-im.ui.screens.wallet.send.events

View File

@ -1,7 +1,7 @@
(ns status-im.ui.screens.extensions.add.events
(:require [re-frame.core :as re-frame]
[pluto.registry :as registry]
[status-im.extensions.registry :as extensions]
[status-im.extensions.core :as extensions]
[status-im.ui.screens.navigation :as navigation]
[status-im.i18n :as i18n]
[status-im.utils.handlers :as handlers]
@ -19,7 +19,7 @@
(fx/merge cofx
{:ui/show-confirmation {:title (i18n/label :t/success)
:content (i18n/label :t/extension-installed)
:on-accept #(re-frame/dispatch [:navigate-to-clean :home])
:on-accept #(re-frame/dispatch [:navigate-to-clean :my-profile])
:on-cancel nil}}
#(registry/add extension-data %)
#(registry/activate extension-key %)))))

View File

@ -3,6 +3,10 @@
(:require [status-im.ui.components.styles :as styles]
[status-im.ui.components.colors :as colors]))
(def screen
{:flex 1
:background-color colors/white})
(def wrapper
{:flex 1
:margin 16})

View File

@ -29,7 +29,7 @@
(views/defview show-extension []
(views/letsubs [{:keys [data errors]} [:get-staged-extension]]
[react/view components.styles/flex
[react/view styles/screen
[status-bar/status-bar]
[react/keyboard-avoiding-view components.styles/flex
[toolbar/simple-toolbar (i18n/label :t/extension)]
@ -52,12 +52,12 @@
[components.common/bottom-button
{:forward? true
:label (i18n/label :t/install)
:disabled? (seq errors)
:disabled? (not (empty? errors))
:on-press #(re-frame/dispatch [:extension/install data])}]]]]))
(views/defview add-extension []
(views/letsubs [extension-url [:get-extension-url]]
[react/view components.styles/flex
[react/view styles/screen
[status-bar/status-bar]
[react/keyboard-avoiding-view components.styles/flex
[toolbar/simple-toolbar (i18n/label :t/extension-find)]

View File

@ -1,10 +0,0 @@
(ns status-im.ui.screens.extensions.events
(:require [re-frame.core :as re-frame]
[pluto.registry :as registry]
[status-im.utils.handlers :as handlers]
status-im.ui.screens.extensions.add.events))
(handlers/register-handler-fx
:extensions/toggle-activation
(fn [{:keys [db]} [_ id m]]
nil))

View File

@ -2,7 +2,6 @@
(:require-macros [status-im.utils.views :as views])
(:require [re-frame.core :as re-frame]
[status-im.i18n :as i18n]
[status-im.extensions.registry :as registry]
[status-im.ui.components.icons.vector-icons :as vector-icons]
[status-im.ui.components.list.views :as list]
[status-im.ui.components.react :as react]