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() {
|
||||
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() {
|
||||
var service = {};
|
||||
|
||||
service.setBaseUrl = function(url) {
|
||||
config.baseUrl = url;
|
||||
};
|
||||
|
||||
service.setTransports = function(transports) {
|
||||
config.transports = transports;
|
||||
};
|
||||
|
||||
service.getBitcore = function() {
|
||||
return Client.Bitcore;
|
||||
};
|
||||
|
@ -46,20 +24,21 @@ bwcModule.provider("bwcService", function() {
|
|||
service.buildTx = Client.buildTx;
|
||||
service.parseSecret = Client.parseSecret;
|
||||
service.Client = Client;
|
||||
service.config = config;
|
||||
|
||||
service.getUtils = function() {
|
||||
return Client.Utils;
|
||||
};
|
||||
|
||||
service.getClient = function(walletData) {
|
||||
service.getClient = function(walletData, opts) {
|
||||
|
||||
//note opts use `baseurl` all lowercase;
|
||||
var bwc = new Client({
|
||||
baseUrl: config.baseUrl,
|
||||
verbose: config.verbose,
|
||||
transports: config.transports
|
||||
baseUrl: opts.baseurl || 'https://bws.bitpay.com/bws/api',
|
||||
verbose: opts.verbose,
|
||||
transports: ['polling'],
|
||||
});
|
||||
if (walletData)
|
||||
bwc.import(walletData);
|
||||
bwc.import(walletData, opts);
|
||||
return bwc;
|
||||
};
|
||||
return service;
|
||||
|
|
|
@ -67,7 +67,6 @@ angular.module('copayApp.services')
|
|||
var defaults = configService.getDefaults();
|
||||
|
||||
bwcService.setBaseUrl((config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url);
|
||||
bwcService.setTransports(['polling']);
|
||||
}
|
||||
|
||||
root.setWalletClient = function(credentials) {
|
||||
|
@ -219,10 +218,7 @@ angular.module('copayApp.services')
|
|||
|
||||
root._seedWallet = function(opts, cb) {
|
||||
opts = opts || {};
|
||||
if (opts.bwsurl)
|
||||
bwcService.setBaseUrl(opts.bwsurl);
|
||||
|
||||
var walletClient = bwcService.getClient();
|
||||
var walletClient = bwcService.getClient(null, opts);
|
||||
var network = opts.networkName || 'livenet';
|
||||
|
||||
|
||||
|
@ -471,10 +467,8 @@ angular.module('copayApp.services')
|
|||
};
|
||||
|
||||
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);
|
||||
try {
|
||||
|
@ -573,7 +567,6 @@ angular.module('copayApp.services')
|
|||
|
||||
configService.get(function(err) {
|
||||
bwcService.setBaseUrl(defaults.bws.url);
|
||||
bwcService.setTransports(['polling']);
|
||||
root._createNewProfile(opts, function(err, p) {
|
||||
if (err) return cb(err);
|
||||
|
||||
|
|
|
@ -173,6 +173,14 @@ angular.module('copayApp.services')
|
|||
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) {
|
||||
storage.set('CleanAndScanAddresses', walletId, cb);
|
||||
};
|
||||
|
|
|
@ -93,13 +93,11 @@ mocks.init = function(fixtures, controllerName, opts, done) {
|
|||
|
||||
$delegate.getClient = function(walletData) {
|
||||
|
||||
var bwc = new $delegate.Client({
|
||||
baseUrl: config.baseUrl,
|
||||
verbose: config.verbose,
|
||||
transports: config.transports
|
||||
});
|
||||
var bwc = new $delegate.Client();
|
||||
if (walletData)
|
||||
bwc.import(walletData);
|
||||
bwc.import(walletData, {
|
||||
baseUrl: config.baseUrl
|
||||
});
|
||||
|
||||
function createHash(method, url, args) {
|
||||
var headers = JSON.stringify(bwc._getHeaders(method, url, args));
|
||||
|
|
Loading…
Reference in New Issue