Merge pull request #206 from JDonadio/bug/delete-wallet

Fix delete wallet - wallet alias
This commit is contained in:
Matias Alejo Garcia 2016-08-19 13:06:28 -03:00 committed by GitHub
commit 5b14c8aca3
2 changed files with 30 additions and 46 deletions

View File

@ -10,9 +10,9 @@
<ion-content class="has-header" ng-controller="preferencesDeleteWalletController" cache-view="false"> <ion-content class="has-header" ng-controller="preferencesDeleteWalletController" cache-view="false">
<div translate>Warning!</div> <div translate>Warning!</div>
<div translate>Permanently delete this wallet. THIS ACTION CANNOT BE REVERSED</div> <div translate>Permanently delete this wallet. THIS ACTION CANNOT BE REVERSED</div>
<div class="right" ng-style="{'color':index.backgroundColor}" ng-show="!isDeletingWallet"> <div class="right" ng-style="{'color':backgroundColor}" ng-show="!isDeletingWallet">
{{index.walletName}}<span ng-show="index.alias">({{index.alias}})</span> <span ng-show="alias">{{alias}}</span>{{walletName}}
</div> </div>
<button class="button button-block button-stable" ng-click="deleteWallet()"translate>Delete wallet</button> <button class="button button-block button-stable" ng-click="showDeletePopup()"translate>Delete wallet</button>
</ion-content> </ion-content>
</ion-view> </ion-view>

View File

@ -1,39 +1,39 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('preferencesDeleteWalletController', angular.module('copayApp.controllers').controller('preferencesDeleteWalletController',
function($scope, $rootScope, $filter, $timeout, $log, $ionicModal, storageService, notification, profileService, platformInfo, go, gettext, gettextCatalog, applicationService, ongoingProcess) { function($scope, $ionicPopup, $stateParams, lodash, notification, profileService, go, gettextCatalog, ongoingProcess) {
var isCordova = platformInfo.isCordova; var wallet = profileService.getWallet($stateParams.walletId);
$scope.isCordova = isCordova; $scope.alias = lodash.isEqual(wallet.name, wallet.credentials.walletName) ? null : wallet.name + ' ';
$scope.walletName = '[' + wallet.credentials.walletName + ']';
$scope.error = null; $scope.error = null;
var walletName = $scope.alias || $scope.walletName;
var delete_msg = gettextCatalog.getString('Are you sure you want to delete this wallet?'); $scope.showDeletePopup = function() {
var accept_msg = gettextCatalog.getString('Accept'); var popup = $ionicPopup.show({
var cancel_msg = gettextCatalog.getString('Cancel'); template: '<span>' + gettextCatalog.getString('Are you sure you want to delete this wallet?') + '</span>',
var confirm_msg = gettextCatalog.getString('Confirm'); title: gettextCatalog.getString('Confirm'),
buttons: [
var _modalDeleteWallet = function() { {
$scope.title = delete_msg; text: gettextCatalog.getString('Cancel'),
$scope.accept_msg = accept_msg; onTap: function(e) {
$scope.cancel_msg = cancel_msg; popup.close();
$scope.confirm_msg = confirm_msg; }
$scope.okAction = doDeleteWallet; },
$scope.loading = false; {
text: gettextCatalog.getString('Accept'),
$ionicModal.fromTemplateUrl('views/modals/confirmation.html', { type: 'button-positive',
scope: $scope onTap: function(e) {
}).then(function(modal) { deleteWallet();
$scope.confirmationModal = modal; popup.close();
$scope.confirmationModal.show(); }
}
]
}); });
}; };
var doDeleteWallet = function() { function deleteWallet() {
ongoingProcess.set('deletingWallet', true); ongoingProcess.set('deletingWallet', true);
var fc = profileService.focusedClient; profileService.deleteWalletClient(wallet, function(err) {
var name = fc.credentials.walletName;
var walletName = (fc.alias || '') + ' [' + name + ']';
profileService.deleteWalletClient(fc, function(err) {
ongoingProcess.set('deletingWallet', false); ongoingProcess.set('deletingWallet', false);
if (err) { if (err) {
$scope.error = err.message || err; $scope.error = err.message || err;
@ -45,20 +45,4 @@ angular.module('copayApp.controllers').controller('preferencesDeleteWalletContro
} }
}); });
}; };
$scope.deleteWallet = function() {
if (isCordova) {
navigator.notification.confirm(
delete_msg,
function(buttonIndex) {
if (buttonIndex == 1) {
doDeleteWallet();
}
},
confirm_msg, [accept_msg, cancel_msg]
);
} else {
_modalDeleteWallet();
}
};
}); });