'use strict'; angular.module('copayApp.controllers').controller('preferencesDeleteWalletController', function($scope, $rootScope, $filter, $timeout, $modal, notification, profileService, isCordova, go) { this.isCordova = isCordova; this.error = null; var _modalDeleteWallet = function() { var ModalInstanceCtrl = function($scope, $modalInstance) { $scope.title = 'Are you sure you want to delete this wallet?'; $scope.loading = false; $scope.ok = function() { $scope.loading = true; $modalInstance.close('ok'); }; $scope.cancel = function() { $modalInstance.dismiss('cancel'); }; }; var modalInstance = $modal.open({ templateUrl: 'views/modals/confirmation.html', windowClass: 'full', controller: ModalInstanceCtrl }); modalInstance.result.then(function(ok) { if (ok) { _deleteWallet(); } }); }; var _deleteWallet = function() { $timeout(function() { var fc = profileService.focusedClient; var walletName = fc.credentials.walletName; profileService.deleteWalletFC({}, function(err) { if (err) { this.error = err.message || err; console.log(err); $timeout(function() { $scope.$digest(); }); } else { go.walletHome(); $timeout(function() { notification.success('Success', 'The wallet "' + walletName + '" was deleted'); }); } }); }, 100); }; this.deleteWallet = function() { if (isCordova) { navigator.notification.confirm( 'Are you sure you want to delete this wallet?', function(buttonIndex) { if (buttonIndex == 2) { _deleteWallet(); } }, 'Confirm', ['Cancel', 'OK'] ); } else { _modalDeleteWallet(); } }; });