refactor baseurl in getClient

This commit is contained in:
Matias Alejo Garcia 2016-06-01 16:44:07 -03:00
commit 02861992e6
No known key found for this signature in database
GPG key ID: 02470DB551277AB3

View file

@ -62,7 +62,7 @@ angular.module('copayApp.services')
}); });
}; };
root.setBaseURL = function(walletId) { root._getBaseURL = function(walletId) {
var config = configService.getSync(); var config = configService.getSync();
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
@ -75,10 +75,12 @@ angular.module('copayApp.services')
return; return;
} }
root.setBaseURL(credentials.walletId);
$log.debug('Importing wallet:' + credentials.walletId); $log.debug('Importing wallet:' + credentials.walletId);
var client = bwcService.getClient(JSON.stringify(credentials)); var client = bwcService.getClient(JSON.stringify(credentials), {
baseurl: root._getBaseURL(credentials.walletId),
});
root.walletClients[credentials.walletId] = client; root.walletClients[credentials.walletId] = client;
if (client.incorrectDerivation) { if (client.incorrectDerivation) {
@ -327,8 +329,8 @@ angular.module('copayApp.services')
// check if exist // check if exist
if (lodash.find(root.profile.credentials, { if (lodash.find(root.profile.credentials, {
'walletId': walletData.walletId 'walletId': walletData.walletId
})) { })) {
return cb(gettext('Cannot join the same wallet more that once')); return cb(gettext('Cannot join the same wallet more that once'));
} }
} catch (ex) { } catch (ex) {
@ -495,10 +497,7 @@ angular.module('copayApp.services')
}; };
root.importExtendedPrivateKey = function(xPrivKey, opts, cb) { root.importExtendedPrivateKey = function(xPrivKey, opts, cb) {
if (opts.bwsurl) var walletClient = bwcService.getClient(null, opts);
bwcService.setBaseUrl(opts.bwsurl);
var walletClient = bwcService.getClient();
$log.debug('Importing Wallet xPrivKey'); $log.debug('Importing Wallet xPrivKey');
walletClient.importFromExtendedPrivateKey(xPrivKey, opts, function(err) { walletClient.importFromExtendedPrivateKey(xPrivKey, opts, function(err) {
@ -517,10 +516,7 @@ angular.module('copayApp.services')
}; };
root.importMnemonic = function(words, opts, cb) { root.importMnemonic = function(words, opts, cb) {
if (opts.bwsurl) var walletClient = bwcService.getClient(null, opts);
bwcService.setBaseUrl(opts.bwsurl);
var walletClient = bwcService.getClient();
$log.debug('Importing Wallet Mnemonic'); $log.debug('Importing Wallet Mnemonic');
@ -538,10 +534,7 @@ angular.module('copayApp.services')
}; };
root.importExtendedPublicKey = function(opts, cb) { root.importExtendedPublicKey = function(opts, cb) {
if (opts.bwsurl) var walletClient = bwcService.getClient(null, opts);
bwcService.setBaseUrl(opts.bwsurl);
var walletClient = bwcService.getClient();
$log.debug('Importing Wallet XPubKey'); $log.debug('Importing Wallet XPubKey');
walletClient.importFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, { walletClient.importFromExtendedPublicKey(opts.extendedPublicKey, opts.externalSource, opts.entropySource, {
@ -566,7 +559,6 @@ angular.module('copayApp.services')
var defaults = configService.getDefaults(); var defaults = configService.getDefaults();
configService.get(function(err) { configService.get(function(err) {
bwcService.setBaseUrl(defaults.bws.url);
root._createNewProfile(opts, function(err, p) { root._createNewProfile(opts, function(err, p) {
if (err) return cb(err); if (err) return cb(err);