paypro: add fetchPaymentTx, use for form validation. improve css selection.
This commit is contained in:
parent
b7b7b2e38e
commit
6b6e251511
2 changed files with 53 additions and 40 deletions
|
|
@ -17,59 +17,59 @@ angular.module('copayApp.directives')
|
||||||
var uri = copay.HDPath.parseBitcoinURI(value);
|
var uri = copay.HDPath.parseBitcoinURI(value);
|
||||||
|
|
||||||
if (uri && uri.merchant) {
|
if (uri && uri.merchant) {
|
||||||
var total = bitcore
|
// XXX This might be unwise, it might be better to
|
||||||
.bignum('1000')
|
// create a tentative TX proposal here.
|
||||||
.div(config.unitToSatoshi)
|
scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) {
|
||||||
.toString(10);
|
// scope.wallet.createPaymentTx(uri.merchant, function(ntxid, ca) {
|
||||||
|
// var txp = scope.wallet.txProposals.txps[ntxid];
|
||||||
|
// if (!txp) return;
|
||||||
|
var txp = { merchant: merchantData };
|
||||||
|
|
||||||
var amount = angular.element(angular
|
var expires = new Date(txp.merchant.pr.expires * 1000);
|
||||||
.element(document)
|
|
||||||
.find('form')
|
|
||||||
.find('input')[1]);
|
|
||||||
amount.val(total);
|
|
||||||
amount.attr('disabled', true);
|
|
||||||
|
|
||||||
var tamount = angular.element(angular
|
|
||||||
.element(document)
|
|
||||||
.find('section')
|
|
||||||
.find('p')[1]);
|
|
||||||
tamount.attr('class',
|
|
||||||
tamount.attr('class').replace(' hidden', ''));
|
|
||||||
tamount.text(total
|
|
||||||
+ ' (CA: Internet Widgets Pty Ltd. Expires: '
|
|
||||||
+ new Date().toISOString()
|
|
||||||
+ '): Hi, we\'d like some bitcoin.');
|
|
||||||
|
|
||||||
scope.wallet.createPaymentTx(uri.merchant, function(ntxid, ca) {
|
|
||||||
var txp = scope.wallet.txProposals.txps[ntxid];
|
|
||||||
if (!txp) return;
|
|
||||||
|
|
||||||
var expires = txp.merchant.pr.expires;
|
|
||||||
var memo = txp.merchant.pr.memo;
|
var memo = txp.merchant.pr.memo;
|
||||||
var payment_url = txp.merchant.pr.payment_url;
|
var payment_url = txp.merchant.pr.payment_url;
|
||||||
var total = txp.merchant.total;
|
var total = txp.merchant.total;
|
||||||
|
|
||||||
var total = bitcore
|
if (typeof total === 'string') {
|
||||||
.bignum.fromBuffer(txp.merchant.total)
|
total = bitcore.bignum(total, 10).toBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
total = bitcore
|
||||||
|
.bignum.fromBuffer(total)
|
||||||
.div(config.unitToSatoshi)
|
.div(config.unitToSatoshi)
|
||||||
.toString(10);
|
.toString(10);
|
||||||
|
|
||||||
var amount = angular.element(angular
|
// var amount = angular.element(angular
|
||||||
.element(document)
|
// .element(document)
|
||||||
.find('form')
|
// .find('form')
|
||||||
.find('input')[1]);
|
// .find('input')[1]);
|
||||||
|
|
||||||
|
var amount = angular.element(
|
||||||
|
document.querySelector('input#amount'));
|
||||||
amount.val(total);
|
amount.val(total);
|
||||||
amount.attr('disabled', true);
|
amount.attr('disabled', true);
|
||||||
|
|
||||||
var tamount = angular.element(angular
|
// var sendto = angular.element(angular
|
||||||
.element(document)
|
// .element(document)
|
||||||
.find('section')
|
// .find('section')
|
||||||
.find('p')[1]);
|
// .find('p')[0]);
|
||||||
|
|
||||||
|
var sendto = angular.element(
|
||||||
|
document.querySelector('div.send-note > p[ng-class]:first-of-type'));
|
||||||
|
sendto.html(sendto.html() + '<br><b>Server:</b> ' + memo);
|
||||||
|
|
||||||
|
// var tamount = angular.element(angular
|
||||||
|
// .element(document)
|
||||||
|
// .find('section')
|
||||||
|
// .find('p')[1]);
|
||||||
|
|
||||||
|
var tamount = angular.element(
|
||||||
|
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', ''))
|
||||||
tamount.text(total + ' (CA: ' + ca
|
tamount.text(total + ' (CA: ' + ca
|
||||||
+ '. Expires: '
|
+ '. Expires: '
|
||||||
+ new Date(expires * 1000).toISOString()
|
+ expires.toISOString()
|
||||||
+ '): ' + memo);
|
+ '): ' + memo);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -898,6 +898,15 @@ Wallet.prototype.createPaymentTx = function(options, cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Wallet.prototype.fetchPaymentTx = function(options, cb) {
|
||||||
|
options = options || {};
|
||||||
|
if (typeof options === 'string') {
|
||||||
|
options = { uri: options };
|
||||||
|
}
|
||||||
|
options.fetch = true;
|
||||||
|
return this.createPaymentTx(options, cb);
|
||||||
|
};
|
||||||
|
|
||||||
Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
|
Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|
@ -977,9 +986,13 @@ Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
|
||||||
ca: ca,
|
ca: ca,
|
||||||
},
|
},
|
||||||
request_url: options.uri || options.url,
|
request_url: options.uri || options.url,
|
||||||
total: bignum('0').toString(10)
|
total: bignum('0', 10).toString(10)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (options.fetch) {
|
||||||
|
return cb(null, merchantData);
|
||||||
|
}
|
||||||
|
|
||||||
return this.getUnspent(function(err, unspent) {
|
return this.getUnspent(function(err, unspent) {
|
||||||
var ntxid = self.createPaymentTxSync(options, merchantData, unspent);
|
var ntxid = self.createPaymentTxSync(options, merchantData, unspent);
|
||||||
if (ntxid) {
|
if (ntxid) {
|
||||||
|
|
@ -1019,7 +1032,7 @@ Wallet.prototype.sendPaymentTx = function(ntxid, options, cb) {
|
||||||
|| self.publicKeyRing.getPubKeys(0, false, this.getMyCopayerId())[0];
|
|| self.publicKeyRing.getPubKeys(0, false, this.getMyCopayerId())[0];
|
||||||
|
|
||||||
if (options.refund_to) {
|
if (options.refund_to) {
|
||||||
var total = bignum('0');
|
var total = bignum('0', 10);
|
||||||
for (var i = 0; i < tx.outs.length - 1; i++) {
|
for (var i = 0; i < tx.outs.length - 1; i++) {
|
||||||
total = total.add(bignum.fromBuffer(tx.outs[i].v));
|
total = total.add(bignum.fromBuffer(tx.outs[i].v));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue