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,12 +1,18 @@
|
|||
'use strict';
|
||||
angular.module('copayApp.directives')
|
||||
.directive('validAddress', ['$rootScope', 'bitcore',
|
||||
function($rootScope, bitcore) {
|
||||
.directive('validAddress', ['$rootScope', 'bitcore', 'bitcoreCash',
|
||||
function($rootScope, bitcore, bitcoreCash) {
|
||||
return {
|
||||
require: 'ngModel',
|
||||
link: function(scope, elem, attrs, ctrl) {
|
||||
// Bitcoin address
|
||||
var URI = bitcore.URI;
|
||||
var Address = bitcore.Address
|
||||
|
||||
// Bitcoin Cash address
|
||||
var URICash = bitcoreCash.URI;
|
||||
var AddressCash = bitcoreCash.Address
|
||||
|
||||
var validator = function(value) {
|
||||
|
||||
// Regular url
|
||||
|
|
@ -16,8 +22,8 @@ angular.module('copayApp.directives')
|
|||
}
|
||||
|
||||
// Bip21 uri
|
||||
var uri, isAddressValidLivenet, isAddressValidTestnet;
|
||||
if (/^bitcoin:/.test(value)) {
|
||||
var uri, isAddressValidLivenet, isAddressValidTestnet;
|
||||
var isUriValid = URI.isValid(value);
|
||||
if (isUriValid) {
|
||||
uri = new URI(value);
|
||||
|
|
@ -26,6 +32,14 @@ angular.module('copayApp.directives')
|
|||
}
|
||||
ctrl.$setValidity('validAddress', isUriValid && (isAddressValidLivenet || isAddressValidTestnet));
|
||||
return value;
|
||||
} else if (/^bitcoincash:/.test(value)) {
|
||||
var isUriValid = URICash.isValid(value);
|
||||
if (isUriValid) {
|
||||
uri = new URICash(value);
|
||||
isAddressValidLivenet = AddressCash.isValid(uri.address.toString(), 'livenet')
|
||||
}
|
||||
ctrl.$setValidity('validAddress', isUriValid && (isAddressValidLivenet));
|
||||
return value;
|
||||
}
|
||||
|
||||
if (typeof value == 'undefined') {
|
||||
|
|
@ -33,10 +47,11 @@ angular.module('copayApp.directives')
|
|||
return;
|
||||
}
|
||||
|
||||
// Regular Address
|
||||
// Regular Address: try Bitcoin and Bitcoin Cash
|
||||
var regularAddressLivenet = Address.isValid(value, 'livenet');
|
||||
var regularAddressTestnet = Address.isValid(value, 'testnet');
|
||||
ctrl.$setValidity('validAddress', (regularAddressLivenet || regularAddressTestnet));
|
||||
var regularAddressCashLivenet = AddressCash.isValid(value, 'livenet');
|
||||
ctrl.$setValidity('validAddress', (regularAddressLivenet || regularAddressTestnet || regularAddressCashLivenet));
|
||||
return value;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue