diff --git a/js/controllers/send.js b/js/controllers/send.js index a33081250..a9d9995cf 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -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, diff --git a/js/directives.js b/js/directives.js index 0d65a4af5..aed56933d 100644 --- a/js/directives.js +++ b/js/directives.js @@ -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 }; diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 1700ec9b1..d1295d1a2 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -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');