Merge pull request #228 from JDonadio/ref/delete-wallet

Shows delete wallet popup - Copayers view
This commit is contained in:
Matias Alejo Garcia 2016-08-25 14:52:01 -03:00 committed by GitHub
commit 05df98df28
2 changed files with 84 additions and 115 deletions

View file

@ -1,7 +1,5 @@
<ion-view ng-controller="copayersController"> <ion-view ng-controller="copayersController">
<ion-nav-bar class="bar-stable"> <ion-nav-bar class="bar-stable">
<ion-nav-title>{{wallet.name}}</ion-nav-title> <ion-nav-title>{{wallet.name}}</ion-nav-title>
<ion-nav-buttons side="primary"> <ion-nav-buttons side="primary">
@ -11,17 +9,13 @@
</ion-nav-buttons> </ion-nav-buttons>
</ion-nav-bar> </ion-nav-bar>
<ion-nav-buttons side="primary"> <ion-nav-buttons side="primary">
<button class="button" href ui-sref="tabs.home"> <button class="button" href ui-sref="tabs.home">
<i class="ion-arrow-left-c"></i> Back <i class="ion-arrow-left-c"></i> Back
</button> </button>
</ion-nav-buttons> </ion-nav-buttons>
<ion-content delegate-handle="my-handle" overflow-scroll="true"> <ion-content delegate-handle="my-handle" overflow-scroll="true">
<div ng-show="!wallet.notAuthorized"> <div ng-show="!wallet.notAuthorized">
<h1 class="text-center" translate>Share this invitation with your copayers</h1> <h1 class="text-center" translate>Share this invitation with your copayers</h1>
@ -30,7 +24,7 @@
<qrcode size="220" error-correction-level="L" data="{{secret}}"></qrcode> <qrcode size="220" error-correction-level="L" data="{{secret}}"></qrcode>
<div ng-show="!secret" style="position:relative; top:-226px; height:0px"> <div ng-show="!secret" style="position:relative; top:-226px; height:0px">
<div style="height:220px; width:220px; margin:auto; background: white"> <div style="height:220px; width:220px; margin:auto; background: white">
<ion-spinner class="spinner-stable" icon="lines"></ion-spinner> <ion-spinner class="spinner-dark" icon="lines"></ion-spinner>
</div> </div>
</div> </div>
<div class="secret" ng-show="!isCordova"> <div class="secret" ng-show="!isCordova">
@ -74,12 +68,11 @@
</div> </div>
<div class="text-center"> <div class="text-center">
<button class="tiny round outline dark-gray warning" ng-click="deleteWallet()"> <button class="tiny round outline dark-gray warning" ng-click="showDeletePopup()">
<i class="fi-trash"></i> <span translate>Cancel and delete the wallet</span> <i class="fi-trash"></i> <span translate>Cancel and delete the wallet</span>
</button> </button>
</div> </div>
</div> </div>
</div> </div>
</ion-content> </ion-content>
</ion-view> </ion-view>

View file

@ -1,63 +1,55 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('copayersController', angular.module('copayApp.controllers').controller('copayersController',
function($scope, $rootScope, $timeout, $log, $ionicModal, profileService, platformInfo, gettext, gettextCatalog, $stateParams, $state) { function($scope, $log, $ionicPopup, profileService, platformInfo, gettextCatalog, $stateParams, ongoingProcess, $state) {
var self = this; if (!$stateParams.walletId) {
$scope.isCordova = platformInfo.isCordova; $log.debug('No wallet provided...back to home');
var isWP = platformInfo.isWP; return $state.transitionTo('tabs.home');
var isAndroid = platformInfo.isAndroid;
var delete_msg = gettextCatalog.getString('Are you sure you want to delete this wallet?');
var accept_msg = gettextCatalog.getString('Accept');
var cancel_msg = gettextCatalog.getString('Cancel');
var confirm_msg = gettextCatalog.getString('Confirm');
var _modalDeleteWallet = function() {
$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();
});
};
var doDeleteWallet = function() {
var wallet = profileService.getWallet($stateParams.walletId);
var walletName = wallet.credentials.walletName;
profileService.deleteWalletClient(wallet, function(err) {
if (err) {
self.error = err.message || err;
$timeout(function() {
$scope.$digest();
});
} else {
$state.go('tabs.home');
} }
});
};
$scope.deleteWallet = function() { var wallet = profileService.getWallet($stateParams.walletId);
if ($scope.isCordova) { var secret;
navigator.notification.confirm( try {
delete_msg, secret = wallet.status.wallet.secret;
function(buttonIndex) { } catch (e) {};
if (buttonIndex == 1) {
doDeleteWallet(); $scope.wallet = wallet;
$scope.secret = secret;
$scope.isCordova = platformInfo.isCordova;
$scope.showDeletePopup = function() {
var popup = $ionicPopup.show({
template: '<span>' + gettextCatalog.getString('Are you sure you want to delete this wallet?') + '</span>',
title: gettextCatalog.getString('Confirm'),
buttons: [
{
text: gettextCatalog.getString('Cancel'),
onTap: function(e) {
popup.close();
} }
}, },
confirm_msg, [accept_msg, cancel_msg] {
); text: gettextCatalog.getString('Accept'),
} else { type: 'button-positive',
_modalDeleteWallet(); onTap: function(e) {
deleteWallet();
popup.close();
} }
}
]
});
};
function deleteWallet() {
ongoingProcess.set('deletingWallet', true);
profileService.deleteWalletClient(wallet, function(err) {
ongoingProcess.set('deletingWallet', false);
if (err) {
$scope.error = err.message || err;
} else {
$state.transitionTo('tabs.home');
}
});
}; };
$scope.copySecret = function() { $scope.copySecret = function() {
@ -75,20 +67,4 @@ angular.module('copayApp.controllers').controller('copayersController',
window.plugins.socialsharing.share(message, gettextCatalog.getString('Invitation to share a Copay Wallet'), null, null); window.plugins.socialsharing.share(message, gettextCatalog.getString('Invitation to share a Copay Wallet'), null, null);
} }
}; };
if (!$stateParams.walletId) {
$log.debug('No wallet provided...back to home');
return $state.transitionTo('tabs.home')
}
var wallet = profileService.getWallet($stateParams.walletId);
var secret;
try {
secret = wallet.status.wallet.secret;
} catch (e) {};
$scope.wallet = wallet;
$scope.secret = secret;
}); });