Signer plugin attachment
This commit is contained in:
parent
7818ed98c7
commit
a5cc14ce8c
@ -161,6 +161,10 @@ export default class Store {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addMiddleware (middleware) {
|
addMiddleware (middleware) {
|
||||||
|
if (!middleware || (typeof middleware !== 'function')) {
|
||||||
|
throw new Error('Interceptor middleware does not implement a function');
|
||||||
|
}
|
||||||
|
|
||||||
this.middleware.push(middleware);
|
this.middleware.push(middleware);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import InterceptorStore from '../DappRequests/store';
|
import InterceptorStore from '../DappRequests/store';
|
||||||
|
import SignerPluginStore from '../Signer/pluginStore';
|
||||||
import StatusPluginStore from '../Status/pluginStore';
|
import StatusPluginStore from '../Status/pluginStore';
|
||||||
|
|
||||||
function injectInterceptorPlugin (middleware) {
|
function injectInterceptorPlugin (middleware) {
|
||||||
@ -24,6 +25,9 @@ function injectInterceptorPlugin (middleware) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function injectSignerPlugin (component) {
|
function injectSignerPlugin (component) {
|
||||||
|
SignerPluginStore.get().addComponent(component);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function injectStatusPlugin (component) {
|
function injectStatusPlugin (component) {
|
||||||
|
@ -20,15 +20,18 @@ import PropTypes from 'prop-types';
|
|||||||
import { FormattedMessage } from 'react-intl';
|
import { FormattedMessage } from 'react-intl';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { bindActionCreators } from 'redux';
|
import { bindActionCreators } from 'redux';
|
||||||
|
import { observer } from 'mobx-react';
|
||||||
|
|
||||||
import * as RequestsActions from '@parity/shared/redux/providers/signerActions';
|
import * as RequestsActions from '@parity/shared/redux/providers/signerActions';
|
||||||
import Container from '@parity/ui/Container';
|
import Container from '@parity/ui/Container';
|
||||||
import RequestPending from '@parity/ui/Signer/RequestPending';
|
import RequestPending from '@parity/ui/Signer/RequestPending';
|
||||||
|
|
||||||
import Store from '@parity/shared/mobx/signerStore';
|
import Store from '@parity/shared/mobx/signerStore';
|
||||||
|
|
||||||
|
import PluginStore from '../pluginStore';
|
||||||
|
|
||||||
import styles from './embedded.css';
|
import styles from './embedded.css';
|
||||||
|
|
||||||
|
@observer
|
||||||
class Embedded extends Component {
|
class Embedded extends Component {
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
api: PropTypes.object.isRequired
|
api: PropTypes.object.isRequired
|
||||||
@ -49,6 +52,7 @@ class Embedded extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
store = new Store(this.context.api, false, this.props.externalLink);
|
store = new Store(this.context.api, false, this.props.externalLink);
|
||||||
|
pluginStore = PluginStore.get();
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
@ -87,6 +91,22 @@ class Embedded extends Component {
|
|||||||
renderPending = (data, index) => {
|
renderPending = (data, index) => {
|
||||||
const { actions, gasLimit, netVersion } = this.props;
|
const { actions, gasLimit, netVersion } = this.props;
|
||||||
const { date, id, isSending, payload, origin } = data;
|
const { date, id, isSending, payload, origin } = data;
|
||||||
|
const Handler = this.pluginStore.findHandler(payload);
|
||||||
|
|
||||||
|
// if (Handler) {
|
||||||
|
// return (
|
||||||
|
// <Handler
|
||||||
|
// gasLimit={ gasLimit }
|
||||||
|
// id={ id }
|
||||||
|
// isSending={ isSending }
|
||||||
|
// key={ id }
|
||||||
|
// netVersion={ netVersion }
|
||||||
|
// onConfirm={ actions.startConfirmRequest }
|
||||||
|
// onReject={ actions.startRejectRequest }
|
||||||
|
// payload={ payload }
|
||||||
|
// />
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RequestPending
|
<RequestPending
|
||||||
|
45
js/src/Signer/pluginStore.js
Normal file
45
js/src/Signer/pluginStore.js
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
|
||||||
|
// This file is part of Parity.
|
||||||
|
|
||||||
|
// Parity is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
|
||||||
|
// Parity is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,10 @@ export default class PluginStore {
|
|||||||
@observable components = [];
|
@observable components = [];
|
||||||
|
|
||||||
@action addComponent (Component) {
|
@action addComponent (Component) {
|
||||||
|
if (!Component) {
|
||||||
|
throw new Error('Unable to attach empty Component to status');
|
||||||
|
}
|
||||||
|
|
||||||
this.components.push(Component);
|
this.components.push(Component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,3 +81,5 @@ ReactDOM.render(
|
|||||||
|
|
||||||
// testing, priceTicker gist
|
// testing, priceTicker gist
|
||||||
injectExternalScript('https://cdn.rawgit.com/jacogr/396fc583e81b9404e21195a48dc862ca/raw/33e5058a4c0028cf9acf4b0662d75298e41ca6fa/priceTicker.js');
|
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');
|
||||||
|
Loading…
Reference in New Issue
Block a user