fixed extensions installation issues

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2018-12-10 16:40:45 +01:00
parent 1a46355c61
commit 8374a7d532
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
8 changed files with 73 additions and 72 deletions

View File

@ -27,7 +27,6 @@
(cond
(= permission constants/dapp-permission-install-extension)
(fx/merge cofx
{:db (assoc-in db [:extensions/manage :url :value] (:uri params))}
(extensions.registry/load (:uri params) true)
(send-response-to-bridge permission message-id true nil)
(process-next-permission dapp-name))

View File

@ -510,21 +510,19 @@
(extensions.registry/change-state cofx extension-key active?)))
(handlers/register-handler-fx
:extensions.ui/show-button-pressed
:extensions.ui/find-button-pressed
(fn [cofx [_ url]]
(extensions.registry/load cofx url false)))
(handlers/register-handler-fx
:extensions.ui/install-extension-button-pressed
(fn [{:keys [db] :as cofx} [_ url]]
(fx/merge cofx
{:db (assoc-in db [:extensions/manage :url :value] url)}
(extensions.registry/load url true))))
(fn [cofx [_ url]]
(extensions.registry/load cofx url true)))
(handlers/register-handler-fx
:extensions.ui/install-button-pressed
(fn [cofx [_ data modal?]]
(extensions.registry/install cofx data modal?)))
(fn [cofx [_ url data modal?]]
(extensions.registry/install cofx url data modal?)))
;; log-level module

View File

@ -49,10 +49,8 @@
(update-hooks hook-fn extension-key))))
(fx/defn install
[{:keys [db] :as cofx} {:keys [hooks] :as extension-data} modal?]
(let [{:extensions/keys [manage]
:account/keys [account]} db
url (get-in manage [:url :value])
[{: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])
:url url
@ -112,11 +110,12 @@
(map #(existing-hooks-for % cofx extension-data))
(apply set/union)))
(fx/defn stage-extension [{:keys [db] :as cofx} extension-data modal?]
(fx/defn stage-extension [{:keys [db] :as cofx} url extension-data modal?]
(let [hooks (existing-hooks cofx extension-data)]
(if (empty? hooks)
(fx/merge cofx
{:db (assoc db :staged-extension extension-data)}
{:db (assoc db :extensions/staged-extension {:url url
:extension-data extension-data})}
(navigation/navigate-to-cofx (if modal? :show-extension-modal :show-extension) nil))
{:utils/show-popup {:title (i18n/label :t/error)
:content (i18n/label :t/extension-hooks-cannot-be-added

View File

@ -16,7 +16,8 @@
[status-im.i18n :as i18n]
[status-im.ui.components.colors :as colors]
[status-im.ui.components.icons.vector-icons :as icons]
[status-im.chat.commands.protocol :as protocol]))
[status-im.chat.commands.protocol :as protocol]
[status-im.extensions.core :as extensions]))
(defn install-extension-message [extension-id outgoing]
[react/touchable-highlight {:on-press #(re-frame/dispatch
@ -33,7 +34,9 @@
(letsubs [id->command [:chats/id->command]]
(let [{:keys [type] :as command} (commands-receiving/lookup-command-by-ref command-message id->command)
extension-id (get-in command-message [:content :params :extension-id])]
(if (and platform/mobile? extension-id (or (not type) (and type (satisfies? protocol/Extension type)
(if (and platform/mobile? extension-id
(extensions/valid-uri? extension-id)
(or (not type) (and type (satisfies? protocol/Extension type)
(not= extension-id (protocol/extension-id type)))))
;; Show install message only for mobile and if message contains extension id and there is no extension installed
;; or installed extension has differen extension id

View File

@ -164,7 +164,8 @@
(spec/def ::collectibles (spec/nilable map?))
(spec/def ::extension-url (spec/nilable string?))
(spec/def ::staged-extension (spec/nilable any?))
(spec/def :extensions/staged-extension (spec/nilable any?))
(spec/def :extensions/manage (spec/nilable any?))
(spec/def ::extensions-store (spec/nilable any?))
;;;;NODE
@ -218,6 +219,7 @@
:networks/networks
:networks/manage
:bootnodes/manage
:extensions/staged-extension
:extensions/manage
:node/status
:node/restart?
@ -321,6 +323,5 @@
::device-UUID
::collectible
::collectibles
::staged-extension
::extensions-store
:registry/registry]))

View File

@ -15,13 +15,13 @@
(handlers/register-handler-fx
:extensions/stage
(fn [cofx [_ _ extension-data]]
(extensions.registry/stage-extension cofx extension-data false)))
(fn [cofx [_ url extension-data]]
(extensions.registry/stage-extension cofx url extension-data false)))
(handlers/register-handler-fx
:extensions/stage-modal
(fn [cofx [_ _ extension-data]]
(extensions.registry/stage-extension cofx extension-data true)))
(fn [cofx [_ url extension-data]]
(extensions.registry/stage-extension cofx url extension-data true)))
(handlers/register-handler-fx
:extensions/add-to-registry

View File

@ -9,4 +9,4 @@
(re-frame/reg-sub
:get-staged-extension
(fn [db]
(:staged-extension db)))
(:extensions/staged-extension db)))

View File

@ -31,7 +31,8 @@
hooks))
(views/defview show-extension-base [modal?]
(views/letsubs [{:keys [data errors]} [:get-staged-extension]]
(views/letsubs [{:keys [extension-data url]} [:get-staged-extension]]
(let [{:keys [data errors]} extension-data]
(if data
[react/view styles/screen
[status-bar/status-bar]
@ -71,14 +72,14 @@
{:forward? true
:label (i18n/label :t/install)
:disabled? (not (empty? errors))
:on-press #(re-frame/dispatch [:extensions.ui/install-button-pressed data modal?])}]]]]
:on-press #(re-frame/dispatch [:extensions.ui/install-button-pressed url data modal?])}]]]]
[react/view styles/screen
[status-bar/status-bar]
[react/view {:flex 1}
[toolbar/simple-toolbar (i18n/label :t/extension)]
[react/view {:style {:flex 1 :justify-content :center :align-items :center}}
[react/text (i18n/label :t/invalid-extension)]
[react/text (str errors)]]]])))
[react/text (str errors)]]]]))))
(views/defview show-extension []
[show-extension-base false])
@ -118,4 +119,4 @@
{:forward? true
:label (i18n/label :t/find)
:disabled? (and (not @pressed) (not (extensions/valid-uri? url)))
:on-press #(do (reset! pressed true) (re-frame/dispatch [:extensions.ui/show-button-pressed (string/trim url)]))}]]]])))
:on-press #(do (reset! pressed true) (re-frame/dispatch [:extensions.ui/find-button-pressed (string/trim url)]))}]]]])))