mirror of https://github.com/BTCPrivate/copay.git
paypro: remove temporary xhr shim.
This commit is contained in:
parent
a9b522888e
commit
cf674dced2
|
@ -35,90 +35,6 @@ if (typeof angular !== 'undefined') {
|
||||||
G.$http = G.$http || angular.bootstrap().get('$http');
|
G.$http = G.$http || angular.bootstrap().get('$http');
|
||||||
}
|
}
|
||||||
|
|
||||||
G.$http = function $http(options, callback) {
|
|
||||||
if (typeof options === 'string') {
|
|
||||||
options = { uri: options };
|
|
||||||
}
|
|
||||||
|
|
||||||
options.method = options.method || 'GET';
|
|
||||||
options.headers = options.headers || {};
|
|
||||||
|
|
||||||
var ret = {
|
|
||||||
success: function(cb) {
|
|
||||||
this._success = cb;
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
error: function(cb) {
|
|
||||||
this._error = cb;
|
|
||||||
return this;
|
|
||||||
},
|
|
||||||
_success: function() {
|
|
||||||
;
|
|
||||||
},
|
|
||||||
_error: function(_, err) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var method = (options.method || 'GET').toUpperCase();
|
|
||||||
var uri = options.uri || options.url;
|
|
||||||
var req = options;
|
|
||||||
|
|
||||||
req.headers = req.headers || {};
|
|
||||||
req.body = req.body || {};
|
|
||||||
|
|
||||||
if (typeof XMLHttpRequest !== 'undefined') {
|
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open(method, uri, true);
|
|
||||||
|
|
||||||
Object.keys(options.headers).forEach(function(key) {
|
|
||||||
var val = options.headers[key];
|
|
||||||
if (key === 'Content-Length') return;
|
|
||||||
if (key === 'Content-Transfer-Encoding') return;
|
|
||||||
xhr.setRequestHeader(key, val);
|
|
||||||
});
|
|
||||||
|
|
||||||
// For older browsers:
|
|
||||||
// xhr.overrideMimeType('text/plain; charset=x-user-defined');
|
|
||||||
|
|
||||||
// Newer browsers:
|
|
||||||
xhr.responseType = 'arraybuffer';
|
|
||||||
|
|
||||||
// xhr.onreadystatechange = function() {
|
|
||||||
// if (xhr.readyState == 4) {
|
|
||||||
// ;
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
xhr.onload = function(event) {
|
|
||||||
var response = xhr.response;
|
|
||||||
var buf = new Uint8Array(response);
|
|
||||||
var headers = {};
|
|
||||||
(xhr.getAllResponseHeaders() || '').replace(
|
|
||||||
/(?:\r?\n|^)([^:\r\n]+): *([^\r\n]+)/g,
|
|
||||||
function($0, $1, $2) {
|
|
||||||
headers[$1.toLowerCase()] = $2;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return ret._success(buf, xhr.status, headers, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
xhr.onerror = function(event) {
|
|
||||||
return ret._error(null, new Error(event.message), null, options);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (options.body) {
|
|
||||||
xhr.send(options.body);
|
|
||||||
} else {
|
|
||||||
xhr.send(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
};
|
|
||||||
|
|
||||||
function Wallet(opts) {
|
function Wallet(opts) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue