[Registry dApp] Actions not available before selecting accounts (#3032)

* Removed hasAccount from actions, now in Application [RegDapp] (#2931)

* Linting issues
This commit is contained in:
Nicolas Gotchac 2016-11-01 14:40:50 +01:00 committed by Jaco Greeff
parent 19d5f93745
commit 297a09399d
6 changed files with 62 additions and 34 deletions

View File

@ -37,3 +37,15 @@
font-size: 80%; font-size: 80%;
background-color: #f0f0f0; background-color: #f0f0f0;
} }
.actions {
margin: 1em;
* {
font-size: 1.3rem !important;
}
> * {
padding-bottom: 0 !important;
}
}

View File

@ -20,6 +20,7 @@ import lightBaseTheme from 'material-ui/styles/baseThemes/lightBaseTheme';
const muiTheme = getMuiTheme(lightBaseTheme); const muiTheme = getMuiTheme(lightBaseTheme);
import CircularProgress from 'material-ui/CircularProgress'; import CircularProgress from 'material-ui/CircularProgress';
import { Card, CardText } from 'material-ui/Card';
import styles from './application.css'; import styles from './application.css';
import Accounts from '../Accounts'; import Accounts from '../Accounts';
import Events from '../Events'; import Events from '../Events';
@ -57,9 +58,7 @@ export default class Application extends Component {
accounts, contacts, accounts, contacts,
contract, fee, contract, fee,
lookup, lookup,
events, events
names,
records
} = this.props; } = this.props;
return ( return (
@ -71,8 +70,9 @@ export default class Application extends Component {
{ contract && fee ? ( { contract && fee ? (
<div> <div>
<Lookup { ...lookup } accounts={ accounts.all } contacts={ contacts } actions={ actions.lookup } /> <Lookup { ...lookup } accounts={ accounts.all } contacts={ contacts } actions={ actions.lookup } />
<Names { ...names } fee={ fee } actions={ actions.names } />
<Records { ...records } actions={ actions.records } /> { this.renderActions() }
<Events { ...events } accounts={ accounts.all } contacts={ contacts } actions={ actions.events } /> <Events { ...events } accounts={ accounts.all } contacts={ contacts } actions={ actions.events } />
<p className={ styles.address }> <p className={ styles.address }>
The Registry is provided by the contract at <code>{ contract.address }.</code> The Registry is provided by the contract at <code>{ contract.address }.</code>
@ -85,4 +85,34 @@ export default class Application extends Component {
); );
} }
renderActions () {
const {
actions,
accounts,
fee,
names,
records
} = this.props;
const hasAccount = !!accounts.selected;
if (!hasAccount) {
return (
<Card className={ styles.actions }>
<CardText>
Please select a valid account in order
to execute actions.
</CardText>
</Card>
);
}
return (
<div>
<Names { ...names } fee={ fee } actions={ actions.names } />
<Records { ...records } actions={ actions.records } />
</div>
);
}
} }

View File

@ -77,7 +77,6 @@ export default class Names extends Component {
static propTypes = { static propTypes = {
actions: PropTypes.object.isRequired, actions: PropTypes.object.isRequired,
fee: PropTypes.object.isRequired, fee: PropTypes.object.isRequired,
hasAccount: PropTypes.bool.isRequired,
pending: PropTypes.bool.isRequired, pending: PropTypes.bool.isRequired,
queue: PropTypes.array.isRequired queue: PropTypes.array.isRequired
} }
@ -89,20 +88,18 @@ export default class Names extends Component {
render () { render () {
const { action, name } = this.state; const { action, name } = this.state;
const { fee, hasAccount, pending, queue } = this.props; const { fee, pending, queue } = this.props;
return ( return (
<Card className={ styles.names }> <Card className={ styles.names }>
<CardHeader title={ 'Manage Names' } /> <CardHeader title={ 'Manage Names' } />
<CardText> <CardText>
{ !hasAccount { (action === 'reserve'
? (<p className={ styles.noSpacing }>Please select an account first.</p>) ? (<p className={ styles.noSpacing }>
: (action === 'reserve' The fee to reserve a name is <code>{ fromWei(fee).toFixed(3) }</code>ETH.
? (<p className={ styles.noSpacing }> </p>)
The fee to reserve a name is <code>{ fromWei(fee).toFixed(3) }</code>ETH. : (<p className={ styles.noSpacing }>To drop a name, you have to be the owner.</p>)
</p>) )
: (<p className={ styles.noSpacing }>To drop a name, you have to be the owner.</p>)
)
} }
<TextField <TextField
hintText='name' hintText='name'
@ -110,7 +107,7 @@ export default class Names extends Component {
onChange={ this.onNameChange } onChange={ this.onNameChange }
/> />
<DropDownMenu <DropDownMenu
disabled={ !hasAccount || pending } disabled={ pending }
value={ action } value={ action }
onChange={ this.onActionChange } onChange={ this.onActionChange }
> >
@ -118,7 +115,7 @@ export default class Names extends Component {
<MenuItem value='drop' primaryText='drop this name' /> <MenuItem value='drop' primaryText='drop this name' />
</DropDownMenu> </DropDownMenu>
<RaisedButton <RaisedButton
disabled={ !hasAccount || pending } disabled={ pending }
className={ styles.spacing } className={ styles.spacing }
label={ action === 'reserve' ? 'Reserve' : 'Drop' } label={ action === 'reserve' ? 'Reserve' : 'Drop' }
primary primary

View File

@ -15,16 +15,11 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>. // along with Parity. If not, see <http://www.gnu.org/licenses/>.
const initialState = { const initialState = {
hasAccount: false,
pending: false, pending: false,
queue: [] queue: []
}; };
export default (state = initialState, action) => { export default (state = initialState, action) => {
if (action.type === 'accounts select') {
return { ...state, hasAccount: !!action.address };
}
if (action.type === 'names reserve start') { if (action.type === 'names reserve start') {
return { ...state, pending: true }; return { ...state, pending: true };
} }

View File

@ -11,7 +11,6 @@ export default class Records extends Component {
static propTypes = { static propTypes = {
actions: PropTypes.object.isRequired, actions: PropTypes.object.isRequired,
hasAccount: PropTypes.bool.isRequired,
pending: PropTypes.bool.isRequired, pending: PropTypes.bool.isRequired,
name: PropTypes.string.isRequired, name: PropTypes.string.isRequired,
type: PropTypes.string.isRequired, type: PropTypes.string.isRequired,
@ -21,7 +20,7 @@ export default class Records extends Component {
state = { name: '', type: 'A', value: '' }; state = { name: '', type: 'A', value: '' };
render () { render () {
const { hasAccount, pending } = this.props; const { pending } = this.props;
const name = this.state.name || this.props.name; const name = this.state.name || this.props.name;
const type = this.state.type || this.props.type; const type = this.state.type || this.props.type;
const value = this.state.value || this.props.value; const value = this.state.value || this.props.value;
@ -30,10 +29,10 @@ export default class Records extends Component {
<Card className={ styles.records }> <Card className={ styles.records }>
<CardHeader title={ 'Manage Entries of a Name' } /> <CardHeader title={ 'Manage Entries of a Name' } />
<CardText> <CardText>
{ !hasAccount <p className={ styles.noSpacing }>
? (<p className={ styles.noSpacing }>Please select an account first.</p>) You can only modify entries of names that you previously registered.
: (<p className={ styles.noSpacing }>You can only modify entries of names that you previously registered.</p>) </p>
}
<TextField <TextField
className={ styles.spacing } className={ styles.spacing }
hintText='name' hintText='name'
@ -48,7 +47,7 @@ export default class Records extends Component {
onChange={ this.onValueChange } onChange={ this.onValueChange }
/> />
<RaisedButton <RaisedButton
disabled={ !hasAccount || pending } disabled={ pending }
className={ styles.spacing } className={ styles.spacing }
label='Save' label='Save'
primary primary

View File

@ -1,14 +1,9 @@
const initialState = { const initialState = {
hasAccount: false,
pending: false, pending: false,
name: '', type: '', value: '' name: '', type: '', value: ''
}; };
export default (state = initialState, action) => { export default (state = initialState, action) => {
if (action.type === 'accounts select') {
return { ...state, hasAccount: !!action.address };
}
if (action.type === 'records update start') { if (action.type === 'records update start') {
return { return {
...state, ...state,