Merge pull request #235 from cmgustavo/ref/design-17
Fix addressbook []
This commit is contained in:
commit
a400db05c0
1 changed files with 3 additions and 12 deletions
|
|
@ -3,16 +3,6 @@
|
||||||
angular.module('copayApp.services').factory('addressbookService', function(bitcore, storageService, lodash) {
|
angular.module('copayApp.services').factory('addressbookService', function(bitcore, storageService, lodash) {
|
||||||
var root = {};
|
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) {
|
root.getLabel = function(addr, cb) {
|
||||||
storageService.getAddressbook('testnet', function(err, ab) {
|
storageService.getAddressbook('testnet', function(err, ab) {
|
||||||
if (ab && ab[addr]) return cb(ab[addr]);
|
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) {
|
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) {
|
storageService.getAddressbook(network, function(err, ab) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (ab) ab = JSON.parse(ab);
|
if (ab) ab = JSON.parse(ab);
|
||||||
ab = ab || {};
|
ab = ab || {};
|
||||||
|
if (lodash.isArray(ab)) ab = {}; // No array
|
||||||
if (ab[entry.address]) return cb('Entry already exist');
|
if (ab[entry.address]) return cb('Entry already exist');
|
||||||
ab[entry.address] = entry.label;
|
ab[entry.address] = entry.label;
|
||||||
storageService.setAddressbook(network, JSON.stringify(ab), function(err, ab) {
|
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) {
|
root.remove = function(addr, cb) {
|
||||||
var network = getNetwork(addr);
|
var network = (new bitcore.Address(addr)).network.name;
|
||||||
storageService.getAddressbook(network, function(err, ab) {
|
storageService.getAddressbook(network, function(err, ab) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
if (ab) ab = JSON.parse(ab);
|
if (ab) ab = JSON.parse(ab);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue