Migrated to latest pluto release

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Julien Eluard 2019-02-04 14:12:46 +01:00 committed by Andrey Shovkoplyas
parent 3efeb71a16
commit 38570aa42f
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
10 changed files with 227 additions and 218 deletions

View File

@ -1,6 +1,6 @@
{:paths ["components/src" "src" "react-native/src/cljsjs" "resources"]
:deps {org.clojure/clojure {:mvn/version "1.9.0"} ;; Keep in sync with .TOOLVERSIONS
org.clojure/clojurescript {:mvn/version "1.10.439"}
org.clojure/clojurescript {:mvn/version "1.10.238"}
org.clojure/core.async {:mvn/version "0.4.474"}
reagent {:mvn/version "0.7.0"
:exclusions [cljsjs/react cljsjs/react-dom cljsjs/react-dom-server cljsjs/create-react-class]}
@ -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-4-7"}
status-im/pluto {:mvn/version "iteration-4-8"}
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-4-7"]
[status-im/pluto "iteration-4-8"]
[mvxcvi/alphabase "1.0.0"]
[rasom/cljs-react-navigation "0.1.4"]]
:plugins [[lein-cljsbuild "1.1.7"]

View File

@ -1,8 +1,5 @@
(ns status-im.chat.commands.core
(:require [re-frame.core :as re-frame]
[clojure.set :as set]
[pluto.reader.hooks :as hooks]
[status-im.constants :as constants]
(:require [clojure.set :as set]
[status-im.chat.constants :as chat.constants]
[status-im.chat.commands.protocol :as protocol]
[status-im.chat.commands.impl.transactions :as transactions]
@ -129,55 +126,6 @@
{}
access-scope->command-id))))}))
(def command-hook
"Hook for extensions"
{:properties
{:description? :string
:scope #{:personal-chats :public-chats :group-chats}
:short-preview? :view
:preview? :view
:on-send? :event
:on-receive? :event
:on-send-sync? :event
:parameters? [{:id :keyword
:type {:one-of #{:text :phone :password :number}}
:placeholder :string
:suggestions? :view}]}
:hook
(reify hooks/Hook
(hook-in [_ id {extension-id :id} {:keys [description scope parameters preview short-preview
on-send on-receive on-send-sync]} cofx]
(let [new-command (if on-send-sync
(reify protocol/Command
(id [_] (name id))
(scope [_] scope)
(description [_] description)
(parameters [_] (or parameters []))
(validate [_ _ _])
(on-send [_ command-message _] (when on-send {:dispatch (on-send command-message)}))
(on-receive [_ command-message _] (when on-receive {:dispatch (on-receive command-message)}))
(short-preview [_ props] (when short-preview (short-preview props)))
(preview [_ props] (when preview (preview props)))
protocol/Yielding
(yield-control [_ props _] {:dispatch (on-send-sync props)})
protocol/Extension
(extension-id [_] extension-id))
(reify protocol/Command
(id [_] (name id))
(scope [_] scope)
(description [_] description)
(parameters [_] (or parameters []))
(validate [_ _ _])
(on-send [_ command-message _] (when on-send {:dispatch (on-send command-message)}))
(on-receive [_ command-message _] (when on-receive {:dispatch (on-receive command-message)}))
(short-preview [_ props] (when short-preview (short-preview props)))
(preview [_ props] (when preview (preview props)))
protocol/Extension
(extension-id [_] extension-id)))]
(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
(fn [cofx [_ commands]]

View File

@ -28,13 +28,13 @@
:extensions/camera-error
(fn [cofx [_ error {:keys [on-failure]}]]
(when on-failure
{:dispatch (on-failure {:result error})})))
(on-failure {:result error}))))
(handlers/register-handler-fx
:extensions/camera-picture-taken
(fn [cofx [_ data {{:keys [on-success]} :data back? :back?}]]
(fx/merge cofx
{:dispatch (on-success {:result data})}
(on-success {:result data})
(when back?
(navigation/navigate-back)))))
@ -50,7 +50,7 @@
:extensions/camera-qr-code-scanned
(fn [cofx [_ _ qr-code {{:keys [on-success]} :data}]]
(fx/merge cofx
{:dispatch (on-success {:result qr-code})}
(on-success {:result qr-code})
(navigation/navigate-back))))
(handlers/register-handler-fx

View File

@ -1,9 +1,10 @@
(ns status-im.extensions.core
(:refer-clojure :exclude [list])
(:require [clojure.string :as string]
[pluto.core :as pluto]
[pluto.storages :as storages]
[pluto.reader :as reader]
[re-frame.core :as re-frame]
[re-frame.registrar :as registrar]
[status-im.chat.commands.core :as commands]
[status-im.chat.commands.impl.transactions :as transactions]
[status-im.ui.components.button.view :as button]
@ -30,7 +31,7 @@
(re-frame/reg-fx
::identity-event
(fn [{:keys [cb]}] (re-frame/dispatch (cb {}))))
(fn [{:keys [cb]}] (cb {})))
(re-frame/reg-event-fx
:extensions/identity-event
@ -58,8 +59,8 @@
(re-frame/reg-fx
::schedule-start
(fn [{:keys [interval on-created on-result]}]
(let [id (js/setInterval #(re-frame/dispatch (on-result {})) interval)]
(re-frame/dispatch (on-created {:value id})))))
(let [id (js/setInterval #(on-result {}) interval)]
(on-created {:value id}))))
(handlers/register-handler-fx
:extensions/schedule-start
@ -190,7 +191,7 @@
(re-frame/reg-fx
::json-parse
(fn [{:keys [value on-result]}]
(re-frame/dispatch (on-result {:value (parse-json value)}))))
(on-result {:value (parse-json value)})))
(handlers/register-handler-fx
:extensions/json-parse
@ -200,7 +201,7 @@
(re-frame/reg-fx
::json-stringify
(fn [value on-result]
(re-frame/dispatch (on-result {:value (js/JSON.stringify (clj->js value))}))))
(on-result {:value (js/JSON.stringify (clj->js value))})))
(handlers/register-handler-fx
:extensions/json-stringify
@ -309,7 +310,7 @@
:selection-modal-screen
(assoc params :on-select #(do
(re-frame/dispatch [:navigate-back])
(re-frame/dispatch (on-select %)))))))
(on-select %))))))
(defn operation->fn [k]
(case k
@ -321,7 +322,7 @@
(re-frame/reg-fx
::arithmetic
(fn [{:keys [operation values on-result]}]
(re-frame/dispatch (on-result {:value (apply (operation->fn operation) values)}))))
(on-result {:value (apply (operation->fn operation) values)})))
(handlers/register-handler-fx
:extensions/arithmetic
@ -335,10 +336,10 @@
(defn button [{:keys [on-click enabled disabled] :as m} label]
[button/secondary-button (merge {:disabled? (or (when (contains? m :enabled) (or (nil? enabled) (false? enabled))) disabled)}
(when on-click {:on-press #(re-frame/dispatch (on-click {}))})) label])
(when on-click {:on-press #(on-click {})})) label])
(defn on-input-change-text [on-change value]
(re-frame/dispatch (on-change {:value value})))
(on-change {:value value}))
(defn- on-input-change-text-delay [current on-change value delay]
;; If an input change handler has been already scheduled cancel it.
@ -360,7 +361,7 @@
#(on-input-change-text on-change %))}))])
(defn touchable-opacity [{:keys [style on-press]} & children]
(into [react/touchable-opacity (merge (when on-press {:on-press #(re-frame/dispatch (on-press {}))})
(into [react/touchable-opacity (merge (when on-press {:on-press #(on-press {})})
(when style {:style style}))] children))
(defn image [{:keys [source uri style]}]
@ -396,7 +397,7 @@
[react/view {:style {:background-color colors/white}}
[checkbox/checkbox {:checked? checked
:style {:padding 0}
:on-value-change #(re-frame/dispatch (on-change {:value %}))}]])
:on-value-change #(on-change {:value %})}]])
(defn activity-indicator-size [k]
(condp = k
@ -411,7 +412,7 @@
(when-let [size' (activity-indicator-size size)] {:size size'}))])
(defn picker [{:keys [style on-change selected enabled data]}]
[react/picker {:style style :on-change #(re-frame/dispatch (on-change {:value %})) :selected selected :enabled enabled :data data}])
[react/picker {:style style :on-change #(on-change {:value %}) :selected selected :enabled enabled :data data}])
(defn- wrap-text-child [o]
(if (ifn? o) o (str o)))
@ -442,23 +443,23 @@
[icons/icon key o])
(def capacities
{:components {'view {:value view}
'scroll-view {:value scroll-view :properties {:keyboard-should-persist-taps :keyword :content-container-style :map}}
'keyboard-avoiding-view {:value react/keyboard-avoiding-view}
'text {:value text}
'touchable-opacity {:value touchable-opacity :properties {:on-press :event}}
'icon {:value icon :properties {:key :keyword :color :any}}
'image {:value image :properties {:uri :string :source :string}}
'input {:value input :properties {:on-change :event :placeholder :string :keyboard-type :keyword :change-delay? :number :placeholder-text-color :any :selection-color :any}}
'button {:value button :properties {:enabled :boolean :disabled :boolean :on-click :event}}
'link {:value link :properties {:uri :string :text? :string :open-in? {:one-of #{:device :status}}}}
'list {:value list :properties {:data :vector :item-view :view :key? :keyword}}
'checkbox {:value checkbox :properties {:on-change :event :checked :boolean}}
'activity-indicator {:value activity-indicator :properties {:animating :boolean :color :string :size :keyword :hides-when-stopped :boolean}}
'picker {:value picker :properties {:on-change :event :selected :string :enabled :boolean :data :vector}}
'nft-token-viewer {:value transactions/nft-token :properties {:token :string}}
'transaction-status {:value transactions/transaction-status :properties {:outgoing :string :tx-hash :string}}
'map {:value map/map-webview
{:components {'view {:data view}
'scroll-view {:data scroll-view :properties {:keyboard-should-persist-taps :keyword :content-container-style :map}}
'keyboard-avoiding-view {:data react/keyboard-avoiding-view}
'text {:data text}
'touchable-opacity {:data touchable-opacity :properties {:on-press :event}}
'icon {:data icon :properties {:key :keyword :color :any}}
'image {:data image :properties {:uri :string :source :string}}
'input {:data input :properties {:on-change :event :placeholder :string :keyboard-type :keyword :change-delay? :number :placeholder-text-color :any :selection-color :any}}
'button {:data button :properties {:enabled :boolean :disabled :boolean :on-click :event}}
'link {:data link :properties {:uri :string :text? :string :open-in? {:one-of #{:device :status}}}}
'list {:data list :properties {:data :vector :item-view :view :key? :keyword}}
'checkbox {:data checkbox :properties {:on-change :event :checked :boolean}}
'activity-indicator {:data activity-indicator :properties {:animating :boolean :color :string :size :keyword :hides-when-stopped :boolean}}
'picker {:data picker :properties {:on-change :event :selected :string :enabled :boolean :data :vector}}
'nft-token-viewer {:data transactions/nft-token :properties {:token :string}}
'transaction-status {:data transactions/transaction-status :properties {:outgoing :string :tx-hash :string}}
'map {:data map/map-webview
:properties {:marker {:lng :number
:lat :number
:boundingbox {:lng1 :number
@ -468,45 +469,45 @@
:fly? :boolean
:interactive? :boolean
:on-change :event}}
'map-link {:value map-link :properties {:text :string :lng :any :lat :any}}}
:queries {'identity {:value :extensions/identity :arguments {:value :map}}
'store/get {:value :store/get :arguments {:key :string}}
'contacts/all {:value :extensions.contacts/all} ;; :photo :name :address :public-key
'wallet/collectibles {:value :get-collectible-token :arguments {:token :string :symbol :string}}
'wallet/balance {:value :extensions.wallet/balance :arguments {:token :string}}
'wallet/token {:value :extensions.wallet/token :arguments {:token :string :amount? :number :amount-in-wei? :number}}
'wallet/tokens {:value :extensions.wallet/tokens :arguments {:filter? :vector :visible? :boolean}}}
'map-link {:data map-link :properties {:text :string :lng :any :lat :any}}}
:queries {'identity {:data :extensions/identity :arguments {:value :map}}
'store/get {:data :store/get :arguments {:key :string}}
'contacts/all {:data :extensions.contacts/all} ;; :photo :name :address :public-key
'wallet/collectibles {:data :get-collectible-token :arguments {:token :string :symbol :string}}
'wallet/balance {:data :extensions.wallet/balance :arguments {:token :string}}
'wallet/token {:data :extensions.wallet/token :arguments {:token :string :amount? :number :amount-in-wei? :number}}
'wallet/tokens {:data :extensions.wallet/tokens :arguments {:filter? :vector :visible? :boolean}}}
:events {'identity
{:permissions [:read]
:value :extensions/identity-event
:data :extensions/identity-event
:arguments {:cb :event}}
'alert
{:permissions [:read]
:value :alert
:data :alert
:arguments {:value :string}}
'selection-screen
{:permissions [:read]
:value :extensions/show-selection-screen
:data :extensions/show-selection-screen
:arguments {:items :vector :on-select :event :render :view :title :string :extractor-key :keyword}}
'chat.command/set-parameter
{:permissions [:read]
:value :extensions.chat.command/set-parameter
:data :extensions.chat.command/set-parameter
:arguments {:value :any}}
'chat.command/set-custom-parameter
{:permissions [:read]
:value :extensions.chat.command/set-custom-parameter
:data :extensions.chat.command/set-custom-parameter
:arguments {:key :keyword :value :any}}
'chat.command/set-parameter-with-custom-params
{:permissions [:read]
:value :extensions.chat.command/set-parameter-with-custom-params
:data :extensions.chat.command/set-parameter-with-custom-params
:arguments {:value :string :params :map}}
'chat.command/send-plain-text-message
{:permissions [:read]
:value :extensions.chat.command/send-plain-text-message
:data :extensions.chat.command/send-plain-text-message
:arguments {:value :string}}
'chat.command/send-message
{:permissions [:read]
:value :extensions.chat.command/send-message
:data :extensions.chat.command/send-message
:arguments {:params :map}}
'chat.command/open-public-chat
{:permissions [:read]
@ -514,11 +515,11 @@
:arguments {:topic :string :navigate-to :boolean}}
'log
{:permissions [:read]
:value :log
:data :log
:arguments {:value :string}}
'arithmetic
{:permissions [:read]
:value :extensions/arithmetic
:data :extensions/arithmetic
:arguments {:values :vector
:operation {:one-of #{:plus :minus :times :divide}}
:on-result :event}}
@ -538,53 +539,53 @@
:on-failure? :event}}
'schedule/start
{:permissions [:read]
:value :extensions/schedule-start
:data :extensions/schedule-start
:arguments {:interval :number
:on-created :event
:on-result :event}}
'schedule/cancel
{:permissions [:read]
:value :extensions/schedule-cancel
:data :extensions/schedule-cancel
:arguments {:value :number}}
'json/parse
{:permissions [:read]
:value :extensions/json-parse
:data :extensions/json-parse
:arguments {:value :string
:on-result :event}}
'json/stringify
{:permissions [:read]
:value :extensions/json-stringify
:data :extensions/json-stringify
:arguments {:value :string
:on-result :event}}
'store/put
{:permissions [:read]
:value :store/put
:data :store/put
:arguments {:key :string :value :any}}
'store/puts
{:permissions [:read]
:value :store/puts
:data :store/puts
:arguments {:value :vector}}
'store/append
{:permissions [:read]
:value :store/append
:data :store/append
:arguments {:key :string :value :any}}
'store/clear
{:permissions [:read]
:value :store/clear
:data :store/clear
:arguments {:key :string}}
'store/clear-all
{:permissions [:read]
:value :store/clear-all}
:data :store/clear-all}
'http/get
{:permissions [:read]
:value :http/get
:data :http/get
:arguments {:url :string
:timeout? :string
:on-success :event
:on-failure? :event}}
'http/post
{:permissions [:read]
:value :http/post
:data :http/post
:arguments {:url :string
:body :string
:timeout? :string
@ -592,26 +593,26 @@
:on-failure? :event}}
'ipfs/cat
{:permissions [:read]
:value :ipfs/cat
:data :ipfs/cat
:arguments {:hash :string
:on-success :event
:on-failure? :event}}
'ipfs/add
{:permissions [:read]
:value :ipfs/add
:data :ipfs/add
:arguments {:value :string
:on-success :event
:on-failure? :event}}
'ethereum/transaction-receipt
{:permissions [:read]
:value :extensions/ethereum-transaction-receipt
:data :extensions/ethereum-transaction-receipt
:arguments {:value :string
:topics-hints :vector
:on-success :event
:on-failure? :event}}
'ethereum/await-transaction-receipt
{:permissions [:read]
:value :extensions/ethereum-await-transaction-receipt
:data :extensions/ethereum-await-transaction-receipt
:arguments {:value :string
:interval :number
:topics-hints :vector
@ -619,18 +620,18 @@
:on-failure? :event}}
'ethereum/sign
{:permissions [:read]
:value :extensions/ethereum-sign
:data :extensions/ethereum-sign
:arguments {:message? :string
:data? :string
:on-success :event
:on-failure? :event}}
'ethereum/create-address
{:permissions [:read]
:value :extensions/ethereum-create-address
:data :extensions/ethereum-create-address
:arguments {:on-result :event}}
'ethereum/send-transaction
{:permissions [:read]
:value :extensions/ethereum-send-transaction
:data :extensions/ethereum-send-transaction
:arguments {:to :string
:gas? :string
:gas-price? :string
@ -642,7 +643,7 @@
:on-failure? :event}}
'ethereum/logs
{:permissions [:read]
:value :extensions/ethereum-logs
:data :extensions/ethereum-logs
:arguments {:from? :string
:to? :string
:address? :vector
@ -652,7 +653,7 @@
:on-failure? :event}}
'ethereum/create-filter
{:permissions [:read]
:value :extensions/ethereum-create-filter
:data :extensions/ethereum-create-filter
:arguments {:type {:one-of #{:filter :block :pending-transaction}}
:from? :string
:to? :string
@ -663,35 +664,35 @@
:on-failure? :event}}
'ethereum/logs-changes
{:permissions [:read]
:value :extensions/ethereum-logs-changes
:data :extensions/ethereum-logs-changes
:arguments {:id :string
:topics-hints :vector}}
'ethereum/cancel-filter
{:permissions [:read]
:value :extensions/ethereum-cancel-filter
:data :extensions/ethereum-cancel-filter
:arguments {:id :string}}
'ethereum.ens/resolve
{:permissions [:read]
:value :extensions/ethereum-resolve-ens
:data :extensions/ethereum-resolve-ens
:arguments {:name :string
:on-success :event
:on-failure? :event}}
'ethereum.erc20/total-supply
{:permissions [:read]
:value :extensions/ethereum-erc20-total-supply
:data :extensions/ethereum-erc20-total-supply
:arguments {:contract :string
:on-success :event
:on-failure? :event}}
'ethereum.erc20/balance-of
{:permissions [:read]
:value :extensions/ethereum-erc20-balance-of
:data :extensions/ethereum-erc20-balance-of
:arguments {:contract :string
:token-owner :string
:on-success :event
:on-failure? :event}}
'ethereum.erc20/transfer
{:permissions [:read]
:value :extensions/ethereum-erc20-transfer
:data :extensions/ethereum-erc20-transfer
:arguments {:contract :string
:to :string
:value :number
@ -699,7 +700,7 @@
:on-failure? :event}}
'ethereum.erc20/transfer-from
{:permissions [:read]
:value :extensions/ethereum-erc20-transfer-from
:data :extensions/ethereum-erc20-transfer-from
:arguments {:contract :string
:from :string
:to :string
@ -708,7 +709,7 @@
:on-failure? :event}}
'ethereum.erc20/approve
{:permissions [:read]
:value :extensions/ethereum-erc20-approve
:data :extensions/ethereum-erc20-approve
:arguments {:contract :string
:spender :string
:value :number
@ -716,7 +717,7 @@
:on-failure? :event}}
'ethereum.erc20/allowance
{:permissions [:read]
:value :extensions/ethereum-erc20-allowance
:data :extensions/ethereum-erc20-allowance
:arguments {:contract :string
:token-owner :string
:spender :string
@ -724,14 +725,14 @@
:on-failure? :event}}
'ethereum.erc721/owner-of
{:permissions [:read]
:value :extensions/ethereum-erc721-owner-of
:data :extensions/ethereum-erc721-owner-of
:arguments {:contract :string
:token-id :string
:on-success :event
:on-failure? :event}}
'ethereum.erc721/is-approved-for-all
{:permissions [:read]
:value :extensions/ethereum-erc721-is-approved-for-all
:data :extensions/ethereum-erc721-is-approved-for-all
:arguments {:contract :string
:owner :string
:operator :string
@ -739,14 +740,14 @@
:on-failure? :event}}
'ethereum.erc721/get-approved
{:permissions [:read]
:value :extensions/ethereum-erc721-get-approved
:data :extensions/ethereum-erc721-get-approved
:arguments {:contract :string
:token-id :string
:on-success :event
:on-failure? :event}}
'ethereum.erc721/set-approval-for-all
{:permissions [:read]
:value :extensions/ethereum-erc721-set-approval-for-all
:data :extensions/ethereum-erc721-set-approval-for-all
:arguments {:contract :string
:operator :string
:approved :boolean
@ -754,7 +755,7 @@
:on-failure? :event}}
'ethereum.erc721/safe-transfer-from
{:permissions [:read]
:value :extensions/ethereum-erc721-safe-transfer-from
:data :extensions/ethereum-erc721-safe-transfer-from
:arguments {:contract :string
:from :string
:to :string
@ -764,7 +765,7 @@
:on-failure? :event}}
'ethereum/call
{:permissions [:read]
:value :extensions/ethereum-call
:data :extensions/ethereum-call
:arguments {:to :string
:method :string
:params? :vector
@ -773,7 +774,7 @@
:on-failure? :event}}
'ethereum/shh_post
{:permissions [:read]
:value :extensions/shh-post
:data :extensions/shh-post
:arguments {:from? :string
:to? :string
:topics :vector
@ -784,7 +785,7 @@
:on-failure? :event}}
'ethereum/shh-new-identity
{:permissions [:read]
:value :extensions/shh-new-identity
:data :extensions/shh-new-identity
:arguments {:on-success :event
:on-failure? :event}}
'ethereum/shh-has-identity
@ -795,45 +796,75 @@
:on-failure? :event}}
'ethereum/shh-new-group
{:permissions [:read]
:value :extensions/shh-new-group
:data :extensions/shh-new-group
:arguments {:on-success :event
:on-failure? :event}}
'ethereum/shh-add-to-group
{:permissions [:read]
:value :extensions/shh-add-to-group
:data :extensions/shh-add-to-group
:arguments {:address :string
:on-success :event
:on-failure? :event}}
'ethereum/shh_new-filter
{:permissions [:read]
:value :extensions/shh-new-filter
:data :extensions/shh-new-filter
:arguments {:to? :string
:topics :vector
:on-success :event
:on-failure? :event}}
'ethereum/shh-uninstall-filter
{:permissions [:read]
:value :extensions/shh-uninstall-filter
:data :extensions/shh-uninstall-filter
:arguments {:id :string}}
'ethereum/shh-get-filter-changes
{:permissions [:read]
:value :extensions/shh-get-filter-changes
:data :extensions/shh-get-filter-changes
:arguments {:id :string}}
'ethereum/shh-get-messages
{:permissions [:read]
:value :extensions/shh-get-messages
:data :extensions/shh-get-messages
:arguments {:id :string}}}
:hooks {:chat.command commands/command-hook
:wallet.settings settings/hook}})
:hooks {:wallet.settings
{:properties
{:label :string
:view :view
:on-open? :event
:on-close? :event}}
:chat.command
{:properties
{:description? :string
:scope #{:personal-chats :public-chats :group-chats}
:short-preview? :view
:preview? :view
:on-send? :event
:on-receive? :event
:on-send-sync? :event
:parameters? [{:id :keyword
:type {:one-of #{:text :phone :password :number}}
:placeholder :string
:suggestions? :view}]}}}})
(defn dispatch-events [_ events]
(doseq [event events]
(when (vector? event)
(re-frame/dispatch event))))
(defn resolve-query [[id :as data]]
(when (registrar/get-handler :sub id)
(re-frame/subscribe data)))
(defn parse [{:keys [data]} id]
(try
(reader/parse {:capacities capacities :env {:id id}} data)
(pluto/parse {:capacities capacities
:env {:id id}
:event-fn dispatch-events
:query-fn resolve-query}
data)
(catch :default e {:errors [{:value (str e)}]})))
(defn parse-extension [{:keys [type value]} id]
(if (= type :success)
(parse (reader/read (:content value)) id)
(parse (pluto/read (:content value)) id)
{:errors [{:type type :value value}]}))
(def uri-prefix "https://get.status.im/extension/")

View File

@ -1,6 +1,5 @@
(ns status-im.extensions.ethereum
(:require [clojure.string :as string]
[re-frame.core :as re-frame]
[status-im.constants :as constants]
[status-im.i18n :as i18n]
[status-im.models.wallet :as models.wallet]
@ -12,7 +11,6 @@
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.handlers :as handlers]
[status-im.utils.money :as money]
[clojure.string :as string]
[status-im.utils.types :as types]
[status-im.native-module.core :as status]))
@ -20,13 +18,13 @@
:extensions/wallet-ui-on-success
(fn [cofx [_ on-success _ result _]]
(fx/merge cofx
{:dispatch (on-success {:value result})}
(when on-success (on-success {:value result}))
(navigation/navigate-back))))
(handlers/register-handler-fx
:extensions/wallet-ui-on-failure
(fn [_ [_ on-failure message]]
(when on-failure {:dispatch (on-failure {:value message})})))
(when on-failure (on-failure {:value message}))))
(defn- wrap-with-resolution [db arguments address-keyword f]
"function responsible to resolve ens taken from argument
@ -85,9 +83,9 @@
(defn- rpc-dispatch [error result f on-success on-failure]
(when result
(re-frame/dispatch (on-success {:value (f result)})))
(on-success {:value (f result)}))
(when (and error on-failure)
(re-frame/dispatch (on-failure {:value error}))))
(on-failure {:value error})))
(defn- rpc-handler [o f on-success on-failure]
(let [{:keys [error result]} (types/json->clj o)]
@ -370,9 +368,9 @@
network-info (get-in db [:account/account :networks network])
chain (ethereum/network->chain-keyword network-info)
registry (get ens/ens-registries chain)]
(ens/get-addr web3 registry name #(re-frame/dispatch (on-success {:value %}))))
(ens/get-addr web3 registry name #(on-success {:value %})))
(when on-failure
(re-frame/dispatch (on-failure {:value (str "'" name "' is not a valid name")}))))))
(on-failure {:value (str "'" name "' is not a valid name")})))))
;; EXTENSION SIGN -> SIGN MESSAGE
(handlers/register-handler-fx
@ -380,7 +378,7 @@
(fn [{db :db :as cofx} [_ _ {:keys [message data id on-success on-failure]}]]
(if (and message data)
(when on-failure
{:dispatch (on-failure {:error "only one of :message and :data can be used"})})
(on-failure {:error "only one of :message and :data can be used"}))
(fx/merge cofx
{:db (assoc-in db [:wallet :send-transaction]
{:id id
@ -400,7 +398,7 @@
(status/call-private-rpc payload #(let [{:keys [error result]} (types/json->clj %1)
response (if error {:result result :error error}
{:result result})]
(re-frame/dispatch (on-result response)))))))
(on-result response))))))
;; poll logs implementation
(handlers/register-handler-fx

View File

@ -1,29 +1,88 @@
(ns status-im.extensions.registry
(:refer-clojure :exclude [list])
(:require [clojure.string :as string]
[pluto.reader.hooks :as hooks]
(:require [clojure.set :as set]
[clojure.string :as string]
[re-frame.core :as re-frame]
[pluto.core :as pluto]
[status-im.accounts.update.core :as accounts.update]
[status-im.chat.commands.core :as commands]
[status-im.chat.commands.protocol :as protocol]
[status-im.i18n :as i18n]
[status-im.utils.fx :as fx]
[clojure.set :as set]
[status-im.ui.screens.navigation :as navigation]))
[status-im.ui.screens.navigation :as navigation]
[status-im.utils.fx :as fx]))
(defprotocol Hook
"Encapsulate hook lifecycle."
(hook-in [this id env properties cofx] "Hook it into host app.")
(unhook [this id env properties cofx] "Remove extension hook from app."))
(defmulti hook-for (fn [hook] (pluto/hook-type hook)))
(defmethod hook-for "wallet.settings" [_]
(reify Hook
(hook-in [_ id _ m {:keys [db]}]
{:db (assoc-in db [:wallet :settings id] m)})
(unhook [_ id _ _ {:keys [db]}]
{:db (update-in db [:wallet :settings] dissoc id)})))
(defmethod hook-for "chat.command" [_]
(reify Hook
(hook-in [_ id {extension-id :id} {:keys [description scope parameters preview short-preview
on-send on-receive on-send-sync]} cofx]
(let [new-command (if on-send-sync
(reify protocol/Command
(id [_] (name id))
(scope [_] scope)
(description [_] description)
(parameters [_] (or parameters []))
(validate [_ _ _])
(on-send [_ command-message _] (when on-send (on-send command-message)))
(on-receive [_ command-message _] (when on-receive (on-receive command-message)))
(short-preview [_ props] (when short-preview (short-preview props)))
(preview [_ props] (when preview (preview props)))
protocol/Yielding
(yield-control [_ props _] (on-send-sync props))
protocol/Extension
(extension-id [_] extension-id))
(reify protocol/Command
(id [_] (name id))
(scope [_] scope)
(description [_] description)
(parameters [_] (or parameters []))
(validate [_ _ _])
(on-send [_ command-message _] (when on-send (on-send command-message)))
(on-receive [_ command-message _] (when on-receive (on-receive command-message)))
(short-preview [_ props] (when short-preview (short-preview props)))
(preview [_ props] (when preview (preview props)))
protocol/Extension
(extension-id [_] extension-id)))]
(commands/load-commands cofx [new-command])))
(unhook [_ id _ {:keys [scope]} {:keys [db] :as cofx}]
(when-let [command (get-in db [:id->command [(name id) scope] :type])]
(commands/remove-command command cofx)))))
(defmethod hook-for :default [a]
(reify Hook
(hook-in [this id env properties cofx])
(unhook [this id env properties cofx])))
(defn hook-id
[s]
(when s
(last (string/split (name s) #"\."))))
(fx/defn update-hooks
[{:keys [db] :as cofx} hook-fn extension-id]
(let [account (get db :account/account)
hooks (get-in account [:extensions extension-id :hooks])]
(apply fx/merge cofx
(mapcat (fn [[_ extension-hooks]]
(map (fn [[hook-id {parsed :parsed {hook :hook} :hook-ref}]]
(when hook
(partial hook-fn hook hook-id {:id extension-id} parsed)))
extension-hooks))
hooks))))
(map (fn [[type extension]]
(hook-fn (hook-for type) (hook-id type) {:id extension-id} extension cofx))
hooks))))
(fx/defn disable-hooks
[{:keys [db] :as cofx} extension-id]
(update-hooks cofx hooks/unhook extension-id))
(update-hooks cofx unhook extension-id))
(fx/defn add-to-registry
[{:keys [db] :as cofx} extension-id extension-data active?]
@ -32,14 +91,14 @@
:active? active?}]
(fx/merge cofx
{:db (update-in db [:account/account :extensions extension-id] merge data)}
(update-hooks hooks/hook-in extension-id))))
(update-hooks hook-in extension-id))))
(fx/defn remove-from-registry
[cofx extension-id]
(let [extensions (get-in cofx [:db :account/account :extensions])]
(fx/merge cofx
(when (get-in extensions [extension-id :active?])
(update-hooks hooks/unhook extension-id))
(update-hooks unhook extension-id))
{:db (update-in cofx [:db :account/account :extensions] dissoc extension-id)})))
(fx/defn change-state
@ -47,8 +106,8 @@
(let [extensions (get-in cofx [:db :account/account :extensions])
new-extensions (assoc-in extensions [extension-key :active?] active?)
hook-fn (if active?
hooks/hook-in
hooks/unhook)]
hook-in
unhook)]
(fx/merge cofx
(accounts.update/account-update {:extensions new-extensions} {:success-event nil})
(update-hooks hook-fn extension-key))))
@ -57,7 +116,7 @@
[{:keys [db] :as cofx} url {:keys [hooks] :as extension-data} modal?]
(let [{:account/keys [account]} db
extension {:id url
:name (get-in extension-data ['meta :name])
:name (or (get-in extension-data [:meta :name]) "Unnamed")
:url url
:active? true}
new-extensions (assoc (:extensions account) url extension)]
@ -115,13 +174,13 @@
(into acc)))
#{}
(get-in cofx [:db :account/account :extensions]))
hooks (->> (get-in extension-data [:data :hooks type])
hooks (->> (get-in extension-data [:hooks type])
(keys)
(into #{}))]
(set/intersection added-hooks hooks)))
(defn existing-hooks [cofx extension-data]
(->> (get-in extension-data [:data :hooks])
(->> (get-in extension-data [:hooks])
(keys)
(map #(existing-hooks-for % cofx extension-data))
(apply set/union)))

View File

@ -1,12 +1,6 @@
(ns status-im.native-module.impl.module
(:require-macros
[cljs.core.async.macros :refer [go-loop go]])
(:require [status-im.ui.components.react :as r]
[re-frame.core :as re-frame]
[taoensso.timbre :as log]
[cljs.core.async :as async]
[status-im.utils.platform :as p]
[status-im.utils.async :as async-util]
[status-im.react-native.js-dependencies :as rn-dependencies]
[clojure.string :as string]
[status-im.utils.platform :as platform]))

View File

@ -3,6 +3,7 @@
(:require [re-frame.core :as re-frame]
[reagent.core :as reagent]
[clojure.string :as string]
[pluto.reader.errors :as errors]
[status-im.extensions.core :as extensions]
[status-im.i18n :as i18n]
[status-im.ui.components.react :as react]
@ -23,13 +24,6 @@
[react/view {:flex 1}
content]]])
(defn hooks [{:keys [hooks]}]
(mapcat (fn [[hook-id values]]
(map (fn [[id]]
(str (name hook-id) "." (name id)))
values))
hooks))
(views/defview show-extension-base [modal?]
(views/letsubs [{:keys [extension-data url]} [:get-staged-extension]]
(let [{:keys [data errors]} extension-data]
@ -45,15 +39,15 @@
(i18n/label :t/extensions-disclaimer)]]
[cartouche {:header (i18n/label :t/identifier)}
[react/text {:style styles/text}
(str (get-in data ['meta :name]))]]
(str (get-in data [:meta :name]))]]
[cartouche {:header (i18n/label :t/name)}
[react/text {:style styles/text}
(str (get-in data ['meta :name]))]]
(str (get-in data [:meta :name]))]]
[cartouche {:header (i18n/label :t/description)}
[react/text {:style styles/text}
(str (get-in data ['meta :description]))]]
(str (get-in data [:meta :description]))]]
[cartouche {:header (i18n/label :t/hooks)}
(into [react/view] (for [hook (hooks data)]
(into [react/view] (for [hook (keys (:hooks data))]
[react/text {:style styles/text}
(str hook)]))]
[cartouche {:header (i18n/label :t/permissions)}
@ -61,9 +55,9 @@
(i18n/label :t/none)]]
[cartouche {:header (i18n/label :t/errors)}
(if errors
(into [react/view] (for [error errors]
(into [react/view] (for [{::errors/keys [type value]} errors]
[react/text {:style styles/text}
(str (name (:pluto.reader.errors/type error)) " " (str (:pluto.reader.errors/value error)))]))
(str (when type (name type)) " " (str value))]))
[react/text {:style styles/text}
(i18n/label :t/none)])]]]
[react/view styles/bottom-container

View File

@ -1,7 +1,6 @@
(ns status-im.ui.screens.wallet.settings.views
(:require-macros [status-im.utils.views :refer [defview letsubs]])
(:require [re-frame.core :as re-frame]
[pluto.reader.hooks :as hooks]
[status-im.i18n :as i18n]
[status-im.ui.components.colors :as colors]
[status-im.ui.components.list.views :as list]
@ -15,20 +14,6 @@
[status-im.utils.ethereum.tokens :as tokens]
[status-im.ui.components.toolbar.actions :as actions]))
(def hook
"Hook for extensions"
{:properties
{:label :string
:view :view
:on-open? :event
:on-close? :event}
:hook
(reify hooks/Hook
(hook-in [_ id _ {:keys [label view _]} {:keys [db]}]
{:db (assoc-in db [:wallet :settings id] {:label label :view view})})
(unhook [_ id _ _ {:keys [db]}]
{:db (update-in db [:wallet :settings] dissoc id)}))})
(defn- render-token [{:keys [symbol name icon]} visible-tokens]
[list/list-item-with-checkbox
{:checked? (contains? visible-tokens (keyword symbol))
@ -80,7 +65,7 @@
{:label label
:action #(do
(when on-open
(re-frame/dispatch (on-open address)))
(on-open address))
(re-frame/dispatch [:navigate-to :wallet-settings-hook m]))})
(defview toolbar-view []