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:
Jaco Greeff 2016-12-08 15:54:23 +01:00 committed by GitHub
parent d38da1f3b4
commit a1fb1240a7
11 changed files with 36 additions and 15 deletions

View File

@ -68,6 +68,7 @@ export default class Personal {
this._accountsInfo(); this._accountsInfo();
return; return;
case 'parity_removeAddress':
case 'parity_setAccountName': case 'parity_setAccountName':
case 'parity_setAccountMeta': case 'parity_setAccountMeta':
this._accountsInfo(); this._accountsInfo();

View File

@ -94,7 +94,6 @@ export default class Application extends Component {
tokenregInstance, tokenregInstance,
accounts: Object accounts: Object
.keys(accountsInfo) .keys(accountsInfo)
.filter((address) => !accountsInfo[address].meta.deleted)
.sort((a, b) => { .sort((a, b) => {
return (accountsInfo[b].uuid || '').localeCompare(accountsInfo[a].uuid || ''); return (accountsInfo[b].uuid || '').localeCompare(accountsInfo[a].uuid || '');
}) })

View File

@ -24,7 +24,6 @@ export const fetch = () => (dispatch) => {
.then((accountsInfo) => { .then((accountsInfo) => {
const addresses = Object const addresses = Object
.keys(accountsInfo) .keys(accountsInfo)
.filter((address) => accountsInfo[address] && !accountsInfo[address].meta.deleted)
.map((address) => ({ .map((address) => ({
...accountsInfo[address], ...accountsInfo[address],
address, address,

View File

@ -102,7 +102,7 @@ export default class AddAddress extends Component {
if (!addressError) { if (!addressError) {
const contact = contacts[address]; const contact = contacts[address];
if (contact && !contact.meta.deleted) { if (contact) {
addressError = ERRORS.duplicateAddress; addressError = ERRORS.duplicateAddress;
} }
} }

View File

@ -231,7 +231,7 @@ export default class AddContract extends Component {
if (!addressError) { if (!addressError) {
const contract = contracts[address]; const contract = contracts[address];
if (contract && !contract.meta.deleted) { if (contract) {
addressError = ERRORS.duplicateAddress; addressError = ERRORS.duplicateAddress;
} }
} }

View File

@ -23,6 +23,7 @@ export default class Personal {
} }
start () { start () {
this._removeDeleted();
this._subscribeAccountsInfo(); this._subscribeAccountsInfo();
} }
@ -40,4 +41,29 @@ export default class Personal {
console.log('personal._subscribeAccountsInfo', 'subscriptionId', subscriptionId); 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);
});
}
} }

View File

@ -53,7 +53,6 @@ class InputAddress extends Component {
const { small, allowCopy, hideUnderline, onSubmit, accountsInfo, tokens } = this.props; const { small, allowCopy, hideUnderline, onSubmit, accountsInfo, tokens } = this.props;
const account = accountsInfo[value] || tokens[value]; const account = accountsInfo[value] || tokens[value];
const hasAccount = account && !(account.meta && account.meta.deleted);
const icon = this.renderIcon(); const icon = this.renderIcon();
@ -74,7 +73,7 @@ class InputAddress extends Component {
label={ label } label={ label }
hint={ hint } hint={ hint }
error={ error } error={ error }
value={ text && hasAccount ? account.name : value } value={ text && account ? account.name : value }
onChange={ this.handleInputChange } onChange={ this.handleInputChange }
onSubmit={ onSubmit } onSubmit={ onSubmit }
allowCopy={ allowCopy && (disabled ? value : false) } allowCopy={ allowCopy && (disabled ? value : false) }

View File

@ -37,17 +37,16 @@ class IdentityName extends Component {
render () { render () {
const { address, accountsInfo, tokens, empty, name, shorten, unknown, className } = this.props; const { address, accountsInfo, tokens, empty, name, shorten, unknown, className } = this.props;
const account = accountsInfo[address] || tokens[address]; const account = accountsInfo[address] || tokens[address];
const hasAccount = account && (account.uuid || !account.meta || !account.meta.deleted);
if (!hasAccount && empty) { if (!account && empty) {
return null; return null;
} }
const addressFallback = shorten ? (<ShortenedHash data={ address } />) : address; const addressFallback = shorten ? (<ShortenedHash data={ address } />) : address;
const fallback = unknown ? defaultName : addressFallback; 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()) || const displayName = (name && name.toUpperCase().trim()) ||
(hasAccount && !isUuid (account && !isUuid
? account.name.toUpperCase().trim() ? account.name.toUpperCase().trim()
: fallback); : fallback);

View File

@ -80,10 +80,8 @@ class Delete extends Component {
const { api, router } = this.context; const { api, router } = this.context;
const { account, route, newError } = this.props; const { account, route, newError } = this.props;
account.meta.deleted = true;
api.parity api.parity
.setAccountMeta(account.address, account.meta) .removeAddress(account.address)
.then(() => { .then(() => {
router.push(route); router.push(route);
this.closeDeleteDialog(); this.closeDeleteDialog();

View File

@ -121,7 +121,7 @@ class Address extends Component {
return ( return (
<Actionbar <Actionbar
title='Address Information' title='Address Information'
buttons={ !contact || contact.meta.deleted ? [] : buttons } /> buttons={ !contact ? [] : buttons } />
); );
} }

View File

@ -229,7 +229,7 @@ class Contract extends Component {
return ( return (
<Actionbar <Actionbar
title='Contract Information' title='Contract Information'
buttons={ !account || account.meta.deleted ? [] : buttons } /> buttons={ !account ? [] : buttons } />
); );
} }