From 64b38802bfcbeb1e17fdea13f71ff51215c1beaa Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Fri, 1 Aug 2014 20:22:11 -0700 Subject: [PATCH] paypro: fixes. clean up form reset from paypro. etc. --- js/controllers/send.js | 21 ------------ js/directives.js | 71 ++++++++++++++++++++-------------------- js/models/core/Wallet.js | 4 ++- 3 files changed, 38 insertions(+), 58 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index 9753a76e3..f215a29f6 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -64,13 +64,6 @@ angular.module('copayApp.controllers').controller('SendController', function done(ntxid, ca) { var txp = w.txProposals.txps[ntxid]; var merchantData = txp.merchant; - var amt = angular.element(document.querySelector('input#amount')); - var sendto = angular.element(document - .querySelector('div.send-note > p[ng-class]:first-of-type')); - var tamount = angular.element(document - .querySelector('div.send-note > p[ng-class]:nth-of-type(2)')); - var submit = angular.element(document.querySelector('button[type=submit]')); - var sendall = angular.element(document.querySelector('[title="Send all funds"]')); if (w.isShared()) { $scope.loading = false; var message = 'The transaction proposal has been created'; @@ -83,13 +76,6 @@ angular.module('copayApp.controllers').controller('SendController', } notification.success('Success!', message); $scope.loadTxs(); - if (merchantData) { - amt.attr('disabled', false); - sendto.html(sendto.html().replace(/
Server:.*$/, '')); - tamount.html(''); - submit.attr('disabled', true); - sendall.attr('class', sendall.attr('class').replace(' hidden', '')); - } } else { w.sendTx(ntxid, function(txid, ca) { if (txid) { @@ -107,13 +93,6 @@ angular.module('copayApp.controllers').controller('SendController', } $scope.loading = false; $scope.loadTxs(); - if (merchantData) { - amt.attr('disabled', false); - sendto.html(sendto.html().replace(/
Server:.*$/, '')); - tamount.html(''); - submit.attr('disabled', true); - sendall.attr('class', sendall.attr('class').replace(' hidden', '')); - } }); } $rootScope.pendingPayment = null; diff --git a/js/directives.js b/js/directives.js index 58c99db2e..e1d009b44 100644 --- a/js/directives.js +++ b/js/directives.js @@ -44,11 +44,14 @@ angular.module('copayApp.directives') // XXX There needs to be a better way to do this: total = +total / config.unitToSatoshi; + // XXX Pretty much all of this code accesses the raw DOM. It's + // very bad, there's probably a better, more angular-y way to + // do things here. + var address = angular.element( document.querySelector('input#address')); - var amount = angular.element( - document.querySelector('input#amount')); + var amount = angular.element( document.querySelector('input#amount')); amount.val(total); amount.attr('disabled', true); @@ -67,8 +70,7 @@ angular.module('copayApp.directives') + expires.toISOString() + ')'); - var submit = angular.element( - document.querySelector('button[type=submit]')); + var submit = angular.element( document.querySelector('button[type=submit]')); submit.attr('disabled', false); var sendall = angular.element( @@ -76,39 +78,36 @@ angular.module('copayApp.directives') sendall.attr('class', sendall.attr('class') + ' hidden'); // Reset all the changes from the payment protocol weirdness. - //address.attr('ng-change', 'ppChange()'); - //scope.ppChange = scope.ppChange || function() { - //address.on('change', function(ev) { - scope.$watch('address', function(newValue, oldValue) { - var val = address.val(); - var uri = copay.HDPath.parseBitcoinURI(val || ''); - if (!uri || !uri.merchant) { - if (amount.attr('disabled') === true) { - amount.attr('disabled', false); + // XXX Bad hook. + if (!scope.__watchingAddress) { + scope.__watchingAddress = true; + scope.$watch('address', function(newValue, oldValue) { + var val = address.val(); + var uri = copay.HDPath.parseBitcoinURI(val || ''); + if (!uri || !uri.merchant) { + if (amount.attr('disabled')) { + amount.val(''); + amount.attr('disabled', false); + } + sendto.html(sendto.html().replace(/
Server:.*$/, '')); + if (!/hidden/.test(tamount.attr('class'))) { + tamount.attr(tamount.attr('class') + ' hidden'); + } + if (~tamount.html().indexOf('(CA: ')) { + tamount.html(''); + } + if (!submit.attr('disabled')) { + submit.attr('disabled', true); + } + if (/ hidden$/.test(sendall.attr('class'))) { + sendall.attr('class', + sendall.attr('class').replace(' hidden', '')); + } } - if (submit.attr('disabled') === false) { - submit.attr('disabled', true); - } - sendto.html(sendto.html().replace(/
Server:.*$/, '')); - if (!/hidden/.test(tamount.attr('class'))) { - tamount.attr(tamount.attr('class') + ' hidden'); - } - if (~tamount.html().indexOf('(CA: ')) { - tamount.html(''); - } - if (submit.attr('disabled') === false) { - submit.attr('disabled', true); - } - if (/ hidden$/.test(sendall.attr('class'))) { - sendall.attr('class', - sendall.attr('class').replace(' hidden', '')); - } - } - // TODO: Check paymentRequest expiration, - // delete if beyond expiration date. - //}; - }); - //scope.$apply(); // scope.$digest(); + // TODO: Check paymentRequest expiration, + // delete if beyond expiration date. + }); + } ctrl.$setValidity('validAddress', true); diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index a3ad9b40a..8e635cb56 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -1035,7 +1035,9 @@ Wallet.prototype.sendPaymentTx = function(ntxid, options, cb) { // 'Content-Length': (pay.byteLength || pay.length) + '', // 'Content-Transfer-Encoding': 'binary' }, - data: buf, // Technically how this should be done via XHR. + // Technically how this should be done via XHR (used to + // be the ArrayBuffer, now you send the View instead). + data: view, responseType: 'arraybuffer' }) .success(function(data, status, headers, config) {