-
+
);
}
}
diff --git a/js/src/views/DappMethods/index.js b/js/src/views/DappMethods/index.js
new file mode 100644
index 000000000..dee1b60b6
--- /dev/null
+++ b/js/src/views/DappMethods/index.js
@@ -0,0 +1,42 @@
+// 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 .
+
+import ReactDOM from 'react-dom';
+import React from 'react';
+import { Route, Router, hashHistory } from 'react-router';
+
+import injectTapEventPlugin from 'react-tap-event-plugin';
+injectTapEventPlugin();
+
+import ContractInstances from '@parity/shared/contracts';
+import { initStore } from '@parity/shared/redux';
+import ContextProvider from '@parity/ui/ContextProvider';
+
+import api from './api';
+import DappMethods from './dappMethods';
+
+ContractInstances.get(api);
+
+const store = initStore(api, hashHistory);
+
+ReactDOM.render(
+
+
+
+
+ ,
+ document.querySelector('#container')
+);
diff --git a/js/src/views/DappMethods/package.json b/js/src/views/DappMethods/package.json
new file mode 100644
index 000000000..7116205b8
--- /dev/null
+++ b/js/src/views/DappMethods/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "@parity/view-dapp-methods",
+ "description": "Parity default dapp method selection",
+ "version": "0.0.0",
+ "main": "index.js",
+ "author": "Parity Team ",
+ "maintainers": [],
+ "contributors": [],
+ "license": "GPL-3.0",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/paritytech/parity.git"
+ },
+ "keywords": [],
+ "scripts": {},
+ "devDependencies": {},
+ "dependencies": {},
+ "peerDependencies": {}
+}
diff --git a/js/src/views/DappMethods/store.js b/js/src/views/DappMethods/store.js
new file mode 100644
index 000000000..c74b4d869
--- /dev/null
+++ b/js/src/views/DappMethods/store.js
@@ -0,0 +1,73 @@
+// 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 .
+
+import { action, observable } from 'mobx';
+
+export default class Store {
+ @observable apps= [];
+ @observable methods = [];
+ @observable permissions = {};
+
+ constructor (api) {
+ this._api = api;
+
+ this.loadInitialise();
+ }
+
+ @action setApps = (apps) => {
+ this.apps = apps;
+ }
+
+ @action setMethods = (methods) => {
+ this.methods = methods;
+ }
+
+ @action setPermissions = (permissions) => {
+ this.permissions = permissions;
+ }
+
+ @action toggleAppPermission = (method, appId) => {
+ const id = `${method}:${appId}`;
+
+ this.permissions = Object.assign({}, this.permissions, {
+ [id]: !this.permissions[id]
+ });
+
+ this.savePermissions();
+ }
+
+ hasAppPermission = (method, appId) => {
+ return this.permissions[`${method}:${appId}`] || false;
+ }
+
+ loadInitialise = () => {
+ return Promise
+ .all([
+ this._api.shell.getApps(false),
+ this._api.shell.getFilteredMethods(),
+ this._api.shell.getMethodPermissions()
+ ])
+ .then(([apps, methods, permissions]) => {
+ this.setApps(apps);
+ this.setMethods(methods);
+ this.setPermissions(permissions);
+ });
+ }
+
+ savePermissions = () => {
+ this._api.shell.setMethodPermissions(this.permissions);
+ }
+}
diff --git a/js/src/views/DappVisible/api.js b/js/src/views/DappVisible/api.js
new file mode 100644
index 000000000..6ad6cd0fe
--- /dev/null
+++ b/js/src/views/DappVisible/api.js
@@ -0,0 +1,21 @@
+// 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 .
+
+import Api from '@parity/api';
+
+const ethereumProvider = window.ethereum || window.parent.ethereum;
+
+export default new Api(ethereumProvider);
diff --git a/js/src/shell/Dapps/SelectVisible/selectVisible.css b/js/src/views/DappVisible/dappVisible.css
similarity index 100%
rename from js/src/shell/Dapps/SelectVisible/selectVisible.css
rename to js/src/views/DappVisible/dappVisible.css
diff --git a/js/src/shell/Dapps/SelectVisible/selectVisible.js b/js/src/views/DappVisible/dappVisible.js
similarity index 80%
rename from js/src/shell/Dapps/SelectVisible/selectVisible.js
rename to js/src/views/DappVisible/dappVisible.js
index da8bba1c5..e84297ab7 100644
--- a/js/src/shell/Dapps/SelectVisible/selectVisible.js
+++ b/js/src/views/DappVisible/dappVisible.js
@@ -18,28 +18,22 @@ import { observer } from 'mobx-react';
import React, { Component, PropTypes } from 'react';
import { FormattedMessage } from 'react-intl';
-import { DappCard, Portal, SelectionList } from '@parity/ui';
+import { DappCard, Page, SelectionList } from '@parity/ui';
-import styles from './selectVisible.css';
+import Store from './store';
+import styles from './dappVisible.css';
@observer
-export default class SelectVisible extends Component {
- static propTypes = {
- store: PropTypes.object.isRequired
+export default class DappVisible extends Component {
+ static contextTypes = {
+ api: PropTypes.object.isRequired
};
+ store = new Store(this.context.api);
+
render () {
- const { store } = this.props;
-
- if (!store.modalOpen) {
- return null;
- }
-
return (
-
{
- this.renderList(store.sortedLocal, store.displayApps,
+ this.renderList(this.store.sortedLocal, this.store.displayApps,
)
}
-
+
);
}
@@ -120,18 +114,14 @@ export default class SelectVisible extends Component {
}
isVisible = (app) => {
- const { store } = this.props;
-
- return store.displayApps[app.id].visible;
+ return (this.store.displayApps[app.id] && this.store.displayApps[app.id].visible) || false;
}
onSelect = (app) => {
- const { store } = this.props;
-
if (this.isVisible(app)) {
- store.hideApp(app.id);
+ this.store.hideApp(app.id);
} else {
- store.showApp(app.id);
+ this.store.showApp(app.id);
}
}
}
diff --git a/js/src/views/DappVisible/index.js b/js/src/views/DappVisible/index.js
new file mode 100644
index 000000000..f90151bfa
--- /dev/null
+++ b/js/src/views/DappVisible/index.js
@@ -0,0 +1,39 @@
+// 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 .
+
+import ReactDOM from 'react-dom';
+import React from 'react';
+import { Route, Router, hashHistory } from 'react-router';
+
+import injectTapEventPlugin from 'react-tap-event-plugin';
+injectTapEventPlugin();
+
+import { initStore } from '@parity/shared/redux';
+import ContextProvider from '@parity/ui/ContextProvider';
+
+import api from './api';
+import DappVisible from './dappVisible';
+
+const store = initStore(api, hashHistory);
+
+ReactDOM.render(
+
+
+
+
+ ,
+ document.querySelector('#container')
+);
diff --git a/js/src/views/DappVisible/package.json b/js/src/views/DappVisible/package.json
new file mode 100644
index 000000000..b0856ba34
--- /dev/null
+++ b/js/src/views/DappVisible/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "@parity/view-dapp-visible",
+ "description": "Parity default dapp visibility selection",
+ "version": "0.0.0",
+ "main": "index.js",
+ "author": "Parity Team ",
+ "maintainers": [],
+ "contributors": [],
+ "license": "GPL-3.0",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/paritytech/parity.git"
+ },
+ "keywords": [],
+ "scripts": {},
+ "devDependencies": {},
+ "dependencies": {},
+ "peerDependencies": {}
+}
diff --git a/js/src/views/DappVisible/store.js b/js/src/views/DappVisible/store.js
new file mode 100644
index 000000000..0c4b2b9ef
--- /dev/null
+++ b/js/src/views/DappVisible/store.js
@@ -0,0 +1,101 @@
+// 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 .
+
+import { action, computed, observable } from 'mobx';
+
+export default class DappsStore {
+ @observable apps = [];
+ @observable displayApps = {};
+
+ _api = null;
+
+ constructor (api) {
+ this._api = api;
+
+ this.loadApps();
+ }
+
+ @computed get sortedBuiltin () {
+ return this.apps.filter((app) => app.type === 'builtin');
+ }
+
+ @computed get sortedLocal () {
+ return this.apps.filter((app) => app.type === 'local');
+ }
+
+ @computed get sortedNetwork () {
+ return this.apps.filter((app) => app.type === 'network');
+ }
+
+ @computed get visibleApps () {
+ return this.apps.filter((app) => this.displayApps[app.id] && this.displayApps[app.id].visible);
+ }
+
+ @computed get visibleBuiltin () {
+ return this.visibleApps.filter((app) => !app.noselect && app.type === 'builtin');
+ }
+
+ @computed get visibleLocal () {
+ return this.visibleApps.filter((app) => app.type === 'local');
+ }
+
+ @computed get visibleNetwork () {
+ return this.visibleApps.filter((app) => app.type === 'network');
+ }
+
+ @computed get visibleViews () {
+ return this.visibleApps.filter((app) => !app.noselect && app.type === 'view');
+ }
+
+ @action setApps = (apps) => {
+ this.apps = apps;
+ }
+
+ @action setDisplayApps = (displayApps) => {
+ this.displayApps = Object.assign({}, this.displayApps, displayApps);
+ };
+
+ @action hideApp = (id) => {
+ this.setDisplayApps({ [id]: { visible: false } });
+ this._api.shell.setAppVisibility(id, false);
+ }
+
+ @action showApp = (id) => {
+ this.setDisplayApps({ [id]: { visible: true } });
+ this._api.shell.setAppVisibility(id, true);
+ }
+
+ getAppById = (id) => {
+ return this.apps.find((app) => app.id === id);
+ }
+
+ loadApps () {
+ return Promise
+ .all([
+ this._api.shell.getApps(true),
+ this._api.shell.getApps(false)
+ ])
+ .then(([all, displayed]) => {
+ this.setDisplayApps(
+ displayed.reduce((result, { id }) => {
+ result[id] = { visible: true };
+ return result;
+ }, {})
+ );
+ this.setApps(all);
+ });
+ }
+}