Wallet/js/controllers/sidebar.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

2014-03-25 11:35:04 -03:00
'use strict';
2014-10-27 16:13:06 -03:00
angular.module('copayApp.controllers').controller('SidebarController', function($scope, $rootScope, $location, controllerUtils) {
2014-08-12 15:26:15 -04:00
$scope.menu = [{
2014-10-31 11:49:52 -03:00
'title': 'Home',
'icon': 'fi-home',
'link': 'homeWallet'
}, {
2014-08-12 15:26:15 -04:00
'title': 'Receive',
'icon': 'fi-download',
2014-08-12 15:26:15 -04:00
'link': 'receive'
}, {
'title': 'Send',
'icon': 'fi-arrow-right',
'link': 'send'
}, {
'title': 'History',
'icon': 'fi-clipboard-pencil',
'link': 'history'
}, {
'title': 'Settings',
'icon': 'fi-widget',
2014-08-21 11:08:20 -04:00
'link': 'more'
2014-08-12 15:26:15 -04:00
}];
$scope.refresh = function() {
var w = $rootScope.wallet;
2014-10-21 09:51:47 -03:00
if (!w) return;
2014-10-10 17:58:19 -03:00
if (w.isReady()) {
w.sendWalletReady();
if ($rootScope.addrInfos.length > 0) {
2014-10-16 16:02:32 -03:00
controllerUtils.clearBalanceCache(w);
controllerUtils.updateBalance(w, function() {
2014-10-10 17:58:19 -03:00
$rootScope.$digest();
});
}
2014-07-16 19:00:34 -03:00
}
2014-08-12 15:26:15 -04:00
};
2014-07-16 19:00:34 -03:00
2014-10-28 12:37:15 -03:00
$scope.signout = function() {
$scope.$emit('signout');
};
2014-08-12 15:26:15 -04:00
$scope.isActive = function(item) {
return item.link && item.link == $location.path().split('/')[1];
};
2014-07-08 15:26:20 -03:00
2014-08-12 15:26:15 -04:00
if ($rootScope.wallet) {
$rootScope.$watch('wallet.id', function() {
$scope.walletSelection = false;
$scope.getWallets();
});
2014-08-12 15:26:15 -04:00
}
$scope.switchWallet = function(wid) {
controllerUtils.setFocusedWallet(wid);
};
2014-10-20 10:29:43 -03:00
$scope.toggleWalletSelection = function() {
$scope.walletSelection = !$scope.walletSelection;
if (!$scope.walletSelection) return;
$scope.getWallets();
};
$scope.getWallets = function() {
if (!$rootScope.iden) return;
2014-10-20 10:29:43 -03:00
$scope.wallets = [];
var wids = _.pluck($rootScope.iden.listWallets(), 'id');
_.each(wids, function(wid) {
if (controllerUtils.isFocusedWallet(wid)) return;
var w = $rootScope.iden.getWalletById(wid);
2014-10-20 10:29:43 -03:00
$scope.wallets.push(w);
controllerUtils.updateBalance(w, function() {
$rootScope.$digest();
})
2014-10-20 10:29:43 -03:00
});
};
2014-08-12 15:26:15 -04:00
});