Adds bitcoin cash support for the address book
This commit is contained in:
parent
881679cd48
commit
c9253c44f3
3 changed files with 55 additions and 14 deletions
|
|
@ -1,8 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('addressbookService', function(bitcore, storageService, lodash) {
|
||||
angular.module('copayApp.services').factory('addressbookService', function($log, bitcore, bitcoreCash, storageService, lodash) {
|
||||
var root = {};
|
||||
|
||||
var getNetwork = function(address) {
|
||||
var network;
|
||||
try {
|
||||
network = (new bitcore.Address(address)).network.name;
|
||||
} catch(e) {
|
||||
$log.error('No valid bitcoin address. Trying bitcoin cash...');
|
||||
network = (new bitcoreCash.Address(address)).network.name;
|
||||
}
|
||||
return network;
|
||||
};
|
||||
|
||||
root.get = function(addr, cb) {
|
||||
storageService.getAddressbook('testnet', function(err, ab) {
|
||||
if (err) return cb(err);
|
||||
|
|
@ -35,7 +46,8 @@ angular.module('copayApp.services').factory('addressbookService', function(bitco
|
|||
};
|
||||
|
||||
root.add = function(entry, cb) {
|
||||
var network = (new bitcore.Address(entry.address)).network.name;
|
||||
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);
|
||||
|
|
@ -53,7 +65,8 @@ angular.module('copayApp.services').factory('addressbookService', function(bitco
|
|||
};
|
||||
|
||||
root.remove = function(addr, cb) {
|
||||
var network = (new bitcore.Address(addr)).network.name;
|
||||
var network = getNetwork(addr);
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue