diff --git a/js/controllers/send.js b/js/controllers/send.js index b20e70359..c9e9aa774 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -13,6 +13,7 @@ angular.module('copayApp.controllers').controller('SendController', $rootScope.title = 'Send'; $scope.loading = false; + $scope.error = $scope.success = null; var satToUnit = 1 / w.settings.unitToSatoshi; $scope.defaultFee = bitcore.TransactionBuilder.FEE_PER_1000B_SAT * satToUnit; $scope.unitToBtc = w.settings.unitToSatoshi / bitcore.util.COIN; @@ -145,15 +146,7 @@ angular.module('copayApp.controllers').controller('SendController', if (w.requiresMultipleSignatures()) { $scope.loading = false; - var message = 'The transaction proposal has been created'; - if (merchantData) { - if (merchantData.pr.ca) { - message += ' This payment protocol transaction' + ' has been verified through ' + merchantData.pr.ca + '.'; - } - message += merchantData.pr.pd.memo; - message += ' Merchant: ' + merchantData.pr.pd.payment_url; - } - $scope.success = message; + notification.success('Success', 'The transaction proposal created'); $scope.loadTxs(); } else { w.sendTx(ntxid, function(txid, merchantData) { @@ -166,7 +159,7 @@ angular.module('copayApp.controllers').controller('SendController', message += merchantData.pr.pd.memo; message += ' Merchant: ' + merchantData.pr.pd.payment_url; } - $scope.success = 'Transaction broadcasted' + message; + $scope.success = 'Transaction broadcasted' + message; } else { $scope.error = 'There was an error sending the transaction'; } @@ -362,7 +355,6 @@ angular.module('copayApp.controllers').controller('SendController', $scope.submitAddressBook = function(form) { if (form.$invalid) { - scope.error = 'Please complete required fields'; return; } var entry = { @@ -409,14 +401,15 @@ angular.module('copayApp.controllers').controller('SendController', $scope.send = function(ntxid, cb) { + $scope.error = $scope.success = null; $scope.loading = true; $rootScope.txAlertCount = 0; w.sendTx(ntxid, function(txid, merchantData) { if (!txid) { - $scope.error = 'There was an error sending the transaction'; + notification.error('Error', 'There was an error sending the transaction'); } else { if (!merchantData) { - $scope.success = 'Transaction broadcasted!'; + notification.success('Success', 'Transaction broadcasted!'); } else { var message = 'Transaction ID: ' + txid; if (merchantData.pr.ca) { @@ -424,7 +417,7 @@ angular.module('copayApp.controllers').controller('SendController', } message += ' Message from server: ' + merchantData.ack.memo; message += ' For merchant: ' + merchantData.pr.pd.payment_url; - $scope.success = 'Transaction sent' + message; + notification.success('Success', 'Transaction sent' + message); } } @@ -435,15 +428,15 @@ angular.module('copayApp.controllers').controller('SendController', $scope.sign = function(ntxid) { $scope.loading = true; + $scope.error = $scope.success = null; try { w.sign(ntxid); } catch (e) { - $scope.error = 'There was an error signing the transaction'; + notification.error('Error','There was an error signing the transaction'); $scope.loadTxs(); return; } - $scope.error = undefined; var p = w.txProposals.getTxProposal(ntxid); if (p.builder.isFullySigned()) { @@ -465,16 +458,15 @@ angular.module('copayApp.controllers').controller('SendController', }; $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) { + if (!$scope.sendForm || !$scope.sendForm.address) { delete $rootScope.merchant; $rootScope.merchantError = false; if (callback) callback(); return; } - var val = scope.sendForm.address.$viewValue || ''; + 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) { @@ -491,8 +483,8 @@ angular.module('copayApp.controllers').controller('SendController', } if (!uri || !uri.merchant) { delete $rootScope.merchant; - scope.sendForm.amount.$setViewValue(''); - scope.sendForm.amount.$render(); + $scope.sendForm.amount.$setViewValue(''); + $scope.sendForm.amount.$render(); if (callback) callback(); if ($rootScope.$$phase !== '$apply' && $rootScope.$$phase !== '$digest') { $rootScope.$apply(); @@ -501,10 +493,10 @@ angular.module('copayApp.controllers').controller('SendController', }; $scope.onChanged = function() { - var scope = $scope; - var value = scope.address || ''; + var value = $scope.address || ''; var uri; + $scope.error = $scope.success = null; // If we're setting the domain, ignore the change. if ($rootScope.merchant && $rootScope.merchant.domain && value === $rootScope.merchant.domain) { return; @@ -528,28 +520,28 @@ angular.module('copayApp.controllers').controller('SendController', } }; - scope.fetchingURL = uri.merchant; - scope.loading = true; + $scope.fetchingURL = uri.merchant; + $scope.loading = true; apply(); var timeout = setTimeout(function() { timeout = null; - scope.fetchingURL = null; - scope.loading = false; - scope.sendForm.address.$setViewValue(''); - scope.sendForm.address.$render(); - scope.sendForm.address.$isValid = false; - scope.error = 'Payment server timed out'; + $scope.fetchingURL = null; + $scope.loading = false; + $scope.sendForm.address.$setViewValue(''); + $scope.sendForm.address.$render(); + $scope.sendForm.address.$isValid = false; + $scope.error = 'Payment server timed out'; apply(); }, 10 * 1000); // Payment Protocol URI (BIP-72) - scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) { + $scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) { if (!timeout) return; clearTimeout(timeout); - scope.loading = false; - scope.fetchingURL = null; + $scope.loading = false; + $scope.fetchingURL = null; apply(); var balance = $rootScope.availableBalance; @@ -561,28 +553,29 @@ angular.module('copayApp.controllers').controller('SendController', if (err) { if (err.amount) { - scope.sendForm.amount.$setViewValue(+err.amount / w.settings.unitToSatoshi); - scope.sendForm.amount.$render(); - scope.sendForm.amount.$isValid = false; - scope.notEnoughAmount = true; + $scope.sendForm.amount.$setViewValue(+err.amount / w.settings.unitToSatoshi); + $scope.sendForm.amount.$render(); + $scope.sendForm.amount.$isValid = false; + $scope.notEnoughAmount = true; $rootScope.merchantError = true; - var lastAddr = scope.sendForm.address.$viewValue; - var unregister = scope.$watch('address', function() { - if (scope.sendForm.address.$viewValue !== lastAddr) { + var lastAddr = $scope.sendForm.address.$viewValue; + var unregister = $scope.$watch('address', function() { + if ($scope.sendForm.address.$viewValue !== lastAddr) { delete $rootScope.merchantError; - scope.sendForm.amount.$setViewValue(''); - scope.sendForm.amount.$render(); + $scope.sendForm.amount.$setViewValue(''); + $scope.sendForm.amount.$render(); unregister(); apply(); } }); } else { - scope.sendForm.address.$setViewValue(''); - scope.sendForm.address.$render(); + $scope.sendForm.address.$setViewValue(''); + $scope.sendForm.address.$render(); } - scope.sendForm.address.$isValid = false; + $scope.sendForm.address.$isValid = false; + copay.logger.error(err); - scope.error = err.message || 'Bad payment server'; + $scope.error = 'Could not fetch payment request'; apply(); return; @@ -593,18 +586,18 @@ angular.module('copayApp.controllers').controller('SendController', merchantData.unitTotal = (+merchantData.total / w.settings.unitToSatoshi) + ''; merchantData.expiration = new Date( - merchantData.pr.pd.expires * 1000).toISOString(); + merchantData.pr.pd.expires * 1000); merchantData.domain = domain; $rootScope.merchant = merchantData; - scope.sendForm.address.$setViewValue(domain); - scope.sendForm.address.$render(); - scope.sendForm.address.$isValid = true; + $scope.sendForm.address.$setViewValue(domain); + $scope.sendForm.address.$render(); + $scope.sendForm.address.$isValid = true; - scope.sendForm.amount.$setViewValue(merchantData.unitTotal); - scope.sendForm.amount.$render(); - scope.sendForm.amount.$isValid = true; + $scope.sendForm.amount.$setViewValue(merchantData.unitTotal); + $scope.sendForm.amount.$render(); + $scope.sendForm.amount.$isValid = true; // If the address changes to a non-payment-protocol one, // delete the `merchant` property from the scope. @@ -613,9 +606,6 @@ angular.module('copayApp.controllers').controller('SendController', }); apply(); - - scope.success = 'Payment Request:' + merchantData.unitTotal + - ' ' + w.settings.unitName + '. ' + (merchantData.pr.pd.memo || ''); }); }; }); diff --git a/js/directives.js b/js/directives.js index 3fea9be8b..e24748362 100644 --- a/js/directives.js +++ b/js/directives.js @@ -186,7 +186,7 @@ angular.module('copayApp.directives') } element.bind('click', function() { - selectText(elm[0]); + selectText(element[0]); }); } }; diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index b4f59e995..48a626e81 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -362,6 +362,11 @@ angular.module('copayApp.services') var res = w.getPendingTxProposals(); _.each(res.txs, function(tx) { root.computeAlternativeAmount(w, tx); + if (tx.merchant) { + var url = tx.merchant.request_url; + var domain = /^(?:https?)?:\/\/([^\/:]+).*$/.exec(url)[1]; + tx.merchant.domain = domain; + } }); $rootScope.txps = res.txs; if ($rootScope.pendingTxCount < res.pendingForUs) { diff --git a/views/home.html b/views/home.html index a0ea9543a..ec882102a 100644 --- a/views/home.html +++ b/views/home.html @@ -49,9 +49,6 @@
-

http://HOLA 1234

- -

http://HOLA 1234

Sign in to Copay

+ +
+
+

+ {{tx.merchant.pr.pd.memo}} +

+ Expires {{tx.merchant.pr.pd.expires * 1000 | amTimeAgo }} + [{{tx.merchant.domain}}] + {{tx.merchant.pr.ca}} + Untrusted +

+
+ diff --git a/views/send.html b/views/send.html index 734fbb3da..621b46a12 100644 --- a/views/send.html +++ b/views/send.html @@ -129,7 +129,7 @@

- + Fetching payment

From {{fetchingURL}} @@ -139,34 +139,24 @@

This is a payment protocol transaction

- Send to: - {{$root.merchant.domain}} + {{$root.merchant.pr.pd.memo}}

+

- Total amount for this transaction: {{amount + defaultFee |noFractionNumber}} {{$root.wallet.settings.unitName}} - + {{ rateService.toFiat((amount + defaultFee) * unitToSatoshi, alternativeIsoCode) | noFractionNumber: 2 }} {{ alternativeIsoCode }} - - + + (Including fee of {{defaultFee|noFractionNumber}} {{$root.wallet.settings.unitName}}) - -

+

- Server Says: - {{$root.merchant.pr.pd.memo}} -

-

- Certificate: - {{$root.merchant.pr.ca}} - Untrusted -

-

- Payment Expiration: - {{$root.merchant.expiration}} -

+ Expires {{$root.merchant.expiration | amTimeAgo }} + [{{$root.merchant.domain}}] + {{$root.merchant.pr.ca}} + Untrusted