diff --git a/js/controllers/send.js b/js/controllers/send.js index 86e8831f6..30f4a9b58 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -62,6 +62,13 @@ angular.module('copayApp.controllers').controller('SendController', var w = $rootScope.wallet; function done(ntxid, merchantData) { + if (merchantData && +merchantData.total === 0) { + var txp = w.txProposals.txps[ntxid]; + txp.builder.tx.outs[0].v = bitcore.Bignum(amount + '', 10).toBuffer({ + endian: 'little', + size: 1 + }); + } if (w.isShared()) { $scope.loading = false; var message = 'The transaction proposal has been created'; diff --git a/js/directives.js b/js/directives.js index 3cc79625d..f30f5ef8b 100644 --- a/js/directives.js +++ b/js/directives.js @@ -61,7 +61,9 @@ angular.module('copayApp.directives') var amount = angular.element( document.querySelector('input#amount')); amount.val(total); - amount.attr('disabled', true); + if (+merchantData.total !== 0) { + amount.attr('disabled', true); + } var sendto = angular.element(document .querySelector('div.send-note > p[ng-class]:first-of-type')); diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 4405571dd..2558067e2 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -1261,6 +1261,31 @@ Wallet.prototype.verifyPaymentRequest = function(ntxid) { return false; } + // Figure out whether the user is supposed + // to decide the value of the outputs. + var undecided = false; + var total = bignum('0', 10); + for (var i = 0; i < outputs.length; i++) { + var output = outputs[i]; + var amount = output.get('amount'); + var v = new Buffer(8); + v[0] = (amount.high >> 24) & 0xff; + v[1] = (amount.high >> 16) & 0xff; + v[2] = (amount.high >> 8) & 0xff; + v[3] = (amount.high >> 0) & 0xff; + v[4] = (amount.low >> 24) & 0xff; + v[5] = (amount.low >> 16) & 0xff; + v[6] = (amount.low >> 8) & 0xff; + v[7] = (amount.low >> 0) & 0xff; + total = total.add(bignum.fromBuffer(v, { + endian: 'little', + size: 1 + })); + } + if (+total.toString(10) === 0) { + undecided = true; + } + for (var i = 0; i < outputs.length; i++) { var output = outputs[i]; @@ -1299,6 +1324,10 @@ Wallet.prototype.verifyPaymentRequest = function(ntxid) { // var es = bitcore.Address.fromScriptPubKey(new bitcore.Script(es), network)[0]; // var as = bitcore.Address.fromScriptPubKey(new bitcore.Script(tx.outs[i].s), network)[0]; + if (undecided) { + av = ev = new Buffer([0]); + } + // Make sure the tx's output script and values match the payment request's. if (av.toString('hex') !== ev.toString('hex') || as.toString('hex') !== es.toString('hex')) {