2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
angular.module('copayApp.controllers').controller('preferencesDeleteWalletController',
|
2016-06-13 15:25:40 -03:00
|
|
|
function($scope, $rootScope, $filter, $timeout, $modal, $log, $ionicModal, storageService, notification, profileService, platformInfo, go, gettext, gettextCatalog, applicationService, ongoingProcess) {
|
2016-05-31 19:02:00 -03:00
|
|
|
var isCordova = platformInfo.isCordova;
|
2015-03-06 12:00:10 -03:00
|
|
|
this.isCordova = isCordova;
|
|
|
|
|
this.error = null;
|
|
|
|
|
|
2015-07-29 20:12:37 +09:00
|
|
|
var delete_msg = gettextCatalog.getString('Are you sure you want to delete this wallet?');
|
2015-07-29 12:37:51 -03:00
|
|
|
var accept_msg = gettextCatalog.getString('Accept');
|
2015-07-29 20:12:37 +09:00
|
|
|
var cancel_msg = gettextCatalog.getString('Cancel');
|
|
|
|
|
var confirm_msg = gettextCatalog.getString('Confirm');
|
|
|
|
|
|
2015-03-06 12:00:10 -03:00
|
|
|
var _modalDeleteWallet = function() {
|
2016-06-10 15:16:02 -03:00
|
|
|
$scope.title = delete_msg;
|
|
|
|
|
$scope.accept_msg = accept_msg;
|
|
|
|
|
$scope.cancel_msg = cancel_msg;
|
|
|
|
|
$scope.confirm_msg = confirm_msg;
|
|
|
|
|
$scope.okAction = doDeleteWallet;
|
|
|
|
|
$scope.loading = false;
|
|
|
|
|
|
|
|
|
|
$ionicModal.fromTemplateUrl('views/modals/confirmation.html', {
|
|
|
|
|
scope: $scope,
|
|
|
|
|
animation: 'slide-in-up'
|
|
|
|
|
}).then(function(modal) {
|
|
|
|
|
$scope.confirmationModal = modal;
|
|
|
|
|
$scope.confirmationModal.show();
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-06 12:21:15 -03:00
|
|
|
var doDeleteWallet = function() {
|
2016-06-13 15:25:40 -03:00
|
|
|
ongoingProcess.set('deletingWallet', true);
|
2015-04-30 13:03:30 -03:00
|
|
|
var fc = profileService.focusedClient;
|
2015-05-14 10:39:22 -03:00
|
|
|
var name = fc.credentials.walletName;
|
2015-10-13 16:11:07 -03:00
|
|
|
var walletName = (fc.alias || '') + ' [' + name + ']';
|
2015-04-30 13:03:30 -03:00
|
|
|
var self = this;
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2016-06-06 12:21:15 -03:00
|
|
|
profileService.deleteWalletClient(fc, function(err) {
|
2016-06-13 15:25:40 -03:00
|
|
|
ongoingProcess.set('deletingWallet', false);
|
2015-04-30 13:03:30 -03:00
|
|
|
if (err) {
|
|
|
|
|
self.error = err.message || err;
|
|
|
|
|
} else {
|
2015-11-06 16:54:25 -03:00
|
|
|
notification.success(gettextCatalog.getString('Success'), gettextCatalog.getString('The wallet "{{walletName}}" was deleted', {
|
|
|
|
|
walletName: walletName
|
|
|
|
|
}));
|
2016-04-11 10:50:50 -03:00
|
|
|
applicationService.restart();
|
2015-04-30 13:03:30 -03:00
|
|
|
}
|
|
|
|
|
});
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
this.deleteWallet = function() {
|
|
|
|
|
if (isCordova) {
|
|
|
|
|
navigator.notification.confirm(
|
2015-07-29 20:12:37 +09:00
|
|
|
delete_msg,
|
2015-03-06 12:00:10 -03:00
|
|
|
function(buttonIndex) {
|
2015-07-29 12:37:51 -03:00
|
|
|
if (buttonIndex == 1) {
|
2016-06-06 12:21:15 -03:00
|
|
|
doDeleteWallet();
|
2015-03-06 12:00:10 -03:00
|
|
|
}
|
|
|
|
|
},
|
2015-07-29 12:37:51 -03:00
|
|
|
confirm_msg, [accept_msg, cancel_msg]
|
2015-03-06 12:00:10 -03:00
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
_modalDeleteWallet();
|
|
|
|
|
}
|
|
|
|
|
};
|
2015-07-29 12:37:51 -03:00
|
|
|
});
|