relocate to packages (+ Tab semantic ui v.7.1)
This commit is contained in:
parent
381ed505a0
commit
c894f7ac1f
@ -17,8 +17,8 @@
|
|||||||
import EventEmitter from 'eventemitter3';
|
import EventEmitter from 'eventemitter3';
|
||||||
|
|
||||||
import Contract from './contract';
|
import Contract from './contract';
|
||||||
import { PromiseProvider, Http as HttpProvider, PostMessage as PostMessageProvider, WsSecure as WsSecureProvider } from './provider';
|
import { PromiseProvider, Http as HttpProvider, PostMessage as PostMessageProvider, Ws as WsProvider } from './provider';
|
||||||
import { Http as HttpTransport, WsSecure as WsSecureTransport } from './transport';
|
import { Http as HttpTransport, Ws as WsTransport } from './transport';
|
||||||
|
|
||||||
import { Db, Eth, Parity, Net, Personal, Shell, Shh, Signer, Trace, Web3 } from './rpc';
|
import { Db, Eth, Parity, Net, Personal, Shell, Shh, Signer, Trace, Web3 } from './rpc';
|
||||||
import Subscriptions from './subscriptions';
|
import Subscriptions from './subscriptions';
|
||||||
@ -36,7 +36,6 @@ export default class Api extends EventEmitter {
|
|||||||
console.log(provider);
|
console.log(provider);
|
||||||
console.warn(new Error('deprecated: Api needs provider with send() function, old-style Transport found instead'));
|
console.warn(new Error('deprecated: Api needs provider with send() function, old-style Transport found instead'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// does use new provider interface (not promiseProvider)
|
// does use new provider interface (not promiseProvider)
|
||||||
if (provider && isFunction(provider.subscribe)) {
|
if (provider && isFunction(provider.subscribe)) {
|
||||||
this._pubsub = new Pubsub(provider);
|
this._pubsub = new Pubsub(provider);
|
||||||
@ -187,12 +186,12 @@ export default class Api extends EventEmitter {
|
|||||||
static Provider = {
|
static Provider = {
|
||||||
Http: HttpProvider,
|
Http: HttpProvider,
|
||||||
PostMessage: PostMessageProvider,
|
PostMessage: PostMessageProvider,
|
||||||
WsSecure: WsSecureProvider
|
Ws: WsProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: kept for backwards compatibility
|
// NOTE: kept for backwards compatibility
|
||||||
static Transport = {
|
static Transport = {
|
||||||
Http: HttpTransport,
|
Http: HttpTransport,
|
||||||
WsSecure: WsSecureTransport
|
Ws: WsTransport
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
js/packages/ui/Form/Tab/index.js
Normal file
17
js/packages/ui/Form/Tab/index.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
|
export default from './tab';
|
42
js/packages/ui/Form/Tab/tab.js
Normal file
42
js/packages/ui/Form/Tab/tab.js
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import React, { PropTypes } from 'react';
|
||||||
|
|
||||||
|
import { Tab as SemanticTab } from 'semantic-ui-react';
|
||||||
|
|
||||||
|
export default function Tab ({ activeIndex, as, defaultActiveIndex, menu, onTabChange, panes, label }) {
|
||||||
|
return (
|
||||||
|
<SemanticTab
|
||||||
|
activeIndex={ activeIndex }
|
||||||
|
as={ as }
|
||||||
|
defaultActiveIndex={ defaultActiveIndex }
|
||||||
|
menu={ menu }
|
||||||
|
onTabChange={ onTabChange }
|
||||||
|
panes={ panes }
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Tab.propTypes = {
|
||||||
|
activeIndex: PropTypes.number || PropTypes.string,
|
||||||
|
as: PropTypes.any,
|
||||||
|
defaultActiveIndex: PropTypes.number || PropTypes.string,
|
||||||
|
menu: PropTypes.number,
|
||||||
|
onTabChange: PropTypes.func,
|
||||||
|
panes: PropTypes.array,
|
||||||
|
label: PropTypes.node
|
||||||
|
};
|
@ -29,5 +29,6 @@ export RadioButtons from './RadioButtons';
|
|||||||
export Toggle from './Toggle';
|
export Toggle from './Toggle';
|
||||||
export TypedInput from './TypedInput';
|
export TypedInput from './TypedInput';
|
||||||
export VaultSelect from './VaultSelect';
|
export VaultSelect from './VaultSelect';
|
||||||
|
export Tab from './Tab';
|
||||||
|
|
||||||
export default from './form';
|
export default from './form';
|
||||||
|
@ -33,7 +33,7 @@ export DappIcon from './DappIcon';
|
|||||||
export DappLink from './DappLink';
|
export DappLink from './DappLink';
|
||||||
export Errors from './Errors';
|
export Errors from './Errors';
|
||||||
export Features, { FEATURES, FeaturesStore } from './Features';
|
export Features, { FEATURES, FeaturesStore } from './Features';
|
||||||
export Form, { AddressSelect, Checkbox, DappUrlInput, Dropdown, FileSelect, Input, InputAddress, InputAddressSelect, InputChip, InputDateTime, Label, RadioButtons, Slider, Toggle, TypedInput, VaultSelect } from './Form';
|
export Form, { AddressSelect, Checkbox, DappUrlInput, Dropdown, FileSelect, Input, InputAddress, InputAddressSelect, InputChip, InputDateTime, Label, RadioButtons, Slider, Toggle, TypedInput, VaultSelect, Tab } from './Form';
|
||||||
export GasPriceEditor from './GasPriceEditor';
|
export GasPriceEditor from './GasPriceEditor';
|
||||||
export GasPriceSelector from './GasPriceSelector';
|
export GasPriceSelector from './GasPriceSelector';
|
||||||
export IconCache from './IconCache';
|
export IconCache from './IconCache';
|
||||||
@ -61,7 +61,6 @@ export Snackbar from './Snackbar';
|
|||||||
export StatusIndicator from './StatusIndicator';
|
export StatusIndicator from './StatusIndicator';
|
||||||
export Tabs from './Tabs';
|
export Tabs from './Tabs';
|
||||||
export Tags from './Tags';
|
export Tags from './Tags';
|
||||||
export Theme from './Theme';
|
|
||||||
export Title from './Title';
|
export Title from './Title';
|
||||||
export TokenImage from './TokenImage';
|
export TokenImage from './TokenImage';
|
||||||
export TxHash from './TxHash';
|
export TxHash from './TxHash';
|
||||||
|
@ -1,197 +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 EventEmitter from 'eventemitter3';
|
|
||||||
|
|
||||||
import Contract from './contract';
|
|
||||||
import { PromiseProvider, Http as HttpProvider, PostMessage as PostMessageProvider, Ws as WsProvider } from './provider';
|
|
||||||
import { Http as HttpTransport, Ws as WsTransport } from './transport';
|
|
||||||
|
|
||||||
import { Db, Eth, Parity, Net, Personal, Shell, Shh, Signer, Trace, Web3 } from './rpc';
|
|
||||||
import Subscriptions from './subscriptions';
|
|
||||||
import Pubsub from './pubsub';
|
|
||||||
import util from './util';
|
|
||||||
import { isFunction } from './util/types';
|
|
||||||
|
|
||||||
import LocalAccountsMiddleware from '~/api/local';
|
|
||||||
|
|
||||||
export default class Api extends EventEmitter {
|
|
||||||
constructor (provider, allowSubscriptions = true) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
if (!provider || !isFunction(provider.send)) {
|
|
||||||
console.log(provider);
|
|
||||||
console.warn(new Error('deprecated: Api needs provider with send() function, old-style Transport found instead'));
|
|
||||||
}
|
|
||||||
// does use new provider interface (not promiseProvider)
|
|
||||||
if (provider && isFunction(provider.subscribe)) {
|
|
||||||
this._pubsub = new Pubsub(provider);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._provider = new PromiseProvider(provider);
|
|
||||||
|
|
||||||
this._db = new Db(this._provider);
|
|
||||||
this._eth = new Eth(this._provider);
|
|
||||||
this._net = new Net(this._provider);
|
|
||||||
this._parity = new Parity(this._provider);
|
|
||||||
this._personal = new Personal(this._provider);
|
|
||||||
this._shell = new Shell(this._provider);
|
|
||||||
this._shh = new Shh(this._provider);
|
|
||||||
this._signer = new Signer(this._provider);
|
|
||||||
this._trace = new Trace(this._provider);
|
|
||||||
this._web3 = new Web3(this._provider);
|
|
||||||
|
|
||||||
if (allowSubscriptions) {
|
|
||||||
this._subscriptions = new Subscriptions(this);
|
|
||||||
}
|
|
||||||
// Doing a request here in test env would cause an error
|
|
||||||
if (LocalAccountsMiddleware && process.env.NODE_ENV !== 'test') {
|
|
||||||
const middleware = this.parity
|
|
||||||
.nodeKind()
|
|
||||||
.then((nodeKind) => {
|
|
||||||
if (nodeKind.availability === 'public') {
|
|
||||||
return LocalAccountsMiddleware;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
})
|
|
||||||
.catch(() => null);
|
|
||||||
|
|
||||||
provider.addMiddleware(middleware);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
get pubsub () {
|
|
||||||
if (!this._pubsub) {
|
|
||||||
throw Error('Pubsub is only available with a subscribing-supported transport injected!');
|
|
||||||
}
|
|
||||||
return this._pubsub;
|
|
||||||
}
|
|
||||||
|
|
||||||
get db () {
|
|
||||||
return this._db;
|
|
||||||
}
|
|
||||||
|
|
||||||
get eth () {
|
|
||||||
return this._eth;
|
|
||||||
}
|
|
||||||
|
|
||||||
get parity () {
|
|
||||||
return this._parity;
|
|
||||||
}
|
|
||||||
|
|
||||||
get net () {
|
|
||||||
return this._net;
|
|
||||||
}
|
|
||||||
|
|
||||||
get personal () {
|
|
||||||
return this._personal;
|
|
||||||
}
|
|
||||||
|
|
||||||
get provider () {
|
|
||||||
return this._provider.provider;
|
|
||||||
}
|
|
||||||
|
|
||||||
get shell () {
|
|
||||||
return this._shell;
|
|
||||||
}
|
|
||||||
|
|
||||||
get shh () {
|
|
||||||
return this._shh;
|
|
||||||
}
|
|
||||||
|
|
||||||
get signer () {
|
|
||||||
return this._signer;
|
|
||||||
}
|
|
||||||
|
|
||||||
get trace () {
|
|
||||||
return this._trace;
|
|
||||||
}
|
|
||||||
|
|
||||||
get transport () {
|
|
||||||
return this.provider;
|
|
||||||
}
|
|
||||||
|
|
||||||
get web3 () {
|
|
||||||
return this._web3;
|
|
||||||
}
|
|
||||||
|
|
||||||
get util () {
|
|
||||||
return util;
|
|
||||||
}
|
|
||||||
|
|
||||||
newContract (abi, address) {
|
|
||||||
return new Contract(this, abi).at(address);
|
|
||||||
}
|
|
||||||
|
|
||||||
subscribe (subscriptionName, callback) {
|
|
||||||
if (!this._subscriptions) {
|
|
||||||
return Promise.resolve(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._subscriptions.subscribe(subscriptionName, callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsubscribe (subscriptionId) {
|
|
||||||
if (!this._subscriptions) {
|
|
||||||
return Promise.resolve(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this._subscriptions.unsubscribe(subscriptionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
pollMethod (method, input, validate) {
|
|
||||||
const [_group, endpoint] = method.split('_');
|
|
||||||
const group = `_${_group}`;
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const timeout = () => {
|
|
||||||
this[group][endpoint](input)
|
|
||||||
.then((result) => {
|
|
||||||
if (validate ? validate(result) : result) {
|
|
||||||
resolve(result);
|
|
||||||
} else {
|
|
||||||
setTimeout(timeout, 500);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
// Don't print if the request is rejected: that's ok
|
|
||||||
if (error.type !== 'REQUEST_REJECTED') {
|
|
||||||
console.error('pollMethod', error);
|
|
||||||
}
|
|
||||||
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
timeout();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static util = util
|
|
||||||
|
|
||||||
static Provider = {
|
|
||||||
Http: HttpProvider,
|
|
||||||
PostMessage: PostMessageProvider,
|
|
||||||
Ws: WsProvider
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: kept for backwards compatibility
|
|
||||||
static Transport = {
|
|
||||||
Http: HttpTransport,
|
|
||||||
Ws: WsTransport
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,100 +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/>.
|
|
||||||
|
|
||||||
export default class PostMessage {
|
|
||||||
id = 0;
|
|
||||||
_messages = {};
|
|
||||||
|
|
||||||
constructor (token, destination) {
|
|
||||||
this._token = token;
|
|
||||||
this._destination = destination;
|
|
||||||
|
|
||||||
window.addEventListener('message', this.receiveMessage, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
addMiddleware () {
|
|
||||||
}
|
|
||||||
|
|
||||||
_send (data) {
|
|
||||||
this._destination.postMessage(data, '*');
|
|
||||||
}
|
|
||||||
|
|
||||||
send = (method, params, callback) => {
|
|
||||||
const id = ++this.id;
|
|
||||||
|
|
||||||
this._messages[id] = { callback };
|
|
||||||
this._send({
|
|
||||||
id,
|
|
||||||
from: this._token,
|
|
||||||
method,
|
|
||||||
params,
|
|
||||||
token: this._token
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
subscribe = (api, callback, params) => {
|
|
||||||
console.log('paritySubscribe', JSON.stringify(params), api, callback);
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const id = ++this.id;
|
|
||||||
|
|
||||||
this._messages[id] = { callback, resolve, reject, subscription: true, initial: true };
|
|
||||||
this._send({
|
|
||||||
id,
|
|
||||||
from: this._token,
|
|
||||||
api,
|
|
||||||
params,
|
|
||||||
token: this._token
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
unsubscribe = (subId) => {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const id = ++this.id;
|
|
||||||
|
|
||||||
this._messages[id] = { callback: (e, v) => e ? reject(e) : resolve(v) };
|
|
||||||
this._send({
|
|
||||||
id,
|
|
||||||
from: this._token,
|
|
||||||
subId,
|
|
||||||
token: this._token
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
unsubscribeAll () {
|
|
||||||
return this.unsubscribe('*');
|
|
||||||
}
|
|
||||||
|
|
||||||
receiveMessage = ({ data: { id, error, from, token, result }, origin, source }) => {
|
|
||||||
if (from !== 'shell' || token !== this._token) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error) {
|
|
||||||
console.error(from, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this._messages[id].subscription) {
|
|
||||||
console.log('subscription', result, 'initial?', this._messages[id].initial);
|
|
||||||
this._messages[id].initial ? this._messages[id].resolve(result) : this._messages[id].callback(error && new Error(error), result);
|
|
||||||
this._messages[id].initial = false;
|
|
||||||
} else {
|
|
||||||
this._messages[id].callback(error && new Error(error), result);
|
|
||||||
this._messages[id] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
37
js/src/library.parity.js
Normal file
37
js/src/library.parity.js
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// 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 es6Promise from 'es6-promise';
|
||||||
|
es6Promise.polyfill();
|
||||||
|
|
||||||
|
const isNode = typeof global !== 'undefined' && typeof global !== 'undefined';
|
||||||
|
const isBrowser = typeof self !== 'undefined' && typeof self.window !== 'undefined';
|
||||||
|
|
||||||
|
if (isBrowser) {
|
||||||
|
require('whatwg-fetch');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNode) {
|
||||||
|
global.fetch = require('node-fetch');
|
||||||
|
}
|
||||||
|
|
||||||
|
import Abi from '@parity/abi';
|
||||||
|
import Api from '@parity/api';
|
||||||
|
|
||||||
|
const Parity = { Api, Abi };
|
||||||
|
|
||||||
|
export default Parity;
|
||||||
|
export { Api, Abi };
|
Loading…
Reference in New Issue
Block a user