mirror of https://github.com/BTCPrivate/copay.git
paypro: fix endianess. fix fields. fix elements in a messy way.
This commit is contained in:
parent
7b678a91b5
commit
91b2d9dd02
|
@ -65,6 +65,8 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
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'));
|
var amt = angular.element(document.querySelector('input#amount'));
|
||||||
|
var submit = angular.element(document.querySelector('button[type=submit]'));
|
||||||
|
var sendall = angular.element(document.querySelector('[title="Send all funds"]'));
|
||||||
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';
|
||||||
|
@ -79,6 +81,8 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
$scope.loadTxs();
|
$scope.loadTxs();
|
||||||
if (merchantData) {
|
if (merchantData) {
|
||||||
amt.attr('disabled', false);
|
amt.attr('disabled', false);
|
||||||
|
submit.attr('disabled', true);
|
||||||
|
sendall.attr('class', sendall.attr('class').replace(' hidden', ''));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
w.sendTx(ntxid, function(txid, ca) {
|
w.sendTx(ntxid, function(txid, ca) {
|
||||||
|
@ -99,6 +103,8 @@ angular.module('copayApp.controllers').controller('SendController',
|
||||||
$scope.loadTxs();
|
$scope.loadTxs();
|
||||||
if (merchantData) {
|
if (merchantData) {
|
||||||
amt.attr('disabled', false);
|
amt.attr('disabled', false);
|
||||||
|
submit.attr('disabled', true);
|
||||||
|
sendall.attr('class', sendall.attr('class').replace(' hidden', ''));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ angular.module('copayApp.directives')
|
||||||
|
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
var Address = bitcore.Address;
|
var Address = bitcore.Address;
|
||||||
|
var bignum = bitcore.Bignum;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
require: 'ngModel',
|
require: 'ngModel',
|
||||||
|
@ -21,17 +22,23 @@ angular.module('copayApp.directives')
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var expires = new Date(merchantData.pr.expires * 1000);
|
var expires = new Date(merchantData.pr.pd.expires * 1000);
|
||||||
var memo = merchantData.pr.memo;
|
var memo = merchantData.pr.pd.memo;
|
||||||
var payment_url = merchantData.pr.payment_url;
|
var payment_url = merchantData.pr.pd.payment_url;
|
||||||
var total = merchantData.total;
|
var total = merchantData.total;
|
||||||
|
|
||||||
if (typeof total === 'string') {
|
if (typeof total === 'string') {
|
||||||
total = bitcore.bignum(total, 10).toBuffer();
|
total = bignum(total, 10).toBuffer({
|
||||||
|
endian: 'little',
|
||||||
|
size: 1
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
total = bitcore
|
total = bignum
|
||||||
.bignum.fromBuffer(total)
|
.fromBuffer(total, {
|
||||||
|
endian: 'little',
|
||||||
|
size: 1
|
||||||
|
})
|
||||||
.div(config.unitToSatoshi)
|
.div(config.unitToSatoshi)
|
||||||
.toString(10);
|
.toString(10);
|
||||||
|
|
||||||
|
@ -47,12 +54,20 @@ 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', '').trim())
|
tamount.attr('class').replace(' hidden', ''))
|
||||||
tamount.text(total + ' (CA: ' + ca
|
tamount.text(total + ' (CA: ' + merchantData.pr.ca
|
||||||
+ '. Expires: '
|
+ '. Expires: '
|
||||||
+ expires.toISOString()
|
+ expires.toISOString()
|
||||||
+ '): ' + memo);
|
+ '): ' + memo);
|
||||||
|
|
||||||
|
var submit = angular.element(
|
||||||
|
document.querySelector('button[type=submit]'));
|
||||||
|
submit.attr('disabled', false);
|
||||||
|
|
||||||
|
var sendall = angular.element(
|
||||||
|
document.querySelector('[title="Send all funds"]'));
|
||||||
|
sendall.attr('class', sendall.attr('class') + ' hidden');
|
||||||
|
|
||||||
// ctrl.$setValidity('validAddress', true);
|
// ctrl.$setValidity('validAddress', true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1004,17 +1004,20 @@ Wallet.prototype.receivePaymentRequest = function(options, pr, cb) {
|
||||||
}),
|
}),
|
||||||
time: time,
|
time: time,
|
||||||
expires: expires,
|
expires: expires,
|
||||||
memo: memo,
|
memo: memo || 'No Message',
|
||||||
payment_url: payment_url,
|
payment_url: payment_url,
|
||||||
merchant_data: merchant_data.toString('hex')
|
merchant_data: merchant_data.toString('hex')
|
||||||
},
|
},
|
||||||
signature: sig,
|
signature: sig,
|
||||||
ca: ca,
|
ca: ca,
|
||||||
},
|
},
|
||||||
request_url: options.uri || options.url,
|
request_url: options.uri,
|
||||||
total: bignum('0', 10).toString(10)
|
total: bignum('0', 10).toString(10)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log('receivePaymentRequest');
|
||||||
|
console.log(merchantData);
|
||||||
|
|
||||||
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);
|
||||||
|
@ -1059,10 +1062,12 @@ 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', 10);
|
var total = txp.merchant.pr.pd.outputs.reduce(function(total, _, i) {
|
||||||
for (var i = 0; i < tx.outs.length - 1; i++) {
|
return total.add(bignum.fromBuffer(tx.outs[i].v, {
|
||||||
total = total.add(bignum.fromBuffer(tx.outs[i].v));
|
endian: 'little',
|
||||||
}
|
size: 1
|
||||||
|
}));
|
||||||
|
}, bugnum('0', 10));
|
||||||
var rpo = new PayPro();
|
var rpo = new PayPro();
|
||||||
rpo = rpo.makeOutput();
|
rpo = rpo.makeOutput();
|
||||||
rpo.set('amount', +total.toString(10));
|
rpo.set('amount', +total.toString(10));
|
||||||
|
@ -1164,7 +1169,7 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent)
|
||||||
merchantData.pr.pd.outputs.forEach(function(output) {
|
merchantData.pr.pd.outputs.forEach(function(output) {
|
||||||
outs.push({
|
outs.push({
|
||||||
address: self.getAddressesStr()[0]
|
address: self.getAddressesStr()[0]
|
||||||
|| 'mfWxJ45yp2SFn7UciZyNpvDKrzbhyfKrY8', // dummy address (testnet 0 * hash160)
|
|| '2N6J45pqfu5y7zgWDwXDAmdd8qzK1oRdz3A', // dummy address (testnet 0 * hash160)
|
||||||
amountSatStr: '0' // dummy amount
|
amountSatStr: '0' // dummy amount
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1185,6 +1190,9 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent)
|
||||||
var signed = b.sign(keys);
|
var signed = b.sign(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('createPaymentTxSync:1');
|
||||||
|
console.log(merchantData);
|
||||||
|
|
||||||
if (typeof merchantData.total === 'string') {
|
if (typeof merchantData.total === 'string') {
|
||||||
merchantData.total = bignum(merchantData.total, 10);
|
merchantData.total = bignum(merchantData.total, 10);
|
||||||
}
|
}
|
||||||
|
@ -1217,11 +1225,17 @@ Wallet.prototype.createPaymentTxSync = function(options, merchantData, unspent)
|
||||||
b.tx.outs[i].v = v;
|
b.tx.outs[i].v = v;
|
||||||
b.tx.outs[i].s = s;
|
b.tx.outs[i].s = s;
|
||||||
|
|
||||||
merchantData.total = merchantData.total.add(bignum.fromBuffer(v));
|
merchantData.total = merchantData.total.add(bignum.fromBuffer(v, {
|
||||||
|
endian: 'little',
|
||||||
|
size: 1
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
merchantData.total = merchantData.total.toString(10);
|
merchantData.total = merchantData.total.toString(10);
|
||||||
|
|
||||||
|
console.log('createPaymentTxSync:2');
|
||||||
|
console.log(merchantData);
|
||||||
|
|
||||||
if (options.fetch) return;
|
if (options.fetch) return;
|
||||||
|
|
||||||
this.log('');
|
this.log('');
|
||||||
|
|
Loading…
Reference in New Issue