Merge pull request #235 from cmgustavo/ref/design-17

Fix addressbook []
This commit is contained in:
Matias Alejo Garcia 2016-08-25 18:20:40 -03:00 committed by GitHub
commit a400db05c0
1 changed files with 3 additions and 12 deletions

View File

@ -3,16 +3,6 @@
angular.module('copayApp.services').factory('addressbookService', function(bitcore, storageService, lodash) {
var root = {};
var getNetwork = function(addr) {
var Address = bitcore.Address;
if (Address.isValid(addr, 'livenet')) {
return 'livenet';
}
if (Address.isValid(addr, 'testnet')) {
return 'testnet';
}
};
root.getLabel = function(addr, cb) {
storageService.getAddressbook('testnet', function(err, ab) {
if (ab && ab[addr]) return cb(ab[addr]);
@ -41,11 +31,12 @@ angular.module('copayApp.services').factory('addressbookService', function(bitco
};
root.add = function(entry, cb) {
var network = getNetwork(entry.address);
var network = (new bitcore.Address(entry.address)).network.name;
storageService.getAddressbook(network, function(err, ab) {
if (err) return cb(err);
if (ab) ab = JSON.parse(ab);
ab = ab || {};
if (lodash.isArray(ab)) ab = {}; // No array
if (ab[entry.address]) return cb('Entry already exist');
ab[entry.address] = entry.label;
storageService.setAddressbook(network, JSON.stringify(ab), function(err, ab) {
@ -58,7 +49,7 @@ angular.module('copayApp.services').factory('addressbookService', function(bitco
};
root.remove = function(addr, cb) {
var network = getNetwork(addr);
var network = (new bitcore.Address(addr)).network.name;
storageService.getAddressbook(network, function(err, ab) {
if (err) return cb(err);
if (ab) ab = JSON.parse(ab);