paypro: _resetPayPro to reset the form.

This commit is contained in:
Christopher Jeffrey 2014-08-01 20:33:50 -07:00 committed by Manuel Araoz
commit bc4a8f73d8

View file

@ -18,6 +18,7 @@ angular.module('copayApp.directives')
if (uri && uri.merchant) { if (uri && uri.merchant) {
scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) { scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
if (err) { if (err) {
if (scope._resetPayPro) scope._resetPayPro();
ctrl.$setValidity('validAddress', false); ctrl.$setValidity('validAddress', false);
return; return;
} }
@ -80,10 +81,10 @@ angular.module('copayApp.directives')
sendall.attr('class', sendall.attr('class') + ' hidden'); sendall.attr('class', sendall.attr('class') + ' hidden');
// Reset all the changes from the payment protocol weirdness. // Reset all the changes from the payment protocol weirdness.
// XXX Bad hook. // XXX Bad hook. Find a better more angular-y way of doing this.
if (!scope.__watchingAddress) { // This will also closure scope every variable above forever.
scope.__watchingAddress = true; if (!scope._resetPayPro) {
scope.$watch('address', function(newValue, oldValue) { scope._resetPayPro = function() {
var val = address.val(); var val = address.val();
var uri = copay.HDPath.parseBitcoinURI(val || ''); var uri = copay.HDPath.parseBitcoinURI(val || '');
if (!uri || !uri.merchant) { if (!uri || !uri.merchant) {
@ -108,11 +109,15 @@ angular.module('copayApp.directives')
} }
// TODO: Check paymentRequest expiration, // TODO: Check paymentRequest expiration,
// delete if beyond expiration date. // delete if beyond expiration date.
}); };
scope.$watch('address',scope._resetPayPro);
} }
ctrl.$setValidity('validAddress', true); ctrl.$setValidity('validAddress', true);
// XXX With PayPro, since amount is already filled in among
// other field oddities, the form is always invalid. Make it
// valid.
scope.sendForm.$valid = true; scope.sendForm.$valid = true;
scope.sendForm.$invalid = false; scope.sendForm.$invalid = false;
scope.sendForm.$pristine = true; scope.sendForm.$pristine = true;