Fix - 253 - Removing contact from Address Book feature not functional

This commit is contained in:
Jean-Baptiste Dominguez 2018-04-30 16:50:38 +09:00
commit 16a484c57c
3 changed files with 20 additions and 7 deletions

View file

@ -64,16 +64,28 @@ angular.module('copayApp.services').factory('addressbookService', function($log,
});
};
root.remove = function(addr, cb) {
var network = getNetwork(addr);
root.remove = function(entry, cb) {
// The entry is in bitcoin address, so I get the legacy one, and I operate.
if (entry.coin == 'bch') {
var a = entry.address;
if (entry.address.indexOf('bitcoincash:') < 0) {
a = 'bitcoincash:' + a;
}
entry.address = bitcoinCashJsService.readAddress(a).legacy;
} else {
entry.address = entry.address;
}
var network = getNetwork(entry.address);
if (lodash.isEmpty(network)) return cb('Not valid bitcoin address');
storageService.getAddressbook(network, function(err, ab) {
if (err) return cb(err);
if (ab) ab = JSON.parse(ab);
ab = ab || {};
if (lodash.isEmpty(ab)) return cb('Addressbook is empty');
if (!ab[addr]) return cb('Entry does not exist');
delete ab[addr];
if (!ab[entry.coin + entry.address]) return cb('Entry does not exist');
delete ab[entry.coin + entry.address];
storageService.setAddressbook(network, JSON.stringify(ab), function(err) {
if (err) return cb('Error deleting entry');
root.list(function(err, ab) {