See addresses outside address book + Save them

This commit is contained in:
Nicolas Gotchac 2016-12-10 15:19:05 +01:00
parent 65f586ed14
commit ef93262311
4 changed files with 119 additions and 30 deletions

View File

@ -28,6 +28,7 @@ export default class AddAddress extends Component {
static propTypes = { static propTypes = {
contacts: PropTypes.object.isRequired, contacts: PropTypes.object.isRequired,
address: PropTypes.string,
onClose: PropTypes.func onClose: PropTypes.func
}; };
@ -39,6 +40,12 @@ export default class AddAddress extends Component {
description: '' description: ''
}; };
componentWillMount () {
if (this.props.address) {
this.onEditAddress(null, this.props.address);
}
}
render () { render () {
return ( return (
<Modal <Modal
@ -77,6 +84,8 @@ export default class AddAddress extends Component {
hint='the network address for the entry' hint='the network address for the entry'
error={ addressError } error={ addressError }
value={ address } value={ address }
disabled={ !!this.props.address }
allowCopy={ false }
onChange={ this.onEditAddress } /> onChange={ this.onEditAddress } />
<Input <Input
label='address name' label='address name'

View File

@ -31,6 +31,10 @@
.infoline, .infoline,
.uuidline { .uuidline {
line-height: 1.618em; line-height: 1.618em;
&.bigaddress {
font-size: 1.25em;
}
} }
.infoline, .infoline,

View File

@ -32,18 +32,20 @@ export default class Header extends Component {
balance: PropTypes.object, balance: PropTypes.object,
className: PropTypes.string, className: PropTypes.string,
children: PropTypes.node, children: PropTypes.node,
isContract: PropTypes.bool isContract: PropTypes.bool,
hideName: PropTypes.bool
}; };
static defaultProps = { static defaultProps = {
className: '', className: '',
children: null, children: null,
isContract: false isContract: false,
hideName: false
}; };
render () { render () {
const { api } = this.context; const { api } = this.context;
const { account, balance, className, children } = this.props; const { account, balance, className, children, hideName } = this.props;
const { address, meta, uuid } = account; const { address, meta, uuid } = account;
if (!account) { if (!account) {
@ -60,17 +62,20 @@ export default class Header extends Component {
<IdentityIcon <IdentityIcon
address={ address } /> address={ address } />
<div className={ styles.floatleft }> <div className={ styles.floatleft }>
<ContainerTitle title={ <IdentityName address={ address } unknown /> } /> { this.renderName(address) }
<div className={ styles.addressline }>
<div className={ [ hideName ? styles.bigaddress : '', styles.addressline ].join(' ') }>
<CopyToClipboard data={ address } /> <CopyToClipboard data={ address } />
<div className={ styles.address }>{ address }</div> <div className={ styles.address }>{ address }</div>
</div> </div>
{ uuidText } { uuidText }
<div className={ styles.infoline }> <div className={ styles.infoline }>
{ meta.description } { meta.description }
</div> </div>
{ this.renderTxCount() } { this.renderTxCount() }
</div> </div>
<div className={ styles.tags }> <div className={ styles.tags }>
<Tags tags={ meta.tags } /> <Tags tags={ meta.tags } />
</div> </div>
@ -89,6 +94,18 @@ export default class Header extends Component {
); );
} }
renderName (address) {
const { hideName } = this.props;
if (hideName) {
return null;
}
return (
<ContainerTitle title={ <IdentityName address={ address } unknown /> } />
);
}
renderTxCount () { renderTxCount () {
const { balance, isContract } = this.props; const { balance, isContract } = this.props;

View File

@ -19,8 +19,9 @@ import { connect } from 'react-redux';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import ActionDelete from 'material-ui/svg-icons/action/delete'; import ActionDelete from 'material-ui/svg-icons/action/delete';
import ContentCreate from 'material-ui/svg-icons/content/create'; import ContentCreate from 'material-ui/svg-icons/content/create';
import ContentAdd from 'material-ui/svg-icons/content/add';
import { EditMeta } from '~/modals'; import { EditMeta, AddAddress } from '~/modals';
import { Actionbar, Button, Page } from '~/ui'; import { Actionbar, Button, Page } from '~/ui';
import Header from '../Account/Header'; import Header from '../Account/Header';
@ -32,7 +33,7 @@ class Address extends Component {
static contextTypes = { static contextTypes = {
api: PropTypes.object.isRequired, api: PropTypes.object.isRequired,
router: PropTypes.object.isRequired router: PropTypes.object.isRequired
} };
static propTypes = { static propTypes = {
setVisibleAccounts: PropTypes.func.isRequired, setVisibleAccounts: PropTypes.func.isRequired,
@ -40,12 +41,13 @@ class Address extends Component {
contacts: PropTypes.object, contacts: PropTypes.object,
balances: PropTypes.object, balances: PropTypes.object,
params: PropTypes.object params: PropTypes.object
} };
state = { state = {
showDeleteDialog: false, showDeleteDialog: false,
showEditDialog: false showEditDialog: false,
} showAdd: false
};
componentDidMount () { componentDidMount () {
this.setVisibleAccounts(); this.setVisibleAccounts();
@ -73,32 +75,69 @@ class Address extends Component {
render () { render () {
const { contacts, balances } = this.props; const { contacts, balances } = this.props;
const { address } = this.props.params; const { address } = this.props.params;
const { showDeleteDialog } = this.state;
if (Object.keys(contacts).length === 0) {
return null;
}
const contact = (contacts || {})[address]; const contact = (contacts || {})[address];
const balance = (balances || {})[address]; const balance = (balances || {})[address];
if (!contact) { return (
<div>
{ this.renderAddAddress(contact, address) }
{ this.renderEditDialog(contact) }
{ this.renderActionbar(contact) }
{ this.renderDelete(contact) }
<Page>
<Header
account={ contact || { address, meta: {} } }
balance={ balance }
hideName={ !contact }
/>
<Transactions
address={ address }
/>
</Page>
</div>
);
}
renderAddAddress (contact, address) {
if (contact) {
return null;
}
const { contacts } = this.props;
const { showAdd } = this.state;
if (!showAdd) {
return null; return null;
} }
return ( return (
<div> <AddAddress
{ this.renderEditDialog(contact) } contacts={ contacts }
{ this.renderActionbar(contact) } onClose={ this.onCloseAdd }
address={ address }
/>
);
}
renderDelete (contact) {
if (!contact) {
return null;
}
const { showDeleteDialog } = this.state;
return (
<Delete <Delete
account={ contact } account={ contact }
visible={ showDeleteDialog } visible={ showDeleteDialog }
route='/addresses' route='/addresses'
onClose={ this.closeDeleteDialog } /> onClose={ this.closeDeleteDialog }
<Page> />
<Header
account={ contact }
balance={ balance } />
<Transactions
address={ address } />
</Page>
</div>
); );
} }
@ -116,17 +155,27 @@ class Address extends Component {
onClick={ this.showDeleteDialog } /> onClick={ this.showDeleteDialog } />
]; ];
const addToBook = (
<Button
key='newAddress'
icon={ <ContentAdd /> }
label='save address'
onClick={ this.onOpenAdd }
/>
);
return ( return (
<Actionbar <Actionbar
title='Address Information' title='Address Information'
buttons={ !contact ? [] : buttons } /> buttons={ !contact ? [ addToBook ] : buttons }
/>
); );
} }
renderEditDialog (contact) { renderEditDialog (contact) {
const { showEditDialog } = this.state; const { showEditDialog } = this.state;
if (!showEditDialog) { if (!contact || !showEditDialog) {
return null; return null;
} }
@ -151,6 +200,16 @@ class Address extends Component {
showDeleteDialog = () => { showDeleteDialog = () => {
this.setState({ showDeleteDialog: true }); this.setState({ showDeleteDialog: true });
} }
onOpenAdd = () => {
this.setState({
showAdd: true
});
}
onCloseAdd = () => {
this.setState({ showAdd: false });
}
} }
function mapStateToProps (state) { function mapStateToProps (state) {