From 20bc1ecbb5d40bf83e70805c7e6d3eab83a9e74c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 15 Sep 2014 15:49:52 -0700 Subject: [PATCH] paypro: fix $root.merchant clearing on tab change. see #1406 - gustavo's comment. --- js/controllers/send.js | 61 +++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index 683b6c71c..d12868d40 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -465,6 +465,40 @@ angular.module('copayApp.controllers').controller('SendController', $scope.loadTxs(); }; + $scope.clearMerchant = function(callback) { + var scope = $scope; + // TODO: Find a better way of detecting + // whether we're in the Send scope or not. + if (!scope.sendForm || !scope.sendForm.address) { + delete $rootScope.merchant; + if (callback) callback(); + return; + } + var val = scope.sendForm.address.$viewValue || ''; + var uri; + // If we're setting the domain, ignore the change. + if ($rootScope.merchant && $rootScope.merchant.domain && val === $rootScope.merchant.domain) { + uri = { + merchant: $rootScope.merchant.request_url + }; + } + if (val.indexOf('bitcoin:') === 0) { + uri = new bitcore.BIP21(val).data; + } else if (/^https?:\/\//.test(val)) { + uri = { + merchant: val + }; + } + if (!uri || !uri.merchant) { + delete $rootScope.merchant; + scope.sendForm.amount.$setViewValue(''); + scope.sendForm.amount.$render(); + if (callback) callback(); + if ($rootScope.$$phase !== '$apply' && $rootScope.$$phase !== '$digest') { + $rootScope.$apply(); + } + } + }; $scope.onChanged = function() { var scope = $scope; @@ -552,31 +586,8 @@ angular.module('copayApp.controllers').controller('SendController', // If the address changes to a non-payment-protocol one, // delete the `merchant` property from the scope. - var unregister = scope.$watch('address', function() { - var val = scope.sendForm.address.$viewValue || ''; - var uri; - // If we're setting the domain, ignore the change. - if ($rootScope.merchant && $rootScope.merchant.domain && val === $rootScope.merchant.domain) { - uri = { - merchant: $rootScope.merchant.request_url - }; - } - if (val.indexOf('bitcoin:') === 0) { - uri = new bitcore.BIP21(val).data; - } else if (/^https?:\/\//.test(val)) { - uri = { - merchant: val - }; - } - if (!uri || !uri.merchant) { - delete $rootScope.merchant; - scope.sendForm.amount.$setViewValue(''); - scope.sendForm.amount.$render(); - unregister(); - if ($rootScope.$$phase !== '$apply' && $rootScope.$$phase !== '$digest') { - $rootScope.$apply(); - } - } + var unregister = $rootScope.$watch(function() { + $scope.clearMerchant(unregister); }); if ($rootScope.$$phase !== '$apply' && $rootScope.$$phase !== '$digest') {