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

registry dapp #2077

Merged
merged 40 commits into from
Sep 19, 2016
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a2ffa30
improve code style in lookup component
derhuerst Sep 8, 2016
4575b4c
registry: header, move status down
derhuerst Sep 8, 2016
5610452
registry: further styling :sparkles:
derhuerst Sep 8, 2016
c1fb52e
add byte-array-to-hex to ethapi
derhuerst Sep 8, 2016
ac55092
fix byte-array-to-hex :bug:
derhuerst Sep 12, 2016
5567a24
actions & reducers for registry events
derhuerst Sep 12, 2016
adbcca1
component for registry events
derhuerst Sep 12, 2016
eba1c8d
integrate events component into registry
derhuerst Sep 12, 2016
38f878d
registry events: show identity icon next to owner
derhuerst Sep 12, 2016
80ceb8e
registry: actions & reducers for account selection
derhuerst Sep 12, 2016
94ff876
registry: component for account selection
derhuerst Sep 12, 2016
55ced5e
bugfixes :bug:
derhuerst Sep 12, 2016
c4ca471
registry: actions & reducers for name registration
derhuerst Sep 12, 2016
70b3657
registry: component for name registration
derhuerst Sep 12, 2016
2e5a912
registry: connect component for name registration
derhuerst Sep 12, 2016
d4ae8a1
registry: sort events, show dropped
derhuerst Sep 13, 2016
616ffab
registry: pull out actions & reducers for accounts
derhuerst Sep 13, 2016
d92d819
registry: minor refactoring
derhuerst Sep 13, 2016
efdacf0
registry: code style :sparkles:
derhuerst Sep 13, 2016
6745a33
Merge from jg-parity-js
derhuerst Sep 13, 2016
3ce2ec8
Merge from js
derhuerst Sep 13, 2016
aae2696
registry: use contract.subscribe to fetch events
derhuerst Sep 13, 2016
c727e2d
registry: cleanup, code style
derhuerst Sep 13, 2016
bb55aab
registry: import globals through a module
derhuerst Sep 13, 2016
21708e8
registry: import globals through a module 2
derhuerst Sep 13, 2016
0d96aeb
registry: cleanup
derhuerst Sep 13, 2016
6b11a7a
registry: compose state from reducers
derhuerst Sep 13, 2016
b68b61f
registry: simplify state
derhuerst Sep 13, 2016
168fd20
registry: simplify props
derhuerst Sep 13, 2016
893bc9f
registry: make props required
derhuerst Sep 13, 2016
589e3c1
registry: filter by event type
derhuerst Sep 14, 2016
0ae0107
registry: toggles, unsubscribing
derhuerst Sep 14, 2016
d7691fd
registry: show timestamp in events log
derhuerst Sep 15, 2016
48c369c
register: lookup & register in lower case
derhuerst Sep 15, 2016
e2f7f54
registry: better UX, bugfixes :bug:
derhuerst Sep 15, 2016
46d8c4e
Merge js into parity-js-registry
derhuerst Sep 19, 2016
adea322
registry: list posted transactions
derhuerst Sep 19, 2016
5897488
registry: styling, better UX
derhuerst Sep 19, 2016
3f6b9a3
registry: nice account selector
derhuerst Sep 19, 2016
c9ddaf5
Merge js into parity-js-registry
derhuerst Sep 19, 2016
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
2 changes: 2 additions & 0 deletions js/src/api/util/bytes-array-to-hex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export default (bytes) =>
'0x' + bytes.map((b) => ('0' + b.toString(16)).slice(-2)).join('')
11 changes: 11 additions & 0 deletions js/src/api/util/bytes-array-to-hex.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import bytesToHex from './bytes-array-to-hex';

describe('api/util/bytes-array-to-hex', () => {
it('correctly converts an empty array', () => {
expect(bytesToHex([])).to.equal('0x');
});

it('correctly converts a non-empty array', () => {
expect(bytesToHex([0, 15, 16])).to.equal('0x000f10');
});
});
3 changes: 3 additions & 0 deletions js/src/dapps/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';

import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin();

import store from './registry/store';
import Container from './registry/Container';

Expand Down
11 changes: 11 additions & 0 deletions js/src/dapps/registry/Application/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.header {
margin: 0; padding: .3em .5em;
color: #fff;
background-color: #333;
}

.header h1 {
line-height: 1.3;
font-size: 200%;
text-transform: uppercase;
}
57 changes: 40 additions & 17 deletions js/src/dapps/registry/Application/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,58 @@ import lightBaseTheme from 'material-ui/styles/baseThemes/lightBaseTheme';
const muiTheme = getMuiTheme(lightBaseTheme);

import CircularProgress from 'material-ui/CircularProgress';
import Status from '../Status';
import Lookup from '../Lookup';
import styles from './application.css';
import Accounts from '../accounts';
import Lookup from '../lookup';
import Register from '../register';
import Events from '../events';
import Status from '../status';

export default class Application extends Component {
static childContextTypes = {
muiTheme: PropTypes.object
};
static childContextTypes = { muiTheme: PropTypes.object };
getChildContext () {
return { muiTheme };
}

static propTypes = {
actions: PropTypes.object.isRequired,
accounts: PropTypes.object.isRequired,
contract: PropTypes.object.isRequired,
owner: PropTypes.string.isRequired,
fee: PropTypes.object.isRequired,
lookup: PropTypes.object.isRequired,
events: PropTypes.array.isRequired,
register: PropTypes.object
};

render () {
const { contract, fee, owner, actions } = this.props;
const {
actions,
accounts,
contract, owner, fee,
lookup,
events,
register
} = this.props;

if (!contract || !fee || !owner) {
return (<CircularProgress size={ 1 } />);
}
return (
<div>
<Status address={ contract.address } fee={ fee } owner={ owner } />
<Lookup lookup={ this.props.lookup } actions={ actions.lookup } />
<div className={ styles.header }>
<h1>RΞgistry</h1>
<Accounts { ...accounts } actions={ actions.accounts } />
</div>
{ contract && fee && owner ? (
<div>
<Lookup { ...lookup } actions={ actions.lookup } />
<Register { ...register } fee={ fee } actions={ actions.register } />
<Events { ...events } actions={ actions.events } />
<Status address={ contract.address } owner={ owner } />
</div>
) : (
<CircularProgress size={ 1 } />
) }
</div>
);
}

}

Application.propTypes = {
contract: PropTypes.object,
fee: PropTypes.object,
owner: PropTypes.string
};
25 changes: 12 additions & 13 deletions js/src/dapps/registry/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,21 @@ import * as actions from './actions';

class Container extends Component {
static propTypes = {
actions: PropTypes.object,
contract: PropTypes.object,
owner: PropTypes.string,
fee: PropTypes.object,
lookup: PropTypes.object
actions: PropTypes.object.isRequired,
accounts: PropTypes.object.isRequired,
contract: PropTypes.object.isRequired,
owner: PropTypes.string.isRequired,
fee: PropTypes.object.isRequired,
lookup: PropTypes.object.isRequired,
events: PropTypes.array.isRequired
};

componentDidMount () {
this.props.actions.fetchContract();
}

render () {
const { actions, contract, owner, fee, lookup } = this.props;
return (<Application
actions={ actions }
contract={ contract }
owner={ owner }
fee={ fee }
lookup={ lookup }
/>);
return (<Application { ...this.props } />);
}
}

Expand All @@ -35,7 +31,10 @@ export default connect(
// react -> redux connection
(dispatch) => {
const bound = bindActionCreators(actions, dispatch);
bound.accounts = bindActionCreators(actions.accounts, dispatch);
bound.lookup = bindActionCreators(actions.lookup, dispatch);
bound.events = bindActionCreators(actions.events, dispatch);
bound.register = bindActionCreators(actions.register, dispatch);
return { actions: bound };
}
)(Container);
2 changes: 1 addition & 1 deletion js/src/dapps/registry/Lookup/actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const sha3 = window.parity.api.format.sha3;
import { sha3 } from '../parity.js';

export const start = (name, key) => ({ type: 'lookup start', name, key });

Expand Down
10 changes: 7 additions & 3 deletions js/src/dapps/registry/Lookup/lookup.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
.lookup {
padding: 1em;
margin: 1em;
}

.results {
margin: .5em 0;
.box {
margin: 0 1em;
}

.spacing {
margin-left: 1em;
}
80 changes: 47 additions & 33 deletions js/src/dapps/registry/Lookup/lookup.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,65 @@
import React, { Component, PropTypes } from 'react';
import { Card, CardHeader, CardText } from 'material-ui/Card';
import TextField from 'material-ui/TextField';
import FlatButton from 'material-ui/FlatButton';
import RaisedButton from 'material-ui/RaisedButton';
import SearchIcon from 'material-ui/svg-icons/action/search';

import styles from './lookup.css';

export default class Lookup extends Component {

static propTypes = {
actions: PropTypes.object,
lookup: PropTypes.object
actions: PropTypes.object.isRequired,
name: PropTypes.string.isRequired,
entry: PropTypes.string.isRequired,
result: PropTypes.string
}

state = { name: '', key: '' };
state = { name: '', entry: 'A' };

render () {
const self = this;
const onNameChange = (e) => {
self.setState({ name: e.target.value });
};
const onKeyChange = (e) => {
self.setState({ key: e.target.value });
};
const onLookupClick = () => {
self.props.actions.lookup(self.state.name, self.state.key);
};
const name = this.state.name || this.props.name;
const entry = this.state.entry || this.props.entry;
const result = this.props.result || '';

return (
<div className={ styles.lookup }>
<TextField
hintText='name'
value={ this.state.name || this.props.lookup.name || '' }
onChange={ onNameChange }
/>
<TextField
hintText='key'
value={ this.state.key || this.props.lookup.key || '' }
onChange={ onKeyChange }
/>
<FlatButton
label='Lookup'
primary
onClick={ onLookupClick }
/>
<div className={ styles.results }>
{ this.props.lookup.result || '' }
<Card className={ styles.lookup }>
<CardHeader title={ 'Query the Registry' } />
<div className={ styles.box }>
<TextField
className={ styles.spacing }
hintText='name'
value={ name }
onChange={ this.onNameChange }
/>
<TextField
className={ styles.spacing }
hintText='entry'
value={ entry }
onChange={ this.onKeyChange }
/>
<RaisedButton
className={ styles.spacing }
label='Lookup'
primary
icon={ <SearchIcon /> }
onClick={ this.onLookupClick }
/>
</div>
</div>
<CardText>
<code>{ result }</code>
</CardText>
</Card>
);
}

onNameChange = (e) => {
this.setState({ name: e.target.value });
};
onKeyChange = (e) => {
this.setState({ entry: e.target.value });
};
onLookupClick = () => {
this.props.actions.lookup(this.state.name, this.state.entry);
};
}
17 changes: 10 additions & 7 deletions js/src/dapps/registry/Lookup/reducers.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
const initialState = {
pending: false,
name: null, key: null,
name: '', entry: '',
result: null
};

export default (state = initialState, action) => {
if (action.type === 'lookup start')
if (action.type === 'lookup start') {
return {
pending: true,
name: action.name, key: action.key,
name: action.name, entry: action.entry,
result: null
};
}

if (action.type === 'lookup error')
if (action.type === 'lookup error') {
return {
pending: false,
name: null, key: null,
name: initialState.name, entry: initialState.entry,
result: null
};
}

if (action.type === 'lookup success')
if (action.type === 'lookup success') {
return {
pending: false,
name: null, key: null,
name: initialState.name, entry: initialState.entry,
result: action.result
};
}

return state;
};
13 changes: 2 additions & 11 deletions js/src/dapps/registry/Status/status.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
.status {
padding: 1em;
color: #fff;
background-color: #c0392b;
}

.address {
}

.fee {
}

.owner {
color: #333;
background-color: #f0f0f0;
}
10 changes: 3 additions & 7 deletions js/src/dapps/registry/Status/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@ import React, { Component, PropTypes } from 'react';

import styles from './status.css';

const { api } = window.parity;

export default class Status extends Component {

static propTypes = {
address: PropTypes.string,
fee: PropTypes.object,
owner: PropTypes.string
}

render () {
const { address, fee, owner } = this.props;
const { address, owner } = this.props;

return (
<div className={ styles.status }>
<div className={ styles.address }>Registry at { address }</div>
<div className={ styles.owner }>Owned by { owner }</div>
<div className={ styles.fee }>Registration fee { api.format.fromWei(fee).toFixed(3) }ΞTH</div>
<div className={ styles.address }>Registry at <code>{ address }</code></div>
<div className={ styles.owner }>Owned by <code>{ owner }</code></div>
</div>
);
}
Expand Down
Loading