Properly delete addresses/contracts in addressbook (#3739)
* Remove previously market addresses at startup * Remove meta.deleted checks * Remove artifact from code move
This commit is contained in:
parent
d38da1f3b4
commit
a1fb1240a7
@ -68,6 +68,7 @@ export default class Personal {
|
||||
this._accountsInfo();
|
||||
return;
|
||||
|
||||
case 'parity_removeAddress':
|
||||
case 'parity_setAccountName':
|
||||
case 'parity_setAccountMeta':
|
||||
this._accountsInfo();
|
||||
|
@ -94,7 +94,6 @@ export default class Application extends Component {
|
||||
tokenregInstance,
|
||||
accounts: Object
|
||||
.keys(accountsInfo)
|
||||
.filter((address) => !accountsInfo[address].meta.deleted)
|
||||
.sort((a, b) => {
|
||||
return (accountsInfo[b].uuid || '').localeCompare(accountsInfo[a].uuid || '');
|
||||
})
|
||||
|
@ -24,7 +24,6 @@ export const fetch = () => (dispatch) => {
|
||||
.then((accountsInfo) => {
|
||||
const addresses = Object
|
||||
.keys(accountsInfo)
|
||||
.filter((address) => accountsInfo[address] && !accountsInfo[address].meta.deleted)
|
||||
.map((address) => ({
|
||||
...accountsInfo[address],
|
||||
address,
|
||||
|
@ -102,7 +102,7 @@ export default class AddAddress extends Component {
|
||||
if (!addressError) {
|
||||
const contact = contacts[address];
|
||||
|
||||
if (contact && !contact.meta.deleted) {
|
||||
if (contact) {
|
||||
addressError = ERRORS.duplicateAddress;
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ export default class AddContract extends Component {
|
||||
if (!addressError) {
|
||||
const contract = contracts[address];
|
||||
|
||||
if (contract && !contract.meta.deleted) {
|
||||
if (contract) {
|
||||
addressError = ERRORS.duplicateAddress;
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ export default class Personal {
|
||||
}
|
||||
|
||||
start () {
|
||||
this._removeDeleted();
|
||||
this._subscribeAccountsInfo();
|
||||
}
|
||||
|
||||
@ -40,4 +41,29 @@ export default class Personal {
|
||||
console.log('personal._subscribeAccountsInfo', 'subscriptionId', subscriptionId);
|
||||
});
|
||||
}
|
||||
|
||||
_removeDeleted () {
|
||||
this._api.parity
|
||||
.accountsInfo()
|
||||
.then((accountsInfo) => {
|
||||
return Promise.all(
|
||||
Object
|
||||
.keys(accountsInfo)
|
||||
.filter((address) => {
|
||||
const account = accountsInfo[address];
|
||||
|
||||
return !account.uuid && account.meta.deleted;
|
||||
})
|
||||
.map((address) => this._api.parity.removeAddress(address))
|
||||
);
|
||||
})
|
||||
.then((results) => {
|
||||
if (results.length) {
|
||||
console.log(`Removed ${results.length} previously marked addresses`);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.warn('removeDeleted', error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,6 @@ class InputAddress extends Component {
|
||||
const { small, allowCopy, hideUnderline, onSubmit, accountsInfo, tokens } = this.props;
|
||||
|
||||
const account = accountsInfo[value] || tokens[value];
|
||||
const hasAccount = account && !(account.meta && account.meta.deleted);
|
||||
|
||||
const icon = this.renderIcon();
|
||||
|
||||
@ -74,7 +73,7 @@ class InputAddress extends Component {
|
||||
label={ label }
|
||||
hint={ hint }
|
||||
error={ error }
|
||||
value={ text && hasAccount ? account.name : value }
|
||||
value={ text && account ? account.name : value }
|
||||
onChange={ this.handleInputChange }
|
||||
onSubmit={ onSubmit }
|
||||
allowCopy={ allowCopy && (disabled ? value : false) }
|
||||
|
@ -37,17 +37,16 @@ class IdentityName extends Component {
|
||||
render () {
|
||||
const { address, accountsInfo, tokens, empty, name, shorten, unknown, className } = this.props;
|
||||
const account = accountsInfo[address] || tokens[address];
|
||||
const hasAccount = account && (account.uuid || !account.meta || !account.meta.deleted);
|
||||
|
||||
if (!hasAccount && empty) {
|
||||
if (!account && empty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const addressFallback = shorten ? (<ShortenedHash data={ address } />) : address;
|
||||
const fallback = unknown ? defaultName : addressFallback;
|
||||
const isUuid = hasAccount && account.name === account.uuid;
|
||||
const isUuid = account && account.name === account.uuid;
|
||||
const displayName = (name && name.toUpperCase().trim()) ||
|
||||
(hasAccount && !isUuid
|
||||
(account && !isUuid
|
||||
? account.name.toUpperCase().trim()
|
||||
: fallback);
|
||||
|
||||
|
@ -80,10 +80,8 @@ class Delete extends Component {
|
||||
const { api, router } = this.context;
|
||||
const { account, route, newError } = this.props;
|
||||
|
||||
account.meta.deleted = true;
|
||||
|
||||
api.parity
|
||||
.setAccountMeta(account.address, account.meta)
|
||||
.removeAddress(account.address)
|
||||
.then(() => {
|
||||
router.push(route);
|
||||
this.closeDeleteDialog();
|
||||
|
@ -121,7 +121,7 @@ class Address extends Component {
|
||||
return (
|
||||
<Actionbar
|
||||
title='Address Information'
|
||||
buttons={ !contact || contact.meta.deleted ? [] : buttons } />
|
||||
buttons={ !contact ? [] : buttons } />
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -229,7 +229,7 @@ class Contract extends Component {
|
||||
return (
|
||||
<Actionbar
|
||||
title='Contract Information'
|
||||
buttons={ !account || account.meta.deleted ? [] : buttons } />
|
||||
buttons={ !account ? [] : buttons } />
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user