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