2019-07-31 21:56:44 +02:00
|
|
|
import React, { PureComponent } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2020-07-20 16:55:47 +02:00
|
|
|
import { Redirect } from 'react-router-dom'
|
2019-07-31 21:56:44 +02:00
|
|
|
import Identicon from '../../../../components/ui/identicon'
|
|
|
|
import Button from '../../../../components/ui/button/button.component'
|
|
|
|
import TextField from '../../../../components/ui/text-field'
|
|
|
|
import { isValidAddress } from '../../../../helpers/utils/util'
|
|
|
|
import PageContainerFooter from '../../../../components/ui/page-container/page-container-footer'
|
|
|
|
|
|
|
|
export default class EditContact extends PureComponent {
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
addToAddressBook: PropTypes.func,
|
|
|
|
removeFromAddressBook: PropTypes.func,
|
|
|
|
history: PropTypes.object,
|
|
|
|
name: PropTypes.string,
|
|
|
|
address: PropTypes.string,
|
2019-10-29 18:53:51 +01:00
|
|
|
chainId: PropTypes.string,
|
2019-07-31 21:56:44 +02:00
|
|
|
memo: PropTypes.string,
|
|
|
|
viewRoute: PropTypes.string,
|
|
|
|
listRoute: PropTypes.string,
|
|
|
|
setAccountLabel: PropTypes.func,
|
2020-07-18 01:30:25 +02:00
|
|
|
showingMyAccounts: PropTypes.bool.isRequired,
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
|
2019-10-30 01:55:10 +01:00
|
|
|
static defaultProps = {
|
|
|
|
name: '',
|
|
|
|
memo: '',
|
|
|
|
}
|
|
|
|
|
2019-07-31 21:56:44 +02:00
|
|
|
state = {
|
2019-10-30 00:21:18 +01:00
|
|
|
newName: this.props.name,
|
|
|
|
newAddress: this.props.address,
|
|
|
|
newMemo: this.props.memo,
|
2019-07-31 21:56:44 +02:00
|
|
|
error: '',
|
|
|
|
}
|
|
|
|
|
2019-07-31 22:17:11 +02:00
|
|
|
render () {
|
2019-07-31 21:56:44 +02:00
|
|
|
const { t } = this.context
|
2020-07-18 01:30:25 +02:00
|
|
|
const {
|
|
|
|
address,
|
|
|
|
addToAddressBook,
|
|
|
|
chainId,
|
|
|
|
history,
|
|
|
|
listRoute,
|
|
|
|
memo,
|
|
|
|
name,
|
|
|
|
removeFromAddressBook,
|
|
|
|
setAccountLabel,
|
|
|
|
showingMyAccounts,
|
|
|
|
viewRoute,
|
|
|
|
} = this.props
|
2019-07-31 21:56:44 +02:00
|
|
|
|
2020-07-20 16:55:47 +02:00
|
|
|
if (!address) {
|
|
|
|
return <Redirect to={{ pathname: listRoute }} />
|
|
|
|
}
|
|
|
|
|
2019-07-31 21:56:44 +02:00
|
|
|
return (
|
|
|
|
<div className="settings-page__content-row address-book__edit-contact">
|
|
|
|
<div className="settings-page__header address-book__header--edit">
|
2019-12-03 17:35:44 +01:00
|
|
|
<Identicon address={address} diameter={60} />
|
2020-07-18 01:30:25 +02:00
|
|
|
{
|
|
|
|
showingMyAccounts
|
|
|
|
? null
|
|
|
|
: (
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
className="settings-page__address-book-button"
|
|
|
|
onClick={async () => {
|
|
|
|
await removeFromAddressBook(chainId, address)
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('deleteAccount')}
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
|
|
|
<div className="address-book__edit-contact__content">
|
2019-07-31 22:17:11 +02:00
|
|
|
<div className="address-book__view-contact__group">
|
2019-07-31 21:56:44 +02:00
|
|
|
<div className="address-book__view-contact__group__label">
|
2019-07-31 22:17:11 +02:00
|
|
|
{ t('userName') }
|
2019-07-31 21:56:44 +02:00
|
|
|
</div>
|
|
|
|
<TextField
|
|
|
|
type="text"
|
|
|
|
id="nickname"
|
2019-10-30 00:42:56 +01:00
|
|
|
placeholder={this.context.t('addAlias')}
|
2019-10-30 00:21:18 +01:00
|
|
|
value={this.state.newName}
|
2020-02-15 21:34:12 +01:00
|
|
|
onChange={(e) => this.setState({ newName: e.target.value })}
|
2019-07-31 21:56:44 +02:00
|
|
|
fullWidth
|
|
|
|
margin="dense"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="address-book__view-contact__group">
|
|
|
|
<div className="address-book__view-contact__group__label">
|
|
|
|
{ t('ethereumPublicAddress') }
|
|
|
|
</div>
|
|
|
|
<TextField
|
|
|
|
type="text"
|
|
|
|
id="address"
|
2019-10-30 00:21:18 +01:00
|
|
|
value={this.state.newAddress}
|
2019-07-31 21:56:44 +02:00
|
|
|
error={this.state.error}
|
2020-02-15 21:34:12 +01:00
|
|
|
onChange={(e) => this.setState({ newAddress: e.target.value })}
|
2019-07-31 21:56:44 +02:00
|
|
|
fullWidth
|
|
|
|
margin="dense"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="address-book__view-contact__group">
|
|
|
|
<div className="address-book__view-contact__group__label--capitalized">
|
|
|
|
{ t('memo') }
|
|
|
|
</div>
|
|
|
|
<TextField
|
|
|
|
type="text"
|
|
|
|
id="memo"
|
|
|
|
placeholder={memo}
|
2019-10-30 00:21:18 +01:00
|
|
|
value={this.state.newMemo}
|
2020-02-15 21:34:12 +01:00
|
|
|
onChange={(e) => this.setState({ newMemo: e.target.value })}
|
2019-07-31 21:56:44 +02:00
|
|
|
fullWidth
|
|
|
|
margin="dense"
|
2019-11-19 00:23:41 +01:00
|
|
|
multiline
|
2019-07-31 21:56:44 +02:00
|
|
|
rows={3}
|
|
|
|
classes={{
|
|
|
|
inputMultiline: 'address-book__view-contact__text-area',
|
|
|
|
inputRoot: 'address-book__view-contact__text-area-wrapper',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<PageContainerFooter
|
|
|
|
cancelText={this.context.t('cancel')}
|
2020-04-29 06:59:49 +02:00
|
|
|
onSubmit={async () => {
|
2019-07-31 21:56:44 +02:00
|
|
|
if (this.state.newAddress !== '' && this.state.newAddress !== address) {
|
|
|
|
// if the user makes a valid change to the address field, remove the original address
|
|
|
|
if (isValidAddress(this.state.newAddress)) {
|
2020-04-29 14:36:10 +02:00
|
|
|
await removeFromAddressBook(chainId, address)
|
2020-04-29 06:59:49 +02:00
|
|
|
await addToAddressBook(this.state.newAddress, this.state.newName || name, this.state.newMemo || memo)
|
2020-07-20 16:55:47 +02:00
|
|
|
if (showingMyAccounts) {
|
|
|
|
setAccountLabel(this.state.newAddress, this.state.newName || name)
|
|
|
|
}
|
2019-07-31 21:56:44 +02:00
|
|
|
history.push(listRoute)
|
|
|
|
} else {
|
2019-10-30 00:21:18 +01:00
|
|
|
this.setState({ error: this.context.t('invalidAddress') })
|
2019-07-31 21:56:44 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// update name
|
2020-04-29 06:59:49 +02:00
|
|
|
await addToAddressBook(address, this.state.newName || name, this.state.newMemo || memo)
|
2020-07-20 16:55:47 +02:00
|
|
|
if (showingMyAccounts) {
|
|
|
|
setAccountLabel(address, this.state.newName || name)
|
|
|
|
}
|
2019-07-31 21:56:44 +02:00
|
|
|
history.push(listRoute)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
onCancel={() => {
|
|
|
|
history.push(`${viewRoute}/${address}`)
|
|
|
|
}}
|
|
|
|
submitText={this.context.t('save')}
|
2019-11-18 16:08:47 +01:00
|
|
|
submitButtonType="confirm"
|
2019-07-31 21:56:44 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|