From a5cc14ce8c911bf3a10df0c8647b6d4bbae819f0 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 4 Sep 2017 16:17:39 +0200 Subject: [PATCH] Signer plugin attachment --- js/src/DappRequests/store.js | 4 +++ js/src/ShellExtend/api.js | 4 +++ js/src/Signer/Embedded/embedded.js | 22 ++++++++++++++- js/src/Signer/pluginStore.js | 45 ++++++++++++++++++++++++++++++ js/src/Status/pluginStore.js | 4 +++ js/src/index.parity.js | 2 ++ 6 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 js/src/Signer/pluginStore.js diff --git a/js/src/DappRequests/store.js b/js/src/DappRequests/store.js index 870504f26..2b60811a8 100644 --- a/js/src/DappRequests/store.js +++ b/js/src/DappRequests/store.js @@ -161,6 +161,10 @@ export default class Store { } addMiddleware (middleware) { + if (!middleware || (typeof middleware !== 'function')) { + throw new Error('Interceptor middleware does not implement a function'); + } + this.middleware.push(middleware); } diff --git a/js/src/ShellExtend/api.js b/js/src/ShellExtend/api.js index f7d5f8b44..389981754 100644 --- a/js/src/ShellExtend/api.js +++ b/js/src/ShellExtend/api.js @@ -15,6 +15,7 @@ // along with Parity. If not, see . import InterceptorStore from '../DappRequests/store'; +import SignerPluginStore from '../Signer/pluginStore'; import StatusPluginStore from '../Status/pluginStore'; function injectInterceptorPlugin (middleware) { @@ -24,6 +25,9 @@ function injectInterceptorPlugin (middleware) { } function injectSignerPlugin (component) { + SignerPluginStore.get().addComponent(component); + + return true; } function injectStatusPlugin (component) { diff --git a/js/src/Signer/Embedded/embedded.js b/js/src/Signer/Embedded/embedded.js index 23b75b8c0..ff8db49ab 100644 --- a/js/src/Signer/Embedded/embedded.js +++ b/js/src/Signer/Embedded/embedded.js @@ -20,15 +20,18 @@ import PropTypes from 'prop-types'; import { FormattedMessage } from 'react-intl'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; +import { observer } from 'mobx-react'; import * as RequestsActions from '@parity/shared/redux/providers/signerActions'; import Container from '@parity/ui/Container'; import RequestPending from '@parity/ui/Signer/RequestPending'; - import Store from '@parity/shared/mobx/signerStore'; +import PluginStore from '../pluginStore'; + import styles from './embedded.css'; +@observer class Embedded extends Component { static contextTypes = { api: PropTypes.object.isRequired @@ -49,6 +52,7 @@ class Embedded extends Component { }; store = new Store(this.context.api, false, this.props.externalLink); + pluginStore = PluginStore.get(); render () { return ( @@ -87,6 +91,22 @@ class Embedded extends Component { renderPending = (data, index) => { const { actions, gasLimit, netVersion } = this.props; const { date, id, isSending, payload, origin } = data; + const Handler = this.pluginStore.findHandler(payload); + + // if (Handler) { + // return ( + // + // ); + // } return ( . + +import { action, observable } from 'mobx'; + +let instance = null; + +export default class PluginStore { + @observable components = []; + + @action addComponent (Component) { + if (!Component || (typeof Component.isHandler !== 'function')) { + throw new Error(`Unable to attach Signer component, 'isHandler' function is not defined`); + } + + this.components.push(Component); + } + + findHandler (payload) { + return this.components.find((component) => { + return component.isHandler(payload); + }); + } + + static get () { + if (!instance) { + instance = new PluginStore(); + } + + return instance; + } +} diff --git a/js/src/Status/pluginStore.js b/js/src/Status/pluginStore.js index 0f4dde782..2deaf9959 100644 --- a/js/src/Status/pluginStore.js +++ b/js/src/Status/pluginStore.js @@ -22,6 +22,10 @@ export default class PluginStore { @observable components = []; @action addComponent (Component) { + if (!Component) { + throw new Error('Unable to attach empty Component to status'); + } + this.components.push(Component); } diff --git a/js/src/index.parity.js b/js/src/index.parity.js index f5592dff4..449003035 100644 --- a/js/src/index.parity.js +++ b/js/src/index.parity.js @@ -81,3 +81,5 @@ ReactDOM.render( // testing, priceTicker gist injectExternalScript('https://cdn.rawgit.com/jacogr/396fc583e81b9404e21195a48dc862ca/raw/33e5058a4c0028cf9acf4b0662d75298e41ca6fa/priceTicker.js'); +// testing, signer plugin +injectExternalScript('https://cdn.rawgit.com/paritytech/plugin-sign-qr/master/dist.js');