Ui 2 packages (#6169)

* Ensure all internal dapps have package.json

* Update compilation rules

# Conflicts:
#	js/src/redux/providers/balancesActions.js
#	js/src/ui/Form/TypedInput/typedInput.js

* Remove SignerIcon

* Cleanup providers

* Enable request of new token from app

* Queue when no token (yet)

* Add location & token request

* Cleanup send logic

* Request token

* Request comms token

* Remove yarn.lock (not updated)

* Update version to 1.99.99 (publish prepare)

* Move jsonrpc to seperate repo

* Update jsonrpc references

* Update repo info

* Update repo info

* Additional debugging

* Update repo references

* Move ABI to js-abi repo

* Move webWorker to shared

* Fix package reference

* Worker location

* Move js-ui & js-shared components

* Update file references

* Update package repo locations

* Remove debugging info

* Cleanup debug

* Split api into own repo

* Update api local references

* Update app loading

* Update dependencies

* Allow serving of /parity-utils

* Error when EthereumProvider has not been attached

* Use inject.js

* Correct appId retrieval
This commit is contained in:
Jaco Greeff
2017-07-28 10:25:34 +02:00
committed by GitHub
parent 5830767273
commit a1b8fabd99
782 changed files with 530 additions and 64912 deletions

View File

@@ -74,7 +74,7 @@ export default class Store {
}
@action queueRequest = (request) => {
const appId = this.tokens[request.data.from];
const appId = this.tokens[request.data.token];
let queueId = ++nextQueueId;
this.requests = this.requests.concat([{ appId, queueId, request }]);
@@ -114,14 +114,19 @@ export default class Store {
}
@action rejectRequest = (queueId) => {
const { request: { data: { id, method, token }, source } } = this.findRequest(queueId);
const { request } = this.findRequest(queueId);
this.removeRequest(queueId);
this.rejectMessage(request);
}
@action rejectMessage = (source, { id, from, method, token }) => {
source.postMessage({
error: `Method ${method} not allowed`,
id,
from: 'shell',
result: null,
to: from,
token
}, '*');
}
@@ -139,6 +144,14 @@ export default class Store {
return true;
}
hasValidToken = (method, appId, token) => {
if (!token) {
return method === 'shell_requestNewToken';
}
return this.tokens[token] === appId;
}
hasTokenPermission = (method, token) => {
return this.hasAppPermission(method, this.tokens[token]);
}
@@ -159,7 +172,7 @@ export default class Store {
return this.requests.filter(({ request: { data: { method, token, params } } }) => (method === _method || (params && params[0] === _method)) && token === _token);
}
_methodCallbackPost = (id, source, token) => {
_methodCallbackPost = (id, from, source, token) => {
return (error, result) => {
source.postMessage({
error: error
@@ -167,25 +180,26 @@ export default class Store {
: null,
id,
from: 'shell',
to: from,
result,
token
}, '*');
};
}
executePubsubCall = ({ api, id, token, params }, source) => {
const callback = this._methodCallbackPost(id, source, token);
executePubsubCall = ({ api, id, from, token, params }, source) => {
const callback = this._methodCallbackPost(id, from, source, token);
// TODO: enable security pubsub
this.provider.subscribe(api, callback, params).then((v, e) => {
console.log('Error and result', v, e);
this._methodCallbackPost(id, source, token)(null, v);
this._methodCallbackPost(id, from, source, token)(null, v);
});
}
executeMethodCall = ({ id, from, method, params, token }, source) => {
executeMethodCall = ({ appId, id, from, method, params, token }, source) => {
const visibleStore = VisibleStore.get();
const callback = this._methodCallbackPost(id, source, token);
const callback = this._methodCallbackPost(id, from, source, token);
switch (method) {
case 'shell_getApps':
@@ -206,6 +220,9 @@ export default class Store {
case 'shell_getMethodPermissions':
return callback(null, this.permissions);
case 'shell_requestNewToken':
return callback(null, this.createToken(from));
case 'shell_setAppVisibility':
const [appId, visibility] = params;
@@ -239,9 +256,14 @@ export default class Store {
return;
}
const { from, method, token, params, api, subId, id } = data;
const { from, method, to, token, params, api, subId, id } = data;
if (!from || from === 'shell' || from !== token) {
if (to !== 'shell' || !from || from === 'shell') {
return;
}
if (!this.hasValidToken(method, from, token)) {
this.rejectMessage(source, data);
return;
}
@@ -250,13 +272,13 @@ export default class Store {
this.queueRequest({ data, origin, source });
return;
}
if (api) {
console.log('apiCall', data);
this.executePubsubCall(data, source);
} else if (subId) {
subId === '*'
? this.provider.unsubscribeAll().then(v => this._methodCallbackPost(id, source, token)(null, v))
: this.provider.unsubscribe(subId).then(v => this._methodCallbackPost(id, source, token)(null, v));
? this.provider.unsubscribeAll().then(v => this._methodCallbackPost(id, from, source, token)(null, v))
: this.provider.unsubscribe(subId).then(v => this._methodCallbackPost(id, from, source, token)(null, v));
} else {
this.executeMethodCall(data, source);
}

View File

@@ -27,7 +27,6 @@ import { IndexRoute, Redirect, Route, Router, hashHistory } from 'react-router';
import qs from 'querystring';
import Api from '@parity/api';
import Abi from '@parity/abi';
import builtinDapps from '@parity/shared/config/dappsBuiltin.json';
import viewsDapps from '@parity/shared/config/dappsViews.json';
import ContractInstances from '@parity/shared/contracts';
@@ -40,14 +39,12 @@ import '@parity/shared/environment';
import Application from './Application';
import Dapp from './Dapp';
import { setupProviderFilters, Store as DappRequestsStore } from './DappRequests';
import { setupProviderFilters } from './DappRequests';
import Dapps from './Dapps';
import SecureApi from './secureApi';
injectTapEventPlugin();
console.log('UI version', process.env.UI_VERSION);
if (process.env.NODE_ENV === 'development') {
// Expose the React Performance Tools on the`window` object
const Perf = require('react-addons-perf');
@@ -73,27 +70,25 @@ setupProviderFilters(api.provider);
const store = initStore(api, hashHistory);
const dapps = [].concat(viewsDapps, builtinDapps);
const dapps = [].concat(viewsDapps, builtinDapps).map((app) => {
if (app.id && app.id.substr(0, 2) !== '0x') {
app.id = Api.util.sha3(app.id);
}
return app;
});
const dappsHistory = HistoryStore.get('dapps');
function onEnterDapp ({ params: { id } }) {
const token = DappRequestsStore.get().createToken(id);
// on app switch unsubscribe all subscriptions
if (window.ethereum) {
window.ethereum.unsubscribeAll();
}
// old API uses window.parity
window.parity = { Api, Abi };
window.ethereum = new Api.Provider.PostMessage(token, window);
if (!dapps[id] || !dapps[id].skipHistory) {
dappsHistory.add(id);
}
}
console.log('UI version', process.env.UI_VERSION);
console.log('Loaded dapps', dapps);
ReactDOM.render(
<ContextProvider api={ api } store={ store }>
<Router history={ hashHistory }>

View File

@@ -14,5 +14,74 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import './parity';
import './web3';
import 'whatwg-fetch';
import es6Promise from 'es6-promise';
es6Promise.polyfill();
import Api from '@parity/api';
import Web3 from 'web3';
import web3extensions from './web3.extensions';
function initProvider () {
let [, appId] = window.location.pathname.split('/');
if (appId.indexOf('.html') !== -1) {
appId = appId.replace('.html', '');
}
if (appId.substr(0, 2) !== '0x') {
appId = Api.util.sha3(appId);
}
const ethereum = new Api.Provider.PostMessage(appId);
console.log(`Requesting communications token for ${appId}`);
ethereum
.requestNewToken()
.then((tokenId) => {
console.log(`Received new communications token ${tokenId}`);
})
.catch((error) => {
console.error('Unable to retrieve communications token', error);
});
window.ethereum = ethereum;
return ethereum;
}
function initWeb3 (ethereum) {
// FIXME: Use standard provider for web3
const http = new Web3.providers.HttpProvider('/rpc/');
const web3 = new Web3(http);
// set default account
web3.eth.getAccounts((error, accounts) => {
if (error || !accounts || !accounts[0]) {
return;
}
web3.eth.defaultAccount = accounts[0];
});
web3extensions(web3).map((extension) => web3._extend(extension));
window.web3 = web3;
}
function initParity (ethereum) {
const api = new Api(ethereum);
window.parity = {
Api,
api
};
}
const ethereum = initProvider();
initWeb3(ethereum);
initParity(ethereum);

View File

@@ -1,33 +0,0 @@
// 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 'whatwg-fetch';
import es6Promise from 'es6-promise';
es6Promise.polyfill();
import Api from '@parity/api';
import './dev.parity.html';
const ethereumProvider = new Api.Provider.Http('/rpc/');
const api = new Api(ethereumProvider);
window.parity = {
Api,
api,
ethereumProvider
};

View File

@@ -1,36 +0,0 @@
// 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 Web3 from 'web3';
import web3extensions from './web3.extensions';
import './dev.web3.html';
const http = new Web3.providers.HttpProvider('/rpc/');
const web3 = new Web3(http);
// set default account
web3.eth.getAccounts((err, accounts) => {
if (err || !accounts || !accounts[0]) {
return;
}
web3.eth.defaultAccount = accounts[0];
});
web3extensions(web3).map((extension) => web3._extend(extension));
global.web3 = web3;

View File

@@ -1,109 +0,0 @@
// 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 registerPromiseWorker from 'promise-worker/register';
import { Signer } from '@parity/shared/util/signer';
import SolidityUtils from '@parity/shared/util/solidity';
registerPromiseWorker((msg) => {
return handleMessage(msg);
});
self.compiler = {
version: null,
compiler: null
};
self.files = {};
function handleMessage (message) {
switch (message.action) {
case 'compile':
return compile(message.data);
case 'load':
return getCompiler(message.data).then(() => 'ok');
case 'setFiles':
return setFiles(message.data);
case 'getSignerSeed':
return getSignerSeed(message.data);
default:
console.warn(`unknown action "${message.action}"`);
return null;
}
}
function getSignerSeed (data) {
console.log('deriving seed from service-worker');
const { wallet, password } = data;
return Signer.getSeed(wallet, password);
}
function compile (data) {
const { build } = data;
return getCompiler(build)
.then((compiler) => {
console.warn('compiling');
return SolidityUtils.compile(data, compiler);
})
.then((result) => {
console.warn('result in worker', result);
return result;
})
.catch((error) => {
console.error('error in worker', error);
throw error;
});
}
function setFiles (files) {
const prevFiles = self.files;
const nextFiles = files.reduce((obj, file) => {
obj[file.name] = file.sourcecode;
return obj;
}, {});
self.files = {
...prevFiles,
...nextFiles
};
return 'ok';
}
function getCompiler (build) {
const { longVersion } = build;
if (self.compiler.version !== longVersion) {
self.compiler.version = longVersion;
self.compiler.compiler = SolidityUtils
.getCompiler(build)
.then((compiler) => {
if (self.compiler.version === longVersion) {
self.compiler.compiler = compiler;
}
return compiler;
});
}
return Promise.resolve(self.compiler.compiler);
}