From 16a484c57c1ffe340e5ac1cab0dd264371ec7d8e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Dominguez Date: Mon, 30 Apr 2018 16:50:38 +0900 Subject: [PATCH] Fix - 253 - Removing contact from Address Book feature not functional --- src/js/controllers/addressbookView.js | 5 +++-- src/js/services/addressbookService.js | 20 ++++++++++++++++---- www/views/addressbook.view.html | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/js/controllers/addressbookView.js b/src/js/controllers/addressbookView.js index 06bf68fd4..aab6fb5b4 100644 --- a/src/js/controllers/addressbookView.js +++ b/src/js/controllers/addressbookView.js @@ -40,12 +40,13 @@ angular.module('copayApp.controllers').controller('addressbookViewController', f }, 100); }; - $scope.remove = function(addr) { + $scope.remove = function(addressbookEntry) { var title = gettextCatalog.getString('Warning!'); var message = gettextCatalog.getString('Are you sure you want to delete this contact?'); popupService.showConfirm(title, message, null, null, function(res) { if (!res) return; - addressbookService.remove(addr, function(err, ab) { + + addressbookService.remove(addressbookEntry, function(err, ab) { if (err) { popupService.showAlert(gettextCatalog.getString('Error'), err); return; diff --git a/src/js/services/addressbookService.js b/src/js/services/addressbookService.js index f98bda41d..28a3fd31d 100644 --- a/src/js/services/addressbookService.js +++ b/src/js/services/addressbookService.js @@ -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) { diff --git a/www/views/addressbook.view.html b/www/views/addressbook.view.html index cf44f8e72..ad3ba4964 100644 --- a/www/views/addressbook.view.html +++ b/www/views/addressbook.view.html @@ -36,7 +36,7 @@
-
+
Remove