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