2014-03-25 07:35:04 -07:00
|
|
|
'use strict';
|
|
|
|
|
2014-06-03 13:42:36 -07:00
|
|
|
angular.module('copayApp.controllers').controller('HeaderController',
|
2014-07-08 11:26:20 -07:00
|
|
|
function($scope, $rootScope, $location, notification, $http, $sce, controllerUtils, backupService) {
|
2014-06-24 08:36:32 -07:00
|
|
|
$scope.menu = [{
|
2014-04-20 16:21:54 -07:00
|
|
|
'title': 'Addresses',
|
|
|
|
'icon': 'fi-address-book',
|
|
|
|
'link': '#/addresses'
|
2014-03-26 05:18:42 -07:00
|
|
|
}, {
|
|
|
|
'title': 'Transactions',
|
2014-06-23 06:34:40 -07:00
|
|
|
'icon': 'fi-clipboard-pencil',
|
2014-03-26 05:18:42 -07:00
|
|
|
'link': '#/transactions'
|
|
|
|
}, {
|
|
|
|
'title': 'Send',
|
2014-04-15 08:33:00 -07:00
|
|
|
'icon': 'fi-arrow-right',
|
2014-03-26 05:18:42 -07:00
|
|
|
'link': '#/send'
|
|
|
|
}, {
|
2014-07-08 06:48:56 -07:00
|
|
|
'title': 'More...',
|
|
|
|
'icon': 'fi-download',
|
2014-03-26 05:18:42 -07:00
|
|
|
'link': '#/backup'
|
2014-04-15 10:02:45 -07:00
|
|
|
}];
|
2014-03-25 07:35:04 -07:00
|
|
|
|
2014-06-23 15:09:26 -07:00
|
|
|
$scope.getNumber = function(num) {
|
|
|
|
return new Array(num);
|
|
|
|
}
|
|
|
|
|
2014-06-24 08:36:32 -07:00
|
|
|
$http.get('https://api.github.com/repos/bitpay/copay/tags').success(function(data) {
|
|
|
|
var toInt = function(s) {
|
|
|
|
return parseInt(s);
|
|
|
|
};
|
2014-06-02 12:52:33 -07:00
|
|
|
var latestVersion = data[0].name.replace('v', '').split('.').map(toInt);
|
|
|
|
var currentVersion = copay.version.split('.').map(toInt);
|
2014-06-30 07:53:20 -07:00
|
|
|
var title = 'Copay ' + data[0].name + ' available.';
|
2014-06-27 11:32:52 -07:00
|
|
|
var content;
|
2014-06-24 08:36:32 -07:00
|
|
|
if (currentVersion[0] < latestVersion[0]) {
|
2014-06-27 11:32:52 -07:00
|
|
|
content = 'It\'s important that you update your wallet at https://copay.io';
|
|
|
|
notification.version(title, content, true);
|
2014-06-02 12:52:33 -07:00
|
|
|
} else if (currentVersion[0] == latestVersion[0] && currentVersion[1] < latestVersion[1]) {
|
2014-06-27 11:32:52 -07:00
|
|
|
var content = 'Please update your wallet at https://copay.io';
|
|
|
|
notification.version(title, content, false);
|
2014-06-24 08:36:32 -07:00
|
|
|
}
|
2014-06-02 12:52:33 -07:00
|
|
|
});
|
|
|
|
|
2014-06-27 11:07:07 -07:00
|
|
|
|
2014-06-04 14:10:47 -07:00
|
|
|
// Init socket handlers (with no wallet yet)
|
|
|
|
controllerUtils.setSocketHandlers();
|
|
|
|
|
2014-03-26 05:18:42 -07:00
|
|
|
$scope.isActive = function(item) {
|
2014-06-24 08:36:32 -07:00
|
|
|
if (item.link && item.link.replace('#', '') == $location.path()) {
|
2014-03-26 05:18:42 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2014-06-24 08:36:32 -07:00
|
|
|
|
2014-03-25 07:35:04 -07:00
|
|
|
$scope.signout = function() {
|
2014-05-15 13:04:26 -07:00
|
|
|
logout();
|
2014-04-30 15:50:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.refresh = function() {
|
2014-05-06 12:21:56 -07:00
|
|
|
var w = $rootScope.wallet;
|
2014-05-06 13:36:16 -07:00
|
|
|
w.connectToAll();
|
2014-06-24 08:36:32 -07:00
|
|
|
if ($rootScope.addrInfos.length > 0) {
|
2014-05-21 14:53:17 -07:00
|
|
|
controllerUtils.updateBalance(function() {
|
|
|
|
$rootScope.$digest();
|
|
|
|
});
|
|
|
|
}
|
2014-03-25 07:35:04 -07:00
|
|
|
};
|
2014-04-09 07:05:25 -07:00
|
|
|
|
2014-04-20 15:39:16 -07:00
|
|
|
$rootScope.isCollapsed = true;
|
2014-05-15 13:04:26 -07:00
|
|
|
|
2014-05-29 20:00:40 -07:00
|
|
|
$scope.toggleCollapse = function() {
|
|
|
|
$rootScope.isCollapsed = !$rootScope.isCollapsed;
|
|
|
|
};
|
|
|
|
|
2014-05-15 13:04:26 -07:00
|
|
|
function logout() {
|
|
|
|
var w = $rootScope.wallet;
|
|
|
|
if (w) {
|
|
|
|
w.disconnect();
|
|
|
|
controllerUtils.logout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ensures a graceful disconnect
|
|
|
|
window.onbeforeunload = logout;
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function() {
|
|
|
|
window.onbeforeunload = undefined;
|
|
|
|
});
|
2014-06-25 13:14:12 -07:00
|
|
|
|
2014-07-07 14:35:44 -07:00
|
|
|
$scope.backup = function() {
|
2014-06-25 13:14:12 -07:00
|
|
|
var w = $rootScope.wallet;
|
2014-07-07 14:35:44 -07:00
|
|
|
w.setBackupReady();
|
2014-07-08 12:47:00 -07:00
|
|
|
backupService.download(w);
|
2014-06-25 13:14:12 -07:00
|
|
|
};
|
|
|
|
|
2014-07-10 13:45:16 -07:00
|
|
|
$scope.dowloadBackup = function() {
|
|
|
|
var w = $rootScope.wallet;
|
|
|
|
backupService.download(w);
|
|
|
|
}
|
|
|
|
|
2014-07-08 11:26:20 -07:00
|
|
|
$scope.getVideoURL = function(copayer) {
|
|
|
|
if (config.disableVideo) return;
|
|
|
|
|
|
|
|
var vi = $rootScope.videoInfo[copayer]
|
|
|
|
if (!vi) return;
|
|
|
|
|
|
|
|
if ($rootScope.wallet.getOnlinePeerIDs().indexOf(copayer) === -1) {
|
|
|
|
// peer disconnected, remove his video
|
|
|
|
delete $rootScope.videoInfo[copayer]
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var encoded = vi.url;
|
|
|
|
var url = decodeURI(encoded);
|
|
|
|
var trusted = $sce.trustAsResourceUrl(url);
|
|
|
|
return trusted;
|
|
|
|
};
|
|
|
|
|
2014-03-25 07:35:04 -07:00
|
|
|
});
|