2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('preferencesDeleteWalletController',
|
2017-01-21 19:37:39 -03:00
|
|
|
function($scope, $ionicHistory, gettextCatalog, lodash, profileService, $state, ongoingProcess, popupService) {
|
|
|
|
|
|
|
|
|
|
$scope.$on("$ionicView.beforeEnter", function(event, data) {
|
|
|
|
|
if (!data.stateParams || !data.stateParams.walletId) {
|
2017-01-23 10:51:39 -03:00
|
|
|
popupService.showAlert(null, gettextCatalog.getString('No wallet selected'), function() {
|
2017-01-21 19:37:39 -03:00
|
|
|
$ionicHistory.goBack();
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$scope.wallet = profileService.getWallet(data.stateParams.walletId);
|
2017-01-23 10:51:39 -03:00
|
|
|
if (!$scope.wallet) {
|
|
|
|
|
popupService.showAlert(null, gettextCatalog.getString('No wallet found'), function() {
|
|
|
|
|
$ionicHistory.goBack();
|
|
|
|
|
});
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-01-21 19:37:39 -03:00
|
|
|
$scope.alias = lodash.isEqual($scope.wallet.name, $scope.wallet.credentials.walletName) ? null : $scope.wallet.name + ' ';
|
|
|
|
|
$scope.walletName = $scope.wallet.credentials.walletName;
|
|
|
|
|
});
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2016-08-19 12:50:52 -03:00
|
|
|
$scope.showDeletePopup = function() {
|
2016-09-05 17:36:11 -03:00
|
|
|
var title = gettextCatalog.getString('Warning!');
|
|
|
|
|
var message = gettextCatalog.getString('Are you sure you want to delete this wallet?');
|
2016-09-12 13:58:36 -03:00
|
|
|
popupService.showConfirm(title, message, null, null, function(res) {
|
2016-09-05 17:36:11 -03:00
|
|
|
if (res) deleteWallet();
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-19 12:50:52 -03:00
|
|
|
function deleteWallet() {
|
2016-06-13 15:25:40 -03:00
|
|
|
ongoingProcess.set('deletingWallet', true);
|
2017-01-21 19:37:39 -03:00
|
|
|
profileService.deleteWalletClient($scope.wallet, function(err) {
|
2016-06-13 15:25:40 -03:00
|
|
|
ongoingProcess.set('deletingWallet', false);
|
2015-04-30 13:03:30 -03:00
|
|
|
if (err) {
|
2016-09-01 10:56:13 -03:00
|
|
|
popupService.showAlert(gettextCatalog.getString('Error'), err.message || err);
|
2015-04-30 13:03:30 -03:00
|
|
|
} else {
|
2017-01-21 19:37:39 -03:00
|
|
|
$ionicHistory.nextViewOptions({
|
|
|
|
|
disableAnimate: true,
|
|
|
|
|
historyRoot: true
|
|
|
|
|
});
|
2016-10-12 14:57:02 -03:00
|
|
|
$ionicHistory.clearHistory();
|
2017-01-21 19:37:39 -03:00
|
|
|
$state.go('tabs.settings').then(function() {
|
|
|
|
|
$state.transitionTo('tabs.home');
|
|
|
|
|
});
|
2015-04-30 13:03:30 -03:00
|
|
|
}
|
|
|
|
|
});
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
2015-07-29 12:37:51 -03:00
|
|
|
});
|