From 953ff985d86ae3d9591883edfc4702798508f93d Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 8 Sep 2014 16:51:37 -0700 Subject: [PATCH] paypro: implement short merchant names in address box and side box. --- js/controllers/send.js | 21 +++++++++++++++++++++ js/directives.js | 12 ++++++++++-- views/send.html | 7 ++++--- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index 80ff2e5a3..e0ee33c8a 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -461,6 +461,13 @@ angular.module('copayApp.controllers').controller('SendController', var value = scope.address || ''; var uri; + // If we're setting the domain, ignore the change. + if ($rootScope.merchant + && $rootScope.merchant.domain + && value === $rootScope.merchant.domain) { + return; + } + if (value.indexOf('bitcoin:') === 0) { uri = new bitcore.BIP21(value).data; } else if (/^https?:\/\//.test(value)) { @@ -517,12 +524,18 @@ angular.module('copayApp.controllers').controller('SendController', return; } + var url = merchantData.request_url; + var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1]; + merchantData.unitTotal = (+merchantData.total / config.unitToSatoshi) + ''; merchantData.expiration = new Date( merchantData.pr.pd.expires * 1000).toISOString(); + merchantData.domain = domain; $rootScope.merchant = merchantData; + scope.sendForm.address.$setViewValue(domain); + scope.sendForm.address.$render(); scope.sendForm.address.$isValid = true; scope.sendForm.amount.$setViewValue(merchantData.unitTotal); @@ -534,6 +547,14 @@ angular.module('copayApp.controllers').controller('SendController', 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)) { diff --git a/js/directives.js b/js/directives.js index 6ddf8456a..e8024cab5 100644 --- a/js/directives.js +++ b/js/directives.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.directives') - .directive('validAddress', function() { + .directive('validAddress', ['$rootScope', function($rootScope) { var bitcore = require('bitcore'); var Address = bitcore.Address; var bignum = bitcore.Bignum; @@ -11,6 +11,14 @@ angular.module('copayApp.directives') link: function(scope, elem, attrs, ctrl) { var validator = function(value) { + // If we're setting the domain, ignore the change. + if ($rootScope.merchant + && $rootScope.merchant.domain + && value === $rootScope.merchant.domain) { + ctrl.$setValidity('validAddress', true); + return value; + } + // Regular url if (/^https?:\/\//.test(value)) { ctrl.$setValidity('validAddress', true); @@ -35,7 +43,7 @@ angular.module('copayApp.directives') ctrl.$formatters.unshift(validator); } }; - }) + }]) .directive('enoughAmount', ['$rootScope', function($rootScope) { var bitcore = require('bitcore'); diff --git a/views/send.html b/views/send.html index 0361d5946..28198856d 100644 --- a/views/send.html +++ b/views/send.html @@ -20,7 +20,7 @@ not valid
- @@ -129,8 +129,9 @@
Send to
-

- {{$root.merchant.request_url}}  +

+ {{$root.merchant.domain}} 

Total amount for this transaction: