2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('sidebarController',
|
|
|
|
|
function($rootScope, $timeout, lodash, profileService, configService, go) {
|
|
|
|
|
var self = this;
|
|
|
|
|
self.walletSelection = false;
|
|
|
|
|
|
|
|
|
|
// wallet list change
|
|
|
|
|
$rootScope.$on('Local/WalletListUpdated', function(event) {
|
|
|
|
|
self.walletSelection = false;
|
|
|
|
|
self.setWallets();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$rootScope.$on('Local/ColorUpdated', function(event) {
|
|
|
|
|
self.setWallets();
|
|
|
|
|
});
|
|
|
|
|
|
2015-05-14 10:39:22 -03:00
|
|
|
$rootScope.$on('Local/AliasUpdated', function(event) {
|
|
|
|
|
self.setWallets();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2015-03-06 12:00:10 -03:00
|
|
|
self.signout = function() {
|
|
|
|
|
profileService.signout();
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-12 15:00:51 -03:00
|
|
|
self.switchWallet = function(selectedWalletId, currentWalletId) {
|
|
|
|
|
if (selectedWalletId == currentWalletId) return;
|
2015-03-06 12:00:10 -03:00
|
|
|
self.walletSelection = false;
|
2015-06-12 15:00:51 -03:00
|
|
|
profileService.setAndStoreFocus(selectedWalletId, function() {
|
2015-04-28 20:13:28 -03:00
|
|
|
});
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.toggleWalletSelection = function() {
|
|
|
|
|
self.walletSelection = !self.walletSelection;
|
|
|
|
|
if (!self.walletSelection) return;
|
|
|
|
|
self.setWallets();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.setWallets = function() {
|
|
|
|
|
if (!profileService.profile) return;
|
|
|
|
|
var config = configService.getSync();
|
|
|
|
|
config.colorFor = config.colorFor || {};
|
2015-05-14 10:39:22 -03:00
|
|
|
config.aliasFor = config.aliasFor || {};
|
2015-03-06 12:00:10 -03:00
|
|
|
var ret = lodash.map(profileService.profile.credentials, function(c) {
|
|
|
|
|
return {
|
|
|
|
|
m: c.m,
|
|
|
|
|
n: c.n,
|
2015-05-14 10:39:22 -03:00
|
|
|
name: config.aliasFor[c.walletId] || c.walletName,
|
2015-03-06 12:00:10 -03:00
|
|
|
id: c.walletId,
|
2015-05-29 15:25:41 -03:00
|
|
|
color: config.colorFor[c.walletId] || '#4A90E2',
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
|
|
|
|
});
|
2015-05-14 10:39:22 -03:00
|
|
|
self.wallets = lodash.sortBy(ret, 'name');
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
self.setWallets();
|
|
|
|
|
|
|
|
|
|
});
|