mirror of https://github.com/BTCPrivate/copay.git
refactor baseUrl in angular-bwc
This commit is contained in:
parent
a8ef458941
commit
6bd316424a
|
@ -6,31 +6,9 @@ bwcModule.constant('MODULE_VERSION', '1.0.0');
|
||||||
bwcModule.provider("bwcService", function() {
|
bwcModule.provider("bwcService", function() {
|
||||||
var provider = {};
|
var provider = {};
|
||||||
|
|
||||||
var config = {
|
|
||||||
baseUrl: 'https://bws.bitpay.com/bws/api',
|
|
||||||
verbose: null,
|
|
||||||
transports: null
|
|
||||||
};
|
|
||||||
|
|
||||||
provider.setBaseUrl = function(url) {
|
|
||||||
config.baseUrl = url;
|
|
||||||
};
|
|
||||||
|
|
||||||
provider.setVerbose = function(v) {
|
|
||||||
config.verbose = v ? true : false;
|
|
||||||
};
|
|
||||||
|
|
||||||
provider.$get = function() {
|
provider.$get = function() {
|
||||||
var service = {};
|
var service = {};
|
||||||
|
|
||||||
service.setBaseUrl = function(url) {
|
|
||||||
config.baseUrl = url;
|
|
||||||
};
|
|
||||||
|
|
||||||
service.setTransports = function(transports) {
|
|
||||||
config.transports = transports;
|
|
||||||
};
|
|
||||||
|
|
||||||
service.getBitcore = function() {
|
service.getBitcore = function() {
|
||||||
return Client.Bitcore;
|
return Client.Bitcore;
|
||||||
};
|
};
|
||||||
|
@ -46,20 +24,21 @@ bwcModule.provider("bwcService", function() {
|
||||||
service.buildTx = Client.buildTx;
|
service.buildTx = Client.buildTx;
|
||||||
service.parseSecret = Client.parseSecret;
|
service.parseSecret = Client.parseSecret;
|
||||||
service.Client = Client;
|
service.Client = Client;
|
||||||
service.config = config;
|
|
||||||
|
|
||||||
service.getUtils = function() {
|
service.getUtils = function() {
|
||||||
return Client.Utils;
|
return Client.Utils;
|
||||||
};
|
};
|
||||||
|
|
||||||
service.getClient = function(walletData) {
|
service.getClient = function(walletData, opts) {
|
||||||
|
|
||||||
|
//note opts use `baseurl` all lowercase;
|
||||||
var bwc = new Client({
|
var bwc = new Client({
|
||||||
baseUrl: config.baseUrl,
|
baseUrl: opts.baseurl || 'https://bws.bitpay.com/bws/api',
|
||||||
verbose: config.verbose,
|
verbose: opts.verbose,
|
||||||
transports: config.transports
|
transports: ['polling'],
|
||||||
});
|
});
|
||||||
if (walletData)
|
if (walletData)
|
||||||
bwc.import(walletData);
|
bwc.import(walletData, opts);
|
||||||
return bwc;
|
return bwc;
|
||||||
};
|
};
|
||||||
return service;
|
return service;
|
||||||
|
|
|
@ -67,7 +67,6 @@ angular.module('copayApp.services')
|
||||||
var defaults = configService.getDefaults();
|
var defaults = configService.getDefaults();
|
||||||
|
|
||||||
bwcService.setBaseUrl((config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url);
|
bwcService.setBaseUrl((config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url);
|
||||||
bwcService.setTransports(['polling']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
root.setWalletClient = function(credentials) {
|
root.setWalletClient = function(credentials) {
|
||||||
|
@ -219,10 +218,7 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
root._seedWallet = function(opts, cb) {
|
root._seedWallet = function(opts, cb) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
if (opts.bwsurl)
|
var walletClient = bwcService.getClient(null, opts);
|
||||||
bwcService.setBaseUrl(opts.bwsurl);
|
|
||||||
|
|
||||||
var walletClient = bwcService.getClient();
|
|
||||||
var network = opts.networkName || 'livenet';
|
var network = opts.networkName || 'livenet';
|
||||||
|
|
||||||
|
|
||||||
|
@ -471,10 +467,8 @@ angular.module('copayApp.services')
|
||||||
};
|
};
|
||||||
|
|
||||||
root.importWallet = function(str, opts, cb) {
|
root.importWallet = function(str, opts, cb) {
|
||||||
if (opts.bwsurl)
|
|
||||||
bwcService.setBaseUrl(opts.bwsurl);
|
|
||||||
|
|
||||||
var walletClient = bwcService.getClient();
|
var walletClient = bwcService.getClient(null, opts);
|
||||||
|
|
||||||
$log.debug('Importing Wallet:', opts);
|
$log.debug('Importing Wallet:', opts);
|
||||||
try {
|
try {
|
||||||
|
@ -573,7 +567,6 @@ angular.module('copayApp.services')
|
||||||
|
|
||||||
configService.get(function(err) {
|
configService.get(function(err) {
|
||||||
bwcService.setBaseUrl(defaults.bws.url);
|
bwcService.setBaseUrl(defaults.bws.url);
|
||||||
bwcService.setTransports(['polling']);
|
|
||||||
root._createNewProfile(opts, function(err, p) {
|
root._createNewProfile(opts, function(err, p) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
|
|
||||||
|
|
|
@ -173,6 +173,14 @@ angular.module('copayApp.services')
|
||||||
storage.remove('backup-' + walletId, cb);
|
storage.remove('backup-' + walletId, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
root.setDerivationTestFlag = function(walletId, ua, cb) {
|
||||||
|
storage.set('DerivationTest-'+walletId+ua.replace(' ', ''), true, cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
root.getDerivationTestFlag = function(walletId, ua, cb) {
|
||||||
|
storage.get('DerivationTest-'+walletId+ua.replace(' ', ''), cb);
|
||||||
|
};
|
||||||
|
|
||||||
root.setCleanAndScanAddresses = function(walletId, cb) {
|
root.setCleanAndScanAddresses = function(walletId, cb) {
|
||||||
storage.set('CleanAndScanAddresses', walletId, cb);
|
storage.set('CleanAndScanAddresses', walletId, cb);
|
||||||
};
|
};
|
||||||
|
|
|
@ -93,13 +93,11 @@ mocks.init = function(fixtures, controllerName, opts, done) {
|
||||||
|
|
||||||
$delegate.getClient = function(walletData) {
|
$delegate.getClient = function(walletData) {
|
||||||
|
|
||||||
var bwc = new $delegate.Client({
|
var bwc = new $delegate.Client();
|
||||||
baseUrl: config.baseUrl,
|
|
||||||
verbose: config.verbose,
|
|
||||||
transports: config.transports
|
|
||||||
});
|
|
||||||
if (walletData)
|
if (walletData)
|
||||||
bwc.import(walletData);
|
bwc.import(walletData, {
|
||||||
|
baseUrl: config.baseUrl
|
||||||
|
});
|
||||||
|
|
||||||
function createHash(method, url, args) {
|
function createHash(method, url, args) {
|
||||||
var headers = JSON.stringify(bwc._getHeaders(method, url, args));
|
var headers = JSON.stringify(bwc._getHeaders(method, url, args));
|
||||||
|
|
Loading…
Reference in New Issue