mirror of https://github.com/BTCPrivate/copay.git
paypro: deal with cached payment requests properly.
This commit is contained in:
parent
af12b56678
commit
decd981bce
|
@ -94,8 +94,12 @@ angular.module('copayApp.controllers').controller('SendController',
|
|||
&& copay.HDPath.parseBitcoinURI(address);
|
||||
|
||||
if (uri && uri.merchant) {
|
||||
var data = w.paymentRequests[uri.merchant];
|
||||
if (data) {
|
||||
var req = w.paymentRequests[uri.merchant];
|
||||
if (req) {
|
||||
if (commentText) {
|
||||
req.options.memo = commentText;
|
||||
}
|
||||
w.receivePaymentRequest(req.options, req.pr, done);
|
||||
} else {
|
||||
w.createPaymentTx({
|
||||
uri: uri.merchant,
|
||||
|
|
|
@ -17,8 +17,6 @@ angular.module('copayApp.directives')
|
|||
var uri = copay.HDPath.parseBitcoinURI(value);
|
||||
|
||||
if (uri && uri.merchant) {
|
||||
// XXX This might be unwise, it might be better to
|
||||
// create a tentative TX proposal here.
|
||||
scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
|
||||
var txp = { merchant: merchantData };
|
||||
|
||||
|
|
|
@ -870,6 +870,7 @@ Wallet.prototype.createPaymentTx = function(options, cb) {
|
|||
if (typeof options === 'string') {
|
||||
options = { uri: options };
|
||||
}
|
||||
options.uri = options.uri || options.url;
|
||||
|
||||
if (options.uri.indexOf('bitcoin:') === 0) {
|
||||
options.uri = parseBitcoinURI(options.uri).merchant;
|
||||
|
@ -906,11 +907,13 @@ Wallet.prototype.fetchPaymentTx = function(options, cb) {
|
|||
if (typeof options === 'string') {
|
||||
options = { uri: options };
|
||||
}
|
||||
options.uri = options.uri || options.url;
|
||||
options.fetch = true;
|
||||
if (this.paymentRequests[options.uri]) {
|
||||
return cb(null, this.paymentRequests[options.uri].merchantData);
|
||||
}
|
||||
return this.createPaymentTx(options, function(err, merchantData, options, pr) {
|
||||
var id = self.hashMerchantData(merchantData);
|
||||
self.paymentRequests[id] = {
|
||||
id: id,
|
||||
self.paymentRequests[options.uri] = {
|
||||
merchantData: merchantData,
|
||||
options: options,
|
||||
pr: pr
|
||||
|
@ -919,17 +922,13 @@ Wallet.prototype.fetchPaymentTx = function(options, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
Wallet.hashMerchantData =
|
||||
Wallet.prototype.hashMerchantData = function(merchantData) {
|
||||
return merchantData.request_url
|
||||
+ ':' + merchantData.pr.payment_url
|
||||
+ ':' + merchantData.total
|
||||
+ ':' + merchantData.pr.pd.merchant_data;
|
||||
};
|
||||
|
||||
Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
|
||||
var self = this;
|
||||
|
||||
if (this.paymentRequests[options.uri]) {
|
||||
delete this.paymentRequests[options.uri];
|
||||
}
|
||||
|
||||
var ver = pr.get('payment_details_version');
|
||||
var pki_type = pr.get('pki_type');
|
||||
var pki_data = pr.get('pki_data');
|
||||
|
|
Loading…
Reference in New Issue