Wallet/src/js/controllers/sidebar.js

64 lines
2 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.controllers').controller('sidebarController',
2016-05-20 11:58:47 -03:00
function($rootScope, $timeout, $ionicScrollDelegate, lodash, profileService, configService, go, platformInfo) {
2015-03-06 12:00:10 -03:00
var self = this;
2016-05-31 16:52:38 -03:00
self.isWindowsPhoneApp = platformInfo.isWP && platformInfo.isCordova;
2015-03-06 12:00:10 -03:00
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();
};
self.switchWallet = function(selectedWalletId, currentWalletId) {
var client = profileService.focusedClient;
if (selectedWalletId == currentWalletId && client.isComplete()) return;
2015-03-06 12:00:10 -03:00
self.walletSelection = false;
2015-11-18 16:37:15 -03:00
profileService.setAndStoreFocus(selectedWalletId, function() {});
$ionicScrollDelegate.scrollTop();
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;
2015-11-18 16:37:15 -03:00
2015-03-06 12:00:10 -03:00
var config = configService.getSync();
config.colorFor = config.colorFor || {};
2015-05-14 10:39:22 -03:00
config.aliasFor = config.aliasFor || {};
2015-11-18 16:37:15 -03:00
// Sanitize empty wallets (fixed in BWC 1.8.1, and auto fixed when wallets completes)
var credentials = lodash.filter(profileService.profile.credentials, 'walletName');
var ret = lodash.map(credentials, function(c) {
2015-03-06 12:00:10 -03:00
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-11-18 16:37:15 -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();
});