paypro: stop using global $http.
This commit is contained in:
parent
d51c1c552f
commit
052e2522be
3 changed files with 13 additions and 21 deletions
|
|
@ -25,10 +25,6 @@ var TxProposals = require('./TxProposals');
|
||||||
var PrivateKey = require('./PrivateKey');
|
var PrivateKey = require('./PrivateKey');
|
||||||
var copayConfig = require('../../../config');
|
var copayConfig = require('../../../config');
|
||||||
|
|
||||||
var G = typeof window !== 'undefined'
|
|
||||||
? window
|
|
||||||
: global;
|
|
||||||
|
|
||||||
function Wallet(opts) {
|
function Wallet(opts) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|
@ -804,7 +800,7 @@ Wallet.prototype.createPaymentTx = function(options, cb) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $http({
|
return Wallet.request({
|
||||||
method: options.method || 'POST',
|
method: options.method || 'POST',
|
||||||
url: options.uri,
|
url: options.uri,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -1041,7 +1037,7 @@ Wallet.prototype.sendPaymentTx = function(ntxid, options, cb) {
|
||||||
view[i] = pay[i];
|
view[i] = pay[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $http({
|
return Wallet.request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: txp.merchant.pr.pd.payment_url,
|
url: txp.merchant.pr.pd.payment_url,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -1719,10 +1715,10 @@ Wallet.prototype.verifySignedJson = function(senderId, payload, signature) {
|
||||||
// deviates from BIP-70.
|
// deviates from BIP-70.
|
||||||
|
|
||||||
// if (typeof angular !== 'undefined') {
|
// if (typeof angular !== 'undefined') {
|
||||||
// G.$http = G.$http || angular.bootstrap().get('$http');
|
// var $http = angular.bootstrap().get('$http');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
G.$http = G.$http || function $http(options, callback) {
|
Wallet.request = function(options, callback) {
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
options = { uri: options };
|
options = { uri: options };
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@ var is_browser = typeof process == 'undefined'
|
||||||
|| typeof process.versions === 'undefined';
|
|| typeof process.versions === 'undefined';
|
||||||
var bitcore = bitcore || require('bitcore');
|
var bitcore = bitcore || require('bitcore');
|
||||||
var PayPro = bitcore.PayPro;
|
var PayPro = bitcore.PayPro;
|
||||||
|
var Wallet = require('../../js/models/core/Wallet');
|
||||||
var G = is_browser ? window : global;
|
|
||||||
G.SSL_UNTRUSTED = true;
|
|
||||||
|
|
||||||
var x509 = {
|
var x509 = {
|
||||||
priv: ''
|
priv: ''
|
||||||
|
|
@ -93,17 +91,14 @@ x509.der = new Buffer(x509.der, 'base64');
|
||||||
x509.pem = new Buffer(x509.pem, 'base64');
|
x509.pem = new Buffer(x509.pem, 'base64');
|
||||||
|
|
||||||
function startServer(cb) {
|
function startServer(cb) {
|
||||||
if (G.$http && G.$http.__server) {
|
if (Wallet.request._server) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
return cb(null, G.$http.__server);
|
return cb(null, Wallet.request._server);
|
||||||
}, 1);
|
}, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var old;
|
var old = Wallet.request;
|
||||||
if (G.$http) {
|
|
||||||
old = G.$http;
|
|
||||||
}
|
|
||||||
|
|
||||||
var server = {
|
var server = {
|
||||||
POST: {
|
POST: {
|
||||||
|
|
@ -283,12 +278,12 @@ function startServer(cb) {
|
||||||
if (cb) return cb();
|
if (cb) return cb();
|
||||||
},
|
},
|
||||||
close: function(cb) {
|
close: function(cb) {
|
||||||
if (old) G.$http = old;
|
Wallet.request = old;
|
||||||
return cb();
|
return cb();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
G.$http = function(options) {
|
Wallet.request = function(options) {
|
||||||
var ret = {
|
var ret = {
|
||||||
success: function(cb) {
|
success: function(cb) {
|
||||||
this._success = cb;
|
this._success = cb;
|
||||||
|
|
@ -332,7 +327,7 @@ function startServer(cb) {
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
G.$http.__server = server;
|
Wallet.request._server = server;
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
return cb(null, server);
|
return cb(null, server);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
var chai = chai || require('chai');
|
var chai = chai || require('chai');
|
||||||
var should = chai.should();
|
var should = chai.should();
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var is_browser = (typeof process == 'undefined' || typeof process.versions === 'undefined');
|
var is_browser = typeof process == 'undefined'
|
||||||
|
|| typeof process.versions === 'undefined';
|
||||||
if (is_browser) {
|
if (is_browser) {
|
||||||
var copay = require('copay'); //browser
|
var copay = require('copay'); //browser
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue