2014-10-11 13:26:10 -07:00
|
|
|
'use strict';
|
2014-12-02 11:53:24 -08:00
|
|
|
angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, $filter, $timeout, backupService, identityService) {
|
2014-11-12 19:07:33 -08:00
|
|
|
$scope.username = $rootScope.iden.getName();
|
2014-10-21 11:11:04 -07:00
|
|
|
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
|
2014-10-16 06:18:37 -07:00
|
|
|
|
2014-11-11 11:01:33 -08:00
|
|
|
$rootScope.title = 'Profile';
|
2014-12-01 07:13:11 -08:00
|
|
|
$scope.hideAdv = true;
|
2014-10-27 12:13:06 -07:00
|
|
|
|
2014-11-11 11:53:57 -08:00
|
|
|
$scope.downloadProfileBackup = function() {
|
2014-10-16 06:18:37 -07:00
|
|
|
backupService.profileDownload($rootScope.iden);
|
|
|
|
};
|
2014-10-21 11:11:04 -07:00
|
|
|
|
2014-11-11 11:53:57 -08:00
|
|
|
$scope.viewProfileBackup = function() {
|
|
|
|
$scope.backupProfilePlainText = backupService.profileEncrypted($rootScope.iden);
|
|
|
|
$scope.hideViewProfileBackup = true;
|
2014-10-21 11:11:04 -07:00
|
|
|
};
|
2014-11-26 07:08:26 -08:00
|
|
|
|
2014-11-10 11:41:07 -08:00
|
|
|
$scope.deleteWallet = function(w) {
|
|
|
|
if (!w) return;
|
2014-11-30 18:08:16 -08:00
|
|
|
identityService.deleteWallet(w, function(err) {
|
2014-11-10 11:41:07 -08:00
|
|
|
$scope.loading = false;
|
2014-11-30 18:08:16 -08:00
|
|
|
if (err) {
|
2014-12-01 10:33:16 -08:00
|
|
|
copay.logger.warn(err);
|
2014-11-30 18:08:16 -08:00
|
|
|
}
|
2014-12-01 10:33:16 -08:00
|
|
|
$scope.setWallets();
|
2014-11-10 11:41:07 -08:00
|
|
|
});
|
|
|
|
};
|
2014-11-11 11:53:57 -08:00
|
|
|
|
2014-12-02 11:53:24 -08:00
|
|
|
|
2014-12-01 12:21:39 -08:00
|
|
|
$scope.init = function() {
|
|
|
|
if ($rootScope.quotaPerItem) {
|
2014-11-26 07:08:26 -08:00
|
|
|
$scope.perItem = $filter('noFractionNumber')($rootScope.quotaPerItem / 1000, 1);
|
|
|
|
$scope.nrWallets = parseInt($rootScope.quotaItems) - 1;
|
2014-12-01 12:21:39 -08:00
|
|
|
}
|
2014-12-02 11:53:24 -08:00
|
|
|
// no need to add event handlers here. Wallet deletion is handle by callback.
|
2014-12-01 12:21:39 -08:00
|
|
|
};
|
|
|
|
|
2014-11-29 23:03:23 -08:00
|
|
|
$scope.setWallets = function() {
|
|
|
|
if (!$rootScope.iden) return;
|
|
|
|
|
2014-12-01 12:21:39 -08:00
|
|
|
var wallets = $rootScope.iden.listWallets();
|
2014-11-26 07:08:26 -08:00
|
|
|
var max = $rootScope.quotaPerItem;
|
2014-12-01 12:21:39 -08:00
|
|
|
|
|
|
|
_.each(wallets, function(w) {
|
|
|
|
var bits = w.sizes().total;
|
2014-11-26 07:08:26 -08:00
|
|
|
w.kb = $filter('noFractionNumber')(bits / 1000, 1);
|
2014-12-01 12:21:39 -08:00
|
|
|
if (max) {
|
2014-11-26 07:08:26 -08:00
|
|
|
w.usage = $filter('noFractionNumber')(bits / max * 100, 0);
|
2014-12-01 12:21:39 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
$scope.wallets = wallets;
|
2014-12-02 11:53:24 -08:00
|
|
|
$timeout(function(){
|
|
|
|
$scope.$digest();
|
|
|
|
})
|
2014-12-01 12:21:39 -08:00
|
|
|
};
|
2014-11-29 23:03:23 -08:00
|
|
|
|
2014-11-11 11:53:57 -08:00
|
|
|
$scope.downloadWalletBackup = function(w) {
|
|
|
|
if (!w) return;
|
|
|
|
backupService.walletDownload(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.viewWalletBackup = function(w) {
|
|
|
|
var ModalInstanceCtrl = function($scope, $modalInstance) {
|
|
|
|
|
|
|
|
if (!w) return;
|
|
|
|
$scope.backupWalletPlainText = backupService.walletEncrypted(w);
|
|
|
|
$scope.hideViewWalletBackup = true;
|
|
|
|
$scope.cancel = function() {
|
|
|
|
$modalInstance.dismiss('cancel');
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
$modal.open({
|
|
|
|
templateUrl: 'views/modals/backup-text.html',
|
|
|
|
windowClass: 'tiny',
|
|
|
|
controller: ModalInstanceCtrl
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-11-26 07:08:26 -08:00
|
|
|
$scope.deleteProfile = function() {
|
|
|
|
identityService.deleteProfile(function(err, res) {
|
2014-12-01 09:44:36 -08:00
|
|
|
if (err) {
|
|
|
|
log.warn(err);
|
|
|
|
notification.error('Error', 'Could not delete profile');
|
|
|
|
return;
|
|
|
|
}
|
2014-11-26 07:08:26 -08:00
|
|
|
$location.path('/');
|
|
|
|
setTimeout(function() {
|
2014-12-01 09:44:36 -08:00
|
|
|
notification.error('Success', 'Profile successfully deleted');
|
|
|
|
}, 1);
|
|
|
|
});
|
2014-12-01 07:13:11 -08:00
|
|
|
};
|
2014-10-11 13:26:10 -07:00
|
|
|
});
|