From 03c3eefd0d68ce49fce5b4d6259885b69b4de7a4 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 15 Sep 2014 11:42:12 -0700 Subject: [PATCH 1/3] paypro: fix xhr error messages. remove comments. --- js/models/core/Wallet.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 61e81b137..815ee3fa0 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -1295,7 +1295,7 @@ Wallet.prototype.createPaymentTx = function(options, cb) { return self.receivePaymentRequest(options, pr, cb); }) .error(function(data, status, headers, config) { - return cb(new Error('Status: ' + JSON.stringify(status))); + return cb(new Error('Status: ' + status)); }); }; @@ -1572,7 +1572,7 @@ Wallet.prototype.sendPaymentTx = function(ntxid, options, cb) { return self.receivePaymentRequestACK(ntxid, tx, txp, ack, cb); }) .error(function(data, status, headers, config) { - return cb(new Error('Status: ' + JSON.stringify(status))); + return cb(new Error('Status: ' + status)); }); }; @@ -2483,15 +2483,6 @@ Wallet.prototype.verifySignedJson = function(senderId, payload, signature) { return v; } -// NOTE: Angular $http module does not send ArrayBuffers correctly, so we're -// not going to use it. We'll have to write our own. Otherwise, we could -// hex-encoded our messages and decode them on the other side, but that -// deviates from BIP-70. - -// if (typeof angular !== 'undefined') { -// var $http = angular.bootstrap().get('$http'); -// } - /** * @desc Create a HTTP request * @TODO: This shouldn't be a wallet responsibility @@ -2557,7 +2548,13 @@ Wallet.request = function(options, callback) { }; xhr.onerror = function(event) { - return ret._error(null, new Error(event.message), null, options); + var status; + if (xhr.status === 0 || !xhr.statusText) { + status = 'HTTP Request Error: This endpoint likely does not support cross-origin requests.'; + } else { + status = xhr.statusText; + } + return ret._error(null, status, null, options); }; if (req.body) { From 20bc1ecbb5d40bf83e70805c7e6d3eab83a9e74c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 15 Sep 2014 15:49:52 -0700 Subject: [PATCH 2/3] 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') { From aa5e90786b64ff4870c7f21e0b3f3c41b90adccb Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 15 Sep 2014 16:37:36 -0700 Subject: [PATCH 3/3] paypro: fix - check for merchant_data existence. --- js/models/core/Wallet.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 815ee3fa0..63ffebafa 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -1408,7 +1408,10 @@ Wallet.prototype.receivePaymentRequest = function(options, pr, cb) { expires: expires, memo: memo || 'This server would like some BTC from you.', payment_url: payment_url, - merchant_data: merchant_data.toString('hex') + merchant_data: merchant_data + ? merchant_data.toString('hex') + // : new Buffer('none', 'utf8').toString('hex') + : '00' }, signature: sig.toString('hex'), ca: trust.caName,