set bws url for each wallet

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

View File

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

View File

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

View File

@ -840,9 +840,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.initGlidera = function(accessToken) {
self.glideraEnabled = configService.getSync().glidera.enabled;
// self.glideraTestnet = configService.getSync().glidera.testnet;
// var network = self.glideraTestnet ? 'testnet' : 'livenet';
// Disabled for testnet
// self.glideraTestnet = configService.getSync().glidera.testnet;
// var network = self.glideraTestnet ? 'testnet' : 'livenet';
// Disabled for testnet
self.glideraTestnet = false;
var network = 'livenet';
@ -1005,11 +1005,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}, cb);
});
$rootScope.$on('Local/BWSUpdated', function(event) {
profileService.applyConfig();
storageService.setCleanAndScanAddresses(function() {});
});
$rootScope.$on('Local/WalletCompleted', function(event) {
self.setFocusedWallet();
go.walletHome();

View File

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

View File

@ -1,7 +1,7 @@
'use strict';
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.success = null;
@ -35,15 +35,16 @@ angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
this.bwsurl = bws;
}
var opts = {
bws: {}
};
opts.bws[walletId] = this.bwsurl;
var opts = {
bws: {}
};
opts.bws[walletId] = this.bwsurl;
configService.set(opts, function(err) {
if (err) console.log(err);
$scope.$emit('Local/BWSUpdated');
configService.set(opts, function(err) {
if (err) console.log(err);
storageService.setCleanAndScanAddresses(function() {
applicationService.restart();
});
});
};
});

View File

@ -48,81 +48,80 @@ angular.module('copayApp.services')
});
};
root.setWalletClients = function() {
lodash.each(root.profile.credentials, function(credentials) {
root.setWalletClient = function(credentials) {
if (root.walletClients[credentials.walletId] &&
root.walletClients[credentials.walletId].started) {
return;
}
if (root.walletClients[credentials.walletId] &&
root.walletClients[credentials.walletId].started) {
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));
root.walletClients[credentials.walletId] = client;
client.removeAllListeners();
client.on('reconnect', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$log.debug('### Online');
}
});
client.on('reconnecting', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$log.debug('### Offline');
}
});
client.on('notification', function(n) {
$log.debug('BWC Notification:', n);
notificationService.newBWCNotification(n,
client.credentials.walletId, client.credentials.walletName);
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$rootScope.$emit(n.type);
} else {
$rootScope.$apply();
}
});
client.on('walletCompleted', function() {
$log.debug('Wallet completed');
root.updateCredentialsFC(function() {
$rootScope.$emit('Local/WalletCompleted')
});
});
root.walletClients[credentials.walletId].started = true;
root.walletClients[credentials.walletId].doNotVerifyPayPro = isChromeApp;
client.initNotifications(function(err) {
if (err) {
$log.error('Could not init notifications err:', err);
return;
}
});
}
var client = bwcService.getClient(JSON.stringify(credentials));
root.walletClients[credentials.walletId] = client;
client.removeAllListeners();
client.on('reconnect', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$log.debug('### Online');
}
});
client.on('reconnecting', function() {
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$log.debug('### Offline');
}
});
client.on('notification', function(n) {
$log.debug('BWC Notification:', n);
notificationService.newBWCNotification(n,
client.credentials.walletId, client.credentials.walletName);
if (root.focusedClient.credentials.walletId == client.credentials.walletId) {
$rootScope.$emit(n.type);
} else {
$rootScope.$apply();
}
});
client.on('walletCompleted', function() {
$log.debug('Wallet completed');
root.updateCredentialsFC(function() {
$rootScope.$emit('Local/WalletCompleted')
});
});
root.walletClients[credentials.walletId].started = true;
root.walletClients[credentials.walletId].doNotVerifyPayPro = isChromeApp;
client.initNotifications(function(err) {
if (err) {
$log.error('Could not init notifications err:', err);
return;
}
});
root.setWalletClients = function(walletId) {
var credentials = root.profile.credentials;
lodash.each(credentials, function(credentials) {
root.setWalletClient(credentials);
});
$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.profile = profile;
configService.get(function(err) {
$log.debug('Preferences read');
if (err) return cb(err);
root.applyConfig();
root.setWalletClients();
storageService.getFocusedWalletId(function(err, focusedWalletId) {
if (err) return cb(err);
@ -327,7 +326,7 @@ angular.module('copayApp.services')
'walletId': walletId
});
if (w) {
return cb(gettext('Wallet already in Copay' + ": ") + w.walletName );
return cb(gettext('Wallet already in Copay' + ": ") + w.walletName);
}
root.profile.credentials.push(JSON.parse(walletClient.export()));
@ -369,7 +368,7 @@ angular.module('copayApp.services')
root._normalizeMnemonic = function(words) {
var isJA = words.indexOf('\u3000') > -1;
var isJA = words.indexOf('\u3000') > -1;
var wordList = words.split(/[\u3000\s]+/);
return wordList.join(isJA ? '\u3000' : ' ');
@ -415,7 +414,6 @@ angular.module('copayApp.services')
root.create = function(opts, cb) {
$log.info('Creating profile');
configService.get(function(err) {
root.applyConfig();
root._createNewProfile(opts, function(err, p) {
if (err) return cb(err);
@ -552,7 +550,7 @@ angular.module('copayApp.services')
$log.info('Requesting Ledger Chrome app to sign the transaction');
ledger.signTx(txp, 0, function(result) {
$log.debug('Ledger response',result);
$log.debug('Ledger response', result);
if (!result.success)
return cb(result.message || result.error);
@ -568,11 +566,11 @@ angular.module('copayApp.services')
var fc = root.focusedClient;
$log.info('Requesting Trezor to sign the transaction');
var xPubKeys = lodash.pluck(fc.credentials.publicKeyRing,'xPubKey');
var xPubKeys = lodash.pluck(fc.credentials.publicKeyRing, 'xPubKey');
trezor.signTx(xPubKeys, txp, 0, function(err, result) {
if (err) return cb(err);
$log.debug('Trezor response',result);
$log.debug('Trezor response', result);
txp.signatures = result.signatures;
return fc.signTxProposal(txp, cb);
});