Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Properly delete addresses/contracts in addressbook #3739

Merged
merged 4 commits into from
Dec 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions js/src/api/subscriptions/personal.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default class Personal {
this._accountsInfo();
return;

case 'parity_removeAddress':
case 'parity_setAccountName':
case 'parity_setAccountMeta':
this._accountsInfo();
Expand Down
1 change: 0 additions & 1 deletion js/src/dapps/basiccoin/Application/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '');
})
Expand Down
1 change: 0 additions & 1 deletion js/src/dapps/registry/addresses/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion js/src/modals/AddAddress/addAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion js/src/modals/AddContract/addContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
26 changes: 26 additions & 0 deletions js/src/redux/providers/personal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class Personal {
}

start () {
this._removeDeleted();
this._subscribeAccountsInfo();
}

Expand All @@ -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);
});
}
}
3 changes: 1 addition & 2 deletions js/src/ui/Form/InputAddress/inputAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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) }
Expand Down
7 changes: 3 additions & 4 deletions js/src/ui/IdentityName/identityName.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions js/src/views/Address/Delete/delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion js/src/views/Address/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Address extends Component {
return (
<Actionbar
title='Address Information'
buttons={ !contact || contact.meta.deleted ? [] : buttons } />
buttons={ !contact ? [] : buttons } />
);
}

Expand Down
2 changes: 1 addition & 1 deletion js/src/views/Contract/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class Contract extends Component {
return (
<Actionbar
title='Contract Information'
buttons={ !account || account.meta.deleted ? [] : buttons } />
buttons={ !account ? [] : buttons } />
);
}

Expand Down