mirror of https://github.com/BTCPrivate/copay.git
paypro: cached payment requests. validation.
This commit is contained in:
parent
2aee44f31c
commit
6e9eaf7d9d
|
@ -64,27 +64,42 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
function done(ntxid, ca) {
|
function done(ntxid, ca) {
|
||||||
var txp = w.txProposals.txps[ntxid];
|
var txp = w.txProposals.txps[ntxid];
|
||||||
var merchantData = txp.merchant;
|
var merchantData = txp.merchant;
|
||||||
|
var amt = angular.element(document.querySelector('input#amount'));
|
||||||
if (w.isShared()) {
|
if (w.isShared()) {
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
var message = 'The transaction proposal has been created';
|
var message = 'The transaction proposal has been created';
|
||||||
if (ca) {
|
if (ca) {
|
||||||
message += '.\nThis payment protocol transaction'
|
message += '\nThis payment protocol transaction'
|
||||||
+ 'has been verified through ' + ca + '.';
|
+ ' has been verified through ' + ca + '.';
|
||||||
|
}
|
||||||
|
if (merchantData) {
|
||||||
|
message += '\nFor merchant: ' + merchantData.pr.payment_url;
|
||||||
}
|
}
|
||||||
notification.success('Success!', message);
|
notification.success('Success!', message);
|
||||||
$scope.loadTxs();
|
$scope.loadTxs();
|
||||||
|
if (merchantData) {
|
||||||
|
amt.attr('disabled', false);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
w.sendTx(ntxid, function(txid, ca) {
|
w.sendTx(ntxid, function(txid, ca) {
|
||||||
if (txid) {
|
if (txid) {
|
||||||
notification.success('Transaction broadcast', 'Transaction id: ' + txid);
|
var message = 'Transaction id: ' + txid;
|
||||||
if (ca) {
|
if (ca) {
|
||||||
notification.success('Root Certificate', ca);
|
message += '\nThis payment protocol transaction'
|
||||||
|
+ ' has been verified through ' + ca + '.';
|
||||||
}
|
}
|
||||||
|
if (merchantData) {
|
||||||
|
message += '\nFor merchant: ' + merchantData.pr.payment_url;
|
||||||
|
}
|
||||||
|
notification.success('Transaction broadcast', message);
|
||||||
} else {
|
} else {
|
||||||
notification.error('Error', 'There was an error sending the transaction.');
|
notification.error('Error', 'There was an error sending the transaction.');
|
||||||
}
|
}
|
||||||
$scope.loading = false;
|
$scope.loading = false;
|
||||||
$scope.loadTxs();
|
$scope.loadTxs();
|
||||||
|
if (merchantData) {
|
||||||
|
amt.attr('disabled', false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$rootScope.pendingPayment = null;
|
$rootScope.pendingPayment = null;
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.directives')
|
angular.module('copayApp.directives')
|
||||||
//.directive('validAddress', ['$rootScope',
|
|
||||||
//function($rootScope) {
|
|
||||||
.directive('validAddress', [
|
.directive('validAddress', [
|
||||||
function() {
|
function() {
|
||||||
|
|
||||||
|
@ -13,17 +11,20 @@ angular.module('copayApp.directives')
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
link: function(scope, elem, attrs, ctrl) {
|
link: function(scope, elem, attrs, ctrl) {
|
||||||
var validator = function(value) {
|
var validator = function(value) {
|
||||||
// Is payment protocol address?
|
|
||||||
var uri = copay.HDPath.parseBitcoinURI(value);
|
var uri = copay.HDPath.parseBitcoinURI(value);
|
||||||
|
|
||||||
|
// Is this a payment protocol URI (BIP-72)?
|
||||||
if (uri && uri.merchant) {
|
if (uri && uri.merchant) {
|
||||||
scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
|
scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
|
||||||
var txp = { merchant: merchantData };
|
if (err) {
|
||||||
|
// XXX where would we send this error?
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var expires = new Date(txp.merchant.pr.expires * 1000);
|
var expires = new Date(merchantData.pr.expires * 1000);
|
||||||
var memo = txp.merchant.pr.memo;
|
var memo = merchantData.pr.memo;
|
||||||
var payment_url = txp.merchant.pr.payment_url;
|
var payment_url = merchantData.pr.payment_url;
|
||||||
var total = txp.merchant.total;
|
var total = merchantData.total;
|
||||||
|
|
||||||
if (typeof total === 'string') {
|
if (typeof total === 'string') {
|
||||||
total = bitcore.bignum(total, 10).toBuffer();
|
total = bitcore.bignum(total, 10).toBuffer();
|
||||||
|
@ -46,14 +47,15 @@ angular.module('copayApp.directives')
|
||||||
var tamount = angular.element(
|
var tamount = angular.element(
|
||||||
document.querySelector('div.send-note > p[ng-class]:nth-of-type(2)'));
|
document.querySelector('div.send-note > p[ng-class]:nth-of-type(2)'));
|
||||||
tamount.attr('class',
|
tamount.attr('class',
|
||||||
tamount.attr('class').replace(' hidden', ''))
|
tamount.attr('class').replace('hidden', '').trim())
|
||||||
tamount.text(total + ' (CA: ' + ca
|
tamount.text(total + ' (CA: ' + ca
|
||||||
+ '. Expires: '
|
+ '. Expires: '
|
||||||
+ expires.toISOString()
|
+ expires.toISOString()
|
||||||
+ '): ' + memo);
|
+ '): ' + memo);
|
||||||
|
|
||||||
|
ctrl.$setValidity('validAddress', true);
|
||||||
});
|
});
|
||||||
|
|
||||||
ctrl.$setValidity('validAddress', true);
|
|
||||||
return 'Merchant: '+ uri.merchant;
|
return 'Merchant: '+ uri.merchant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -881,10 +881,8 @@ Wallet.prototype.createPaymentTx = function(options, cb) {
|
||||||
|
|
||||||
var req = this.paymentRequests[options.uri];
|
var req = this.paymentRequests[options.uri];
|
||||||
if (req) {
|
if (req) {
|
||||||
req.options.memo = options.memo;
|
|
||||||
req.options.fetch = false;
|
|
||||||
delete this.paymentRequests[options.uri];
|
delete this.paymentRequests[options.uri];
|
||||||
this.receivePaymentRequest(req.options, req.pr, cb);
|
this.receivePaymentRequest(options, req.pr, cb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -925,10 +923,10 @@ Wallet.prototype.fetchPaymentTx = function(options, cb) {
|
||||||
return cb(null, req.merchantData);
|
return cb(null, req.merchantData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.createPaymentTx(options, function(err, merchantData, options, pr) {
|
return this.createPaymentTx(options, function(err, merchantData, pr) {
|
||||||
|
if (err) return cb(err);
|
||||||
self.paymentRequests[options.uri] = {
|
self.paymentRequests[options.uri] = {
|
||||||
merchantData: merchantData,
|
merchantData: merchantData,
|
||||||
options: options,
|
|
||||||
pr: pr
|
pr: pr
|
||||||
};
|
};
|
||||||
return cb(null, merchantData);
|
return cb(null, merchantData);
|
||||||
|
@ -1020,7 +1018,7 @@ Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
|
||||||
return this.getUnspent(function(err, unspent) {
|
return this.getUnspent(function(err, unspent) {
|
||||||
if (options.fetch) {
|
if (options.fetch) {
|
||||||
self.createPaymentTxSync(options, merchantData, unspent);
|
self.createPaymentTxSync(options, merchantData, unspent);
|
||||||
return cb(null, merchantData, options, pr);
|
return cb(null, merchantData, pr);
|
||||||
}
|
}
|
||||||
|
|
||||||
var ntxid = self.createPaymentTxSync(options, merchantData, unspent);
|
var ntxid = self.createPaymentTxSync(options, merchantData, unspent);
|
||||||
|
|
Loading…
Reference in New Issue