paypro: minor refactor - clean up whitespace in directives.

This commit is contained in:
Christopher Jeffrey 2014-08-07 09:17:03 -07:00 committed by Manuel Araoz
parent d58bfe9de8
commit 80ceca3b73
1 changed files with 127 additions and 120 deletions

View File

@ -12,10 +12,22 @@ angular.module('copayApp.directives')
require: 'ngModel',
link: function(scope, elem, attrs, ctrl) {
var validator = function(value) {
var uri = copay.HDPath.parseBitcoinURI(value);
var uri;
// Is this a payment protocol URI (BIP-72)?
if (uri && uri.merchant) {
if (/^https?:\/\//.test(value)) {
uri = { merchant: value };
} else {
uri = copay.HDPath.parseBitcoinURI(value);
}
// Regular Address
if (!uri || !uri.merchant) {
var a = new Address(value);
ctrl.$setValidity('validAddress', a.isValid() && a.network().name === config.networkName);
return value;
}
// Payment Protocol URI (BIP-72)
scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
var balance = $rootScope.availableBalance;
var available = +(balance * config.unitToSatoshi).toFixed(0);
@ -147,11 +159,6 @@ angular.module('copayApp.directives')
ctrl.$setValidity('validAddress', true);
return 'Merchant: '+ uri.merchant;
}
var a = new Address(value);
ctrl.$setValidity('validAddress', a.isValid() && a.network().name === config.networkName);
return value;
};
ctrl.$parsers.unshift(validator);