[#6736] support multi-extensions store
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
bc44df32cb
commit
624130e440
2
deps.edn
2
deps.edn
|
@ -11,7 +11,7 @@
|
||||||
com.taoensso/timbre {:mvn/version "4.10.0"}
|
com.taoensso/timbre {:mvn/version "4.10.0"}
|
||||||
hickory {:mvn/version "0.7.1"}
|
hickory {:mvn/version "0.7.1"}
|
||||||
com.cognitect/transit-cljs {:mvn/version "0.8.248"}
|
com.cognitect/transit-cljs {:mvn/version "0.8.248"}
|
||||||
status-im/pluto {:mvn/version "iteration-4-1"}
|
status-im/pluto {:mvn/version "iteration-4-2"}
|
||||||
mvxcvi/alphabase {:mvn/version "1.0.0"}
|
mvxcvi/alphabase {:mvn/version "1.0.0"}
|
||||||
rasom/cljs-react-navigation {:mvn/version "0.1.4"}}
|
rasom/cljs-react-navigation {:mvn/version "0.1.4"}}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:alert
|
:alert
|
||||||
(fn [_ [_ {:keys [value]}]]
|
(fn [_ [_ _ {:keys [value]}]]
|
||||||
{::alert value}))
|
{::alert value}))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
|
@ -31,21 +31,23 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:log
|
:log
|
||||||
(fn [_ [_ {:keys [value]}]]
|
(fn [_ [_ _ {:keys [value]}]]
|
||||||
{::log value}))
|
{::log value}))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:store/get
|
:extensions/identity
|
||||||
(fn [db [_ {:keys [key]}]]
|
(fn [_ [_ _ {:keys [value]}]]
|
||||||
(get-in db [:extensions-store :collectible key])))
|
value))
|
||||||
|
|
||||||
(re-frame/reg-sub :extensions/identity
|
(re-frame/reg-sub
|
||||||
(fn [_ [_ {:keys [value]}]] value))
|
:store/get
|
||||||
|
(fn [db [_ {id :id} {:keys [key]}]]
|
||||||
|
(get-in db [:extensions/store id key])))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:store/put
|
:store/put
|
||||||
(fn [{:keys [db]} [_ {:keys [key value]}]]
|
(fn [{:keys [db]} [_ {id :id} {:keys [key value]}]]
|
||||||
{:db (assoc-in db [:extensions-store :collectible key] value)}))
|
{:db (assoc-in db [:extensions/store id key] value)}))
|
||||||
|
|
||||||
(defn- append [acc k v]
|
(defn- append [acc k v]
|
||||||
(let [o (get acc k)]
|
(let [o (get acc k)]
|
||||||
|
@ -53,13 +55,13 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:store/append
|
:store/append
|
||||||
(fn [{:keys [db]} [_ {:keys [key value]}]]
|
(fn [{:keys [db]} [_ {id :id} {:keys [key value]}]]
|
||||||
{:db (update-in db [:extensions-store :collectible] append key value)}))
|
{:db (update-in db [:extensions/store id] append key value)}))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:store/clear
|
:store/clear
|
||||||
(fn [{:keys [db]} [_ {:keys [key]}]]
|
(fn [{:keys [db]} [_ {id :id} {:keys [key]}]]
|
||||||
{:db (update-in db [:extensions-store :collectible] dissoc key)}))
|
{:db (update-in db [:extensions/store id] dissoc key)}))
|
||||||
|
|
||||||
(defn- json? [res]
|
(defn- json? [res]
|
||||||
(when-let [type (get-in res [:headers "content-type"])]
|
(when-let [type (get-in res [:headers "content-type"])]
|
||||||
|
@ -76,7 +78,7 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:extensions/json-parse
|
:extensions/json-parse
|
||||||
(fn [_ [_ m]]
|
(fn [_ [_ _ m]]
|
||||||
{::json-parse m}))
|
{::json-parse m}))
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
|
@ -86,12 +88,12 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:extensions/json-stringify
|
:extensions/json-stringify
|
||||||
(fn [_ [_ {:keys [value]}]]
|
(fn [_ [_ _ {:keys [value]}]]
|
||||||
{::json-stringify value}))
|
{::json-stringify value}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
:http/get
|
:http/get
|
||||||
(fn [_ [_ {:keys [url on-success on-failure timeout]}]]
|
(fn [_ [_ _ {:keys [url on-success on-failure timeout]}]]
|
||||||
{:http-raw-get (merge {:url url
|
{:http-raw-get (merge {:url url
|
||||||
:success-event-creator
|
:success-event-creator
|
||||||
(fn [{:keys [body] :as o}]
|
(fn [{:keys [body] :as o}]
|
||||||
|
@ -104,7 +106,7 @@
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
:ipfs/cat
|
:ipfs/cat
|
||||||
(fn [_ [_ {:keys [hash on-success on-failure]}]]
|
(fn [_ [_ _ {:keys [hash on-success on-failure]}]]
|
||||||
{:http-raw-get (merge {:url (str "https://ipfs.infura.io/ipfs/" hash)
|
{:http-raw-get (merge {:url (str "https://ipfs.infura.io/ipfs/" hash)
|
||||||
:success-event-creator
|
:success-event-creator
|
||||||
(fn [{:keys [status body]}]
|
(fn [{:keys [status body]}]
|
||||||
|
@ -118,7 +120,7 @@
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
:http/post
|
:http/post
|
||||||
(fn [_ [_ {:keys [url body on-success on-failure timeout]}]]
|
(fn [_ [_ _ {:keys [url body on-success on-failure timeout]}]]
|
||||||
{:http-raw-post (merge {:url url
|
{:http-raw-post (merge {:url url
|
||||||
:body (clj->js body)
|
:body (clj->js body)
|
||||||
:success-event-creator
|
:success-event-creator
|
||||||
|
@ -144,7 +146,7 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:extensions/arithmetic
|
:extensions/arithmetic
|
||||||
(fn [_ [_ m]]
|
(fn [_ [_ _ m]]
|
||||||
{::arithmetic m}))
|
{::arithmetic m}))
|
||||||
|
|
||||||
(defn button [{:keys [on-click]} label]
|
(defn button [{:keys [on-click]} label]
|
||||||
|
@ -286,14 +288,14 @@
|
||||||
:on-result :event}}}
|
:on-result :event}}}
|
||||||
:hooks {:commands commands/command-hook}})
|
:hooks {:commands commands/command-hook}})
|
||||||
|
|
||||||
(defn parse [{:keys [data]}]
|
(defn parse [{:keys [data]} id]
|
||||||
(try
|
(try
|
||||||
(reader/parse {:capacities capacities} data)
|
(reader/parse {:capacities capacities :env {:id id}} data)
|
||||||
(catch :default e {:errors [{:value (str e)}]})))
|
(catch :default e {:errors [{:value (str e)}]})))
|
||||||
|
|
||||||
(defn parse-extension [{:keys [type value]}]
|
(defn parse-extension [{:keys [type value]} id]
|
||||||
(if (= type :success)
|
(if (= type :success)
|
||||||
(parse (reader/read (:content value)))
|
(parse (reader/read (:content value)) id)
|
||||||
{:errors [{:type type :value value}]}))
|
{:errors [{:type type :value value}]}))
|
||||||
|
|
||||||
(def uri-prefix "https://get.status.im/extension/")
|
(def uri-prefix "https://get.status.im/extension/")
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
(ns status-im.extensions.registry
|
(ns status-im.extensions.registry
|
||||||
(:refer-clojure :exclude [list])
|
(:refer-clojure :exclude [list])
|
||||||
(:require [clojure.string :as string]
|
(:require [clojure.string :as string]
|
||||||
[pluto.utils :as utils]
|
|
||||||
[pluto.reader.hooks :as hooks]
|
[pluto.reader.hooks :as hooks]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[status-im.accounts.update.core :as accounts.update]
|
[status-im.accounts.update.core :as accounts.update]
|
||||||
|
@ -13,7 +12,7 @@
|
||||||
[{:keys [db] :as cofx} hook-fn extension-key]
|
[{:keys [db] :as cofx} hook-fn extension-key]
|
||||||
(let [account (get db :account/account)
|
(let [account (get db :account/account)
|
||||||
hooks (get-in account [:extensions extension-key :hooks])]
|
hooks (get-in account [:extensions extension-key :hooks])]
|
||||||
(apply utils/merge-fx cofx
|
(apply fx/merge cofx
|
||||||
(mapcat (fn [[_ extension-hooks]]
|
(mapcat (fn [[_ extension-hooks]]
|
||||||
(map (fn [[hook-id {:keys [hook-ref parsed]}]]
|
(map (fn [[hook-id {:keys [hook-ref parsed]}]]
|
||||||
(partial hook-fn (:hook hook-ref) hook-id parsed))
|
(partial hook-fn (:hook hook-ref) hook-id parsed))
|
||||||
|
@ -47,13 +46,11 @@
|
||||||
(update-hooks hook-fn extension-key))))
|
(update-hooks hook-fn extension-key))))
|
||||||
|
|
||||||
(fx/defn install
|
(fx/defn install
|
||||||
[{:keys [db random-id-generator] :as cofx} extension-data]
|
[{:keys [db] :as cofx} extension-data]
|
||||||
(let [{:extensions/keys [manage]
|
(let [{:extensions/keys [manage]
|
||||||
:account/keys [account]} db
|
:account/keys [account]} db
|
||||||
{:keys [id url]} manage
|
{:keys [url]} manage
|
||||||
extension {:id (-> (:value id)
|
extension {:id (:value url)
|
||||||
(or (random-id-generator))
|
|
||||||
(string/replace "-" ""))
|
|
||||||
:name (get-in extension-data ['meta :name])
|
:name (get-in extension-data ['meta :name])
|
||||||
:url (:value url)
|
:url (:value url)
|
||||||
:active? true}
|
:active? true}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
:extensions/load
|
:extensions/load
|
||||||
(fn [{:keys [extensions follow-up]}]
|
(fn [{:keys [extensions follow-up]}]
|
||||||
(doseq [{:keys [url active?]} extensions]
|
(doseq [{:keys [url active?]} extensions]
|
||||||
(extensions/load-from url #(re-frame/dispatch [follow-up url (extensions/parse-extension %) active?])))))
|
(extensions/load-from url #(re-frame/dispatch [follow-up url (extensions/parse-extension % url) active?])))))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:extensions/stage
|
:extensions/stage
|
||||||
|
|
Loading…
Reference in New Issue