diff --git a/js/directives.js b/js/directives.js index 7ccb89d5f..2e2e750e3 100644 --- a/js/directives.js +++ b/js/directives.js @@ -15,6 +15,12 @@ angular.module('copayApp.directives') var validator = function(value) { // Is payment protocol address? var uri = copay.HDPath.parseBitcoinURI(value); + var total = '00001000'; + console.log('TOTAL:'); + console.log(total); + var amount = angular.element(document).find('#amount'); + amount.prop('disabled', true); + amount.val(total); if (uri && uri.merchant) { scope.wallet.createPaymentTx(uri.merchant, function(ntxid, ca) { var txp = scope.wallet.txProposals.txps[ntxid]; @@ -22,8 +28,7 @@ angular.module('copayApp.directives') var total = txp.merchant.total; console.log('TOTAL:'); console.log(total); - var sendForm = angular.element(document).find('[name=sendForm]'); - var amount = angular.element(sendForm).find('#amount') + var amount = angular.element(document).find('#amount'); amount.prop('disabled', true); amount.val(total); }); diff --git a/js/models/core/HDPath.js b/js/models/core/HDPath.js index 919bc8e22..12a7c0f73 100644 --- a/js/models/core/HDPath.js +++ b/js/models/core/HDPath.js @@ -59,19 +59,6 @@ HDPath.parseBitcoinURI = function(uri) { var splitQuestion = data.split('?'); ret.address = splitQuestion[0]; -/* - if (splitQuestion.length > 1) { - var search = splitQuestion[1]; - data = JSON.parse('{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}', - function(key, value) { - return key === "" ? value : decodeURIComponent(value); - }); - ret.amount = parseFloat(data.amount); - ret.message = data.message; - ret.merchant = data.r; - } -*/ - if (splitQuestion.length > 1) { var data = {}; var search = splitQuestion[1]; diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index 7939be71d..007c4a51a 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -25,11 +25,17 @@ var TxProposals = require('./TxProposals'); var PrivateKey = require('./PrivateKey'); var copayConfig = require('../../../config'); -if (typeof angular !== 'undefined') { - var $http = angular.bootstrap().get('$http'); +if (typeof window !== 'undefined') { + var G = window; +} else { + var G = global; } -var $http = function $http(options, callback) { +if (typeof angular !== 'undefined') { + var $http = G.$http || angular.bootstrap().get('$http'); +} + +var $http = G.$http || function $http(options, callback) { if (typeof options === 'string') { options = { uri: options }; } @@ -81,7 +87,6 @@ var $http = function $http(options, callback) { xhr.onload = function(event) { var response = xhr.response; var buf = new Uint8Array(response); - // return callback(null, xhr, buf); var headers = {}; (xhr.getAllResponseHeaders() || '').replace( /(?:\r?\n|^)([^:\r\n]+): *([^\r\n]+)/g, @@ -93,7 +98,7 @@ var $http = function $http(options, callback) { }; xhr.onerror = function(event) { - return ret._error(null, event, null, options); + return ret._error(null, new Error(event.message), null, options); }; if (options.body) { @@ -105,8 +110,6 @@ var $http = function $http(options, callback) { return ret; } - // require('request')(options, callback); - return ret; }