set bws url for each wallet

This commit is contained in:
Javier 2015-10-19 11:19:28 -03:00
commit 24609c6b15
6 changed files with 68 additions and 77 deletions

View file

@ -118,7 +118,6 @@ angular.module('copayApp.controllers').controller('createController',
configService.set(opts_, function(err) { configService.set(opts_, function(err) {
if (err) console.log(err); if (err) console.log(err);
$scope.$emit('Local/BWSUpdated'); $scope.$emit('Local/BWSUpdated');
applicationService.restart();
go.walletHome(); go.walletHome();
}); });

View file

@ -31,7 +31,6 @@ angular.module('copayApp.controllers').controller('importController',
configService.set(opts, function(err) { configService.set(opts, function(err) {
if (err) return cb(err); if (err) return cb(err);
$scope.$emit('Local/BWSUpdated'); $scope.$emit('Local/BWSUpdated');
applicationService.restart();
return cb(null); return cb(null);
}); });
} }

View file

@ -1005,11 +1005,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}, cb); }, cb);
}); });
$rootScope.$on('Local/BWSUpdated', function(event) {
profileService.applyConfig();
storageService.setCleanAndScanAddresses(function() {});
});
$rootScope.$on('Local/WalletCompleted', function(event) { $rootScope.$on('Local/WalletCompleted', function(event) {
self.setFocusedWallet(); self.setFocusedWallet();
go.walletHome(); go.walletHome();

View file

@ -84,7 +84,6 @@ angular.module('copayApp.controllers').controller('joinController',
configService.set(opts_, function(err) { configService.set(opts_, function(err) {
if (err) console.log(err); if (err) console.log(err);
$scope.$emit('Local/BWSUpdated'); $scope.$emit('Local/BWSUpdated');
applicationService.restart();
}); });
if (fc.isComplete() && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) { if (fc.isComplete() && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) {

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('preferencesBwsUrlController', angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
function($scope, $log, configService, go, applicationService, profileService) { function($scope, $log, configService, go, applicationService, profileService, storageService) {
this.error = null; this.error = null;
this.success = null; this.success = null;
@ -42,8 +42,9 @@ angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
configService.set(opts, function(err) { configService.set(opts, function(err) {
if (err) console.log(err); if (err) console.log(err);
$scope.$emit('Local/BWSUpdated'); storageService.setCleanAndScanAddresses(function() {
applicationService.restart(); applicationService.restart();
}); });
});
}; };
}); });

View file

@ -48,26 +48,28 @@ angular.module('copayApp.services')
}); });
}; };
root.setWalletClients = function() { root.setWalletClient = function(credentials) {
lodash.each(root.profile.credentials, function(credentials) {
if (root.walletClients[credentials.walletId] && if (root.walletClients[credentials.walletId] &&
root.walletClients[credentials.walletId].started) { root.walletClients[credentials.walletId].started) {
return; return;
} }
var config = configService.getSync();
var defaults = configService.getDefaults();
bwcService.setBaseUrl(config.bws[credentials.walletId] || defaults.bws.url);
bwcService.setTransports(['polling']);
var client = bwcService.getClient(JSON.stringify(credentials)); var client = bwcService.getClient(JSON.stringify(credentials));
root.walletClients[credentials.walletId] = client; root.walletClients[credentials.walletId] = client;
client.removeAllListeners(); client.removeAllListeners();
client.on('reconnect', function() { client.on('reconnect', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) { if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$log.debug('### Online'); $log.debug('### Online');
} }
}); });
client.on('reconnecting', function() { client.on('reconnecting', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) { if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$log.debug('### Offline'); $log.debug('### Offline');
@ -104,25 +106,22 @@ angular.module('copayApp.services')
return; return;
} }
}); });
}
root.setWalletClients = function(walletId) {
var credentials = root.profile.credentials;
lodash.each(credentials, function(credentials) {
root.setWalletClient(credentials);
}); });
$rootScope.$emit('Local/WalletListUpdated'); $rootScope.$emit('Local/WalletListUpdated');
}; };
root.applyConfig = function() {
var config = configService.getSync();
$log.debug('Applying preferences');
bwcService.setBaseUrl(config.bws.url);
bwcService.setTransports(['polling']);
};
root.bindProfile = function(profile, cb) { root.bindProfile = function(profile, cb) {
root.profile = profile; root.profile = profile;
configService.get(function(err) { configService.get(function(err) {
$log.debug('Preferences read'); $log.debug('Preferences read');
if (err) return cb(err); if (err) return cb(err);
root.applyConfig();
root.setWalletClients(); root.setWalletClients();
storageService.getFocusedWalletId(function(err, focusedWalletId) { storageService.getFocusedWalletId(function(err, focusedWalletId) {
if (err) return cb(err); if (err) return cb(err);
@ -415,7 +414,6 @@ angular.module('copayApp.services')
root.create = function(opts, cb) { root.create = function(opts, cb) {
$log.info('Creating profile'); $log.info('Creating profile');
configService.get(function(err) { configService.get(function(err) {
root.applyConfig();
root._createNewProfile(opts, function(err, p) { root._createNewProfile(opts, function(err, p) {
if (err) return cb(err); if (err) return cb(err);