Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Backporting to beta #3239

Merged
merged 4 commits into from
Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"devDependencies": {
"babel-cli": "^6.10.1",
"babel-core": "^6.10.4",
"babel-eslint": "^6.1.2",
"babel-eslint": "^7.1.0",
"babel-loader": "^6.2.3",
"babel-plugin-lodash": "^3.2.2",
"babel-plugin-transform-class-properties": "^6.11.5",
Expand Down Expand Up @@ -126,6 +126,9 @@
"marked": "^0.3.6",
"material-ui": "^0.16.1",
"material-ui-chip-input": "^0.8.0",
"mobx": "^2.6.1",
"mobx-react": "^3.5.8",
"mobx-react-devtools": "^4.2.9",
"moment": "^2.14.1",
"qs": "^6.3.0",
"react": "^15.2.1",
Expand Down
4 changes: 4 additions & 0 deletions js/src/contracts/dappreg.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ export default class DappReg {
getContent (id) {
return this.meta(id, 'CONTENT');
}

getManifest (id) {
return this.meta(id, 'MANIFEST');
}
}
53 changes: 10 additions & 43 deletions js/src/views/Dapp/dapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import React, { Component, PropTypes } from 'react';
import { observer } from 'mobx-react';

import Contracts from '../../contracts';
import { fetchAvailable } from '../Dapps/registry';
import DappsStore from '../Dapps/dappsStore';

import styles from './dapp.css';

@observer
export default class Dapp extends Component {
static contextTypes = {
api: PropTypes.object.isRequired
Expand All @@ -30,38 +31,30 @@ export default class Dapp extends Component {
params: PropTypes.object
};

state = {
app: null
}

componentWillMount () {
this.lookup();
}
store = new DappsStore(this.context.api);

render () {
const { app } = this.state;
const { dappsUrl } = this.context.api;
const { id } = this.props.params;
const app = this.store.apps.find((app) => app.id === id);

if (!app) {
return null;
}

let src = null;
switch (app.type) {
case 'builtin':
const dapphost = process.env.NODE_ENV === 'production' && !app.secure
? `${dappsUrl}/ui`
: '';
src = `${dapphost}/${app.url}.html`;
break;
case 'local':
src = `${dappsUrl}/${app.id}/`;
break;
case 'network':
src = `${dappsUrl}/${app.contentHash}/`;
break;
default:
console.error('unknown type', app.type);
const dapphost = process.env.NODE_ENV === 'production' && !app.secure
? `${dappsUrl}/ui`
: '';
src = `${dapphost}/${app.url}.html`;
break;
}

Expand All @@ -76,30 +69,4 @@ export default class Dapp extends Component {
</iframe>
);
}

lookup () {
const { api } = this.context;
const { id } = this.props.params;
const { dappReg } = Contracts.get();

fetchAvailable(api)
.then((available) => {
return available.find((app) => app.id === id);
})
.then((app) => {
if (app.type !== 'network') {
return app;
}

return dappReg
.getContent(app.id)
.then((contentHash) => {
app.contentHash = api.util.bytesToHex(contentHash).substr(2);
return app;
});
})
.then((app) => {
this.setState({ app });
});
}
}
53 changes: 32 additions & 21 deletions js/src/views/Dapps/AddDapps/AddDapps.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import React, { Component, PropTypes } from 'react';
import { observer } from 'mobx-react';
import DoneIcon from 'material-ui/svg-icons/action/done';
import { List, ListItem } from 'material-ui/List';
import Checkbox from 'material-ui/Checkbox';
Expand All @@ -23,57 +24,67 @@ import { Modal, Button } from '../../../ui';

import styles from './AddDapps.css';

@observer
export default class AddDapps extends Component {
static propTypes = {
available: PropTypes.array.isRequired,
hidden: PropTypes.array.isRequired,
open: PropTypes.bool.isRequired,
onHideApp: PropTypes.func.isRequired,
onShowApp: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired
store: PropTypes.object.isRequired
};

render () {
const { onClose, open, available } = this.props;
const { store } = this.props;

if (!store.modalOpen) {
return null;
}

return (
<Modal
compact
title='visible applications'
actions={ [
<Button label={ 'Done' } key='done' onClick={ onClose } icon={ <DoneIcon /> } />
<Button
label={ 'Done' }
key='done'
onClick={ store.closeModal }
icon={ <DoneIcon /> }
/>
] }
visible={ open }
visible
scroll>
<List>
{ available.map(this.renderApp) }
{ store.apps.map(this.renderApp) }
</List>
</Modal>
);
}

renderApp = (app) => {
const { hidden, onHideApp, onShowApp } = this.props;
const isHidden = hidden.includes(app.id);
const description = (
<div className={ styles.description }>
{ app.description }
</div>
);
const { store } = this.props;
const isHidden = store.hidden.includes(app.id);
const onCheck = () => {
if (isHidden) {
onShowApp(app.id);
store.showApp(app.id);
} else {
onHideApp(app.id);
store.hideApp(app.id);
}
};

return (
<ListItem
key={ app.id }
leftCheckbox={ <Checkbox checked={ !isHidden } onCheck={ onCheck } /> }
leftCheckbox={
<Checkbox
checked={ !isHidden }
onCheck={ onCheck }
/>
}
primaryText={ app.name }
secondaryText={ description } />
secondaryText={
<div className={ styles.description }>
{ app.description }
</div>
}
/>
);
}
}
19 changes: 13 additions & 6 deletions js/src/views/Dapps/Summary/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ export default class Summary extends Component {
}

let image = <div className={ styles.image }>&nbsp;</div>;
if (app.image) {
image = <img src={ `http://127.0.0.1:${dappsPort}${app.image}` } className={ styles.image } />;
} else if (app.iconUrl) {
if (app.type === 'local') {
image = <img src={ `http://127.0.0.1:${dappsPort}/${app.id}/${app.iconUrl}` } className={ styles.image } />;
} else {
image = <img src={ `http://127.0.0.1:${dappsPort}${app.image}` } className={ styles.image } />;
}

return (
Expand All @@ -52,9 +52,16 @@ export default class Summary extends Component {
<div className={ styles.description }>
<ContainerTitle
className={ styles.title }
title={ <Link to={ `/app/${app.id}` }>{ app.name }</Link> }
byline={ app.description } />
<div className={ styles.author }>{ app.author }, v{ app.version }</div>
title={
<Link to={ `/app/${app.id}` }>
{ app.name }
</Link>
}
byline={ app.description }
/>
<div className={ styles.author }>
{ app.author }, v{ app.version }
</div>
{ this.props.children }
</div>
</Container>
Expand Down
Loading