From 6f6cf87360b364ffa6feff41f151ee34fa340944 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 19 Aug 2014 10:21:40 -0700 Subject: [PATCH] wallet: fix bip21 calls. fixes #1128. --- js/controllers/send.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index 2a72164d3..c671aeebc 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -113,10 +113,6 @@ angular.module('copayApp.controllers').controller('SendController', var uri; if (address.indexOf('bitcoin:') === 0) { uri = new bitcore.BIP21(address).data; - } else if (address.indexOf('Merchant: ') === 0) { - uri = { - merchant: address.split(/\s+/)[1] - }; } else if (/^https?:\/\//.test(address)) { uri = { merchant: address @@ -403,19 +399,21 @@ angular.module('copayApp.controllers').controller('SendController', $scope.onChanged = function() { var scope = $scope; - var value = scope.address; + var value = scope.address || ''; var uri; - if (/^https?:\/\//.test(value)) { + if (value.indexOf('bitcoin:') === 0) { + uri = new bitcore.BIP21(value).data; + } else if (/^https?:\/\//.test(value)) { uri = { merchant: value }; - } else { - uri = new bitcore.BIP21(value).data; } + if (!uri || !uri.merchant) { return; } + notification.info('Fetching Payment', 'Retrieving Payment Request from ' + uri.merchant); @@ -476,7 +474,14 @@ angular.module('copayApp.controllers').controller('SendController', // delete the `merchant` property from the scope. var unregister = scope.$watch('address', function() { var val = scope.sendForm.address.$viewValue || ''; - var uri = new bitcore.BIP21(val).data; + var uri; + 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('');