1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Merge pull request #7326 from MetaMask/edit-contact

Edit contact details fix.
This commit is contained in:
Thomas Huang 2019-10-29 18:17:36 -07:00 committed by GitHub
commit bed58dd7d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -25,10 +25,16 @@ export default class EditContact extends PureComponent {
setAccountLabel: PropTypes.func,
}
static defaultProps = {
name: '',
address: '',
memo: '',
}
state = {
newName: '',
newAddress: '',
newMemo: '',
newName: this.props.name,
newAddress: this.props.address,
newMemo: this.props.memo,
error: '',
}
@ -60,7 +66,7 @@ export default class EditContact extends PureComponent {
type="text"
id="nickname"
placeholder={this.context.t('addAlias')}
value={this.state.newName || name}
value={this.state.newName}
onChange={e => this.setState({ newName: e.target.value })}
fullWidth
margin="dense"
@ -74,8 +80,7 @@ export default class EditContact extends PureComponent {
<TextField
type="text"
id="address"
placeholder={address}
value={this.state.newAddress || address}
value={this.state.newAddress}
error={this.state.error}
onChange={e => this.setState({ newAddress: e.target.value })}
fullWidth
@ -91,7 +96,7 @@ export default class EditContact extends PureComponent {
type="text"
id="memo"
placeholder={memo}
value={this.state.newMemo || memo}
value={this.state.newMemo}
onChange={e => this.setState({ newMemo: e.target.value })}
fullWidth
margin="dense"
@ -110,12 +115,12 @@ export default class EditContact extends PureComponent {
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)) {
removeFromAddressBook(address)
removeFromAddressBook(chainId, address)
addToAddressBook(this.state.newAddress, this.state.newName || name, this.state.newMemo || memo)
setAccountLabel(this.state.newAddress, this.state.newName || name)
history.push(listRoute)
} else {
this.setState({ error: 'invalid address' })
this.setState({ error: this.context.t('invalidAddress') })
}
} else {
// update name

View File

@ -98,6 +98,8 @@
&--copy-icon {
padding-left: 4px;
width: 30px;
height: 20px;
}
}