Add backup to list of wallets in "manage wallets". Support for safari.

This commit is contained in:
Gustavo Maximiliano Cortez 2014-11-11 16:53:57 -03:00
commit c5f810c069
6 changed files with 74 additions and 80 deletions

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('MoreController', angular.module('copayApp.controllers').controller('MoreController',
function($scope, $rootScope, $location, $filter, backupService, controllerUtils, notification, rateService) { function($scope, $rootScope, $location, $filter, controllerUtils, notification, rateService) {
controllerUtils.redirIfNotComplete(); controllerUtils.redirIfNotComplete();
var w = $rootScope.wallet; var w = $rootScope.wallet;
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; $scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
@ -78,25 +78,6 @@ angular.module('copayApp.controllers').controller('MoreController',
controllerUtils.updateBalance(); controllerUtils.updateBalance();
}; };
$scope.downloadBackup = function() {
backupService.walletDownload(w);
}
$scope.viewBackup = function() {
$scope.backupPlainText = backupService.walletEncrypted(w);
$scope.hideViewBackup = true;
};
$scope.deleteWallet = function() {
$scope.loading = true;
controllerUtils.deleteWallet($scope, $rootScope.wallet, function() {
$rootScope.wallet = null;
var lastFocused = $rootScope.iden.getLastFocusedWallet();
controllerUtils.bindProfile($scope, $rootScope.iden, lastFocused);
$scope.loading = false;
});
};
$scope.purge = function(deleteAll) { $scope.purge = function(deleteAll) {
var removed = w.purgeTxProposals(deleteAll); var removed = w.purgeTxProposals(deleteAll);
if (removed) { if (removed) {

View file

@ -1,19 +1,20 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, controllerUtils, backupService) { angular.module('copayApp.controllers').controller('ProfileController', function($scope, $rootScope, $location, $modal, controllerUtils, backupService) {
$scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0; $scope.isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
$rootScope.title = 'Profile'; $rootScope.title = 'Profile';
$scope.downloadBackup = function() { $scope.downloadProfileBackup = function() {
backupService.profileDownload($rootScope.iden); backupService.profileDownload($rootScope.iden);
}; };
$scope.viewBackup = function() { $scope.viewProfileBackup = function() {
$scope.backupPlainText = backupService.profileEncrypted($rootScope.iden); $scope.backupProfilePlainText = backupService.profileEncrypted($rootScope.iden);
$scope.hideViewBackup = true; $scope.hideViewProfileBackup = true;
}; };
$scope.getWallets = function() { $scope.getWallets = function() {
if (!$rootScope.iden) return;
$scope.wallets = []; $scope.wallets = [];
var wids = _.pluck($rootScope.iden.listWallets(), 'id'); var wids = _.pluck($rootScope.iden.listWallets(), 'id');
_.each(wids, function(wid) { _.each(wids, function(wid) {
@ -29,8 +30,37 @@ angular.module('copayApp.controllers').controller('ProfileController', function(
if (!w) return; if (!w) return;
$scope.loading = w.id; $scope.loading = w.id;
controllerUtils.deleteWallet($scope, w, function() { controllerUtils.deleteWallet($scope, w, function() {
if ($rootScope.wallet.id === w.id) {
$rootScope.wallet = null;
var lastFocused = $rootScope.iden.getLastFocusedWallet();
controllerUtils.bindProfile($scope, $rootScope.iden, lastFocused);
}
$scope.loading = false; $scope.loading = false;
$scope.getWallets(); $scope.getWallets();
}); });
}; };
$scope.downloadWalletBackup = function(w) {
if (!w) return;
backupService.walletDownload(w);
}
$scope.viewWalletBackup = function(w) {
var ModalInstanceCtrl = function($scope, $modalInstance) {
if (!w) return;
$scope.backupWalletPlainText = backupService.walletEncrypted(w);
$scope.hideViewWalletBackup = true;
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};
$modal.open({
templateUrl: 'views/modals/backup-text.html',
windowClass: 'tiny',
controller: ModalInstanceCtrl
});
};
}); });

View file

@ -66,6 +66,7 @@ angular.module('copayApp.controllers').controller('SidebarController', function(
}; };
$scope.getWallets = function() { $scope.getWallets = function() {
if (!$rootScope.iden) return;
$scope.wallets = []; $scope.wallets = [];
var wids = _.pluck($rootScope.iden.listWallets(), 'id'); var wids = _.pluck($rootScope.iden.listWallets(), 'id');
_.each(wids, function(wid) { _.each(wids, function(wid) {

View file

@ -0,0 +1,14 @@
<div class="text-center">
<h1>Copy backup in a safe place</h1>
<div class="show-for-large-up">
<textarea readonly rows="7">{{backupWalletPlainText}}</textarea>
<span translate class="size-12">Copy to clipboard</span>
<span class="btn-copy" clip-copy="backupWalletPlainText"> </span>
</div>
<div class="hide-for-large-up">
<textarea rows="12">{{backupWalletPlainText}}</textarea>
</div>
<div translate class="m10t size-12 text-gray text-right">Copy this text as it is in a safe place (notepad or email)</div>
</div>
<a class="close-reveal-modal" ng-click="cancel()">&#215;</a>

View file

@ -21,46 +21,6 @@
<div class="line-dashed-h m20b"></div> <div class="line-dashed-h m20b"></div>
<div class="row">
<div class="large-6 columns">
<div class="panel">
<h2><i class="fi-download m10r"></i> <span translate>Backup</span></h2>
<p translate class="text-gray">
It's important to backup your wallet so that you can recover it in case of disaster
</p>
<a translate class="button primary m0" ng-click="downloadBackup()"
ng-show="!isSafari">Download File</a>
<a translate class="button primary m0" ng-click="viewBackup()"
ng-show="isSafari && !hideViewBackup">View Backup</a>
<div ng-show="backupPlainText">
<div class="show-for-large-up">
<textarea readonly rows="5">{{backupPlainText}}</textarea>
<span translate class="size-12">Copy to clipboard</span> <span class="btn-copy" clip-copy="backupPlainText"> </span>
</div>
<div class="hide-for-large-up">
<textarea rows="10">{{backupPlainText}}</textarea>
</div>
<div translate class="m10t size-12 text-gray text-right">Copy this text as it is in a safe place (notepad or email)</div>
</div>
</div>
</div>
<div class="large-6 columns">
<div class="panel">
<h2><i class="fi-minus-circle m10r"></i> <span translate>Delete Wallet</span></h2>
<p translate class="text-gray">If all funds have been removed from your wallet and you do not wish to have the wallet data stored on your computer anymore, you can delete your wallet.</p>
<a class="button warning m0"
ng-really-message="{{'Are you sure you want to delete this wallet?'|translate}}"
ng-really-click="deleteWallet()"
ng-class="{'disabled':loading}">
<span ng-show="!loading">Delete</span>
<span ng-show="loading">Deleting...</span>
</a>
</div>
</div>
</div>
<div class="line-dashed-h m20b"></div>
<div class="m20b"> <div class="m20b">
<a class="size-12" ng-click="hideAdv=!hideAdv"> <a class="size-12" ng-click="hideAdv=!hideAdv">
<i class="fi-widget m3r"></i> <i class="fi-widget m3r"></i>

View file

@ -6,14 +6,15 @@
<div class="panel"> <div class="panel">
<h2><i class="fi-download m10r"></i> <span translate>Backup Profile</span></h2> <h2><i class="fi-download m10r"></i> <span translate>Backup Profile</span></h2>
<p translate class="text-gray">It's important to backup your profile so that you can recover it in case of disaster. The backup will include all your profile's wallets</p> <p translate class="text-gray">It's important to backup your profile so that you can recover it in case of disaster. The backup will include all your profile's wallets</p>
<a translate class="button primary m0" ng-click="downloadBackup()" <a translate class="button primary m0" ng-click="downloadProfileBackup()"
ng-show="!isSafari">Backup profile</a> ng-show="!isSafari">Backup profile</a>
<a translate class="button primary m0" ng-click="viewBackup()" <a translate class="button primary m0" ng-click="viewProfileBackup()"
ng-show="isSafari && !hideViewBackup">View profile backup</a> ng-show="isSafari && !hideViewProfileBackup">View profile backup</a>
<div ng-show="backupPlainText"> <div ng-show="backupProfilePlainText">
<textarea rows="5">{{backupPlainText}}</textarea> <textarea rows="5">{{backupProfilePlainText}}</textarea>
<div class="show-for-large-up"> <div class="show-for-large-up">
<span translate class="size-12">Copy to clipboard</span> <span class="btn-copy" clip-copy="backupPlainText"> </span> <span translate class="size-12">Copy to clipboard</span> <span
class="btn-copy" clip-copy="backupProfilePlainText"> </span>
</div> </div>
<div class="hide-for-large-up"> <div class="hide-for-large-up">
<span translate class="size-12">Copy this text as it is in a safe place (notepad or email)</span> <span translate class="size-12">Copy this text as it is in a safe place (notepad or email)</span>
@ -41,8 +42,8 @@
<tr <tr
data-ng-repeat="item in wallets | orderBy:'name'" data-ng-repeat="item in wallets | orderBy:'name'"
ng-init="isReady = item.isReady(); ng-init="isReady = item.isReady();
activeWallet = $root.wallet.id; networkName = item.getNetworkName()" networkName = item.getNetworkName()"
ng-class="{'active':activeWallet == item.id, 'deleting':loading==item.id}"> ng-class="{'deleting':loading==item.id}">
<td>{{item.name || item.id }}</td> <td>{{item.name || item.id }}</td>
<td width="120">{{item.requiredCopayers}} of {{item.totalCopayers}} - {{networkName}}</td> <td width="120">{{item.requiredCopayers}} of {{item.totalCopayers}} - {{networkName}}</td>
<td width="200">{{isReady ? 'Complete' : 'Waiting for copayers...'}}</td> <td width="200">{{isReady ? 'Complete' : 'Waiting for copayers...'}}</td>
@ -53,13 +54,20 @@
</span> </span>
</td> </td>
<td width="70" class="text-center"> <td width="70" class="text-center">
<a translate
class="warning" <div ng-show="loading != item.id">
ng-really-message="{{'Are you sure you want to delete the wallet'}} {{(item.name || item.id)}}" <a title="Download Backup" ng-click="downloadWalletBackup(item)"
ng-really-click="deleteWallet(item)" ng-show="!isSafari"><i class="fi-download"></i></a>
ng-show="activeWallet != item.id && loading != item.id">Delete</a> <a title="View Backup" ng-click="viewWalletBackup(item)"
ng-show="isSafari"><i class="fi-eye"></i></a>
&nbsp; &nbsp;
<a title="Delete Wallet"
class="text-warning"
ng-really-message="{{'Are you sure you want to delete the wallet'}} {{(item.name || item.id)}}"
ng-really-click="deleteWallet(item)"
ng-show="loading != item.id"><i class="fi-trash"></i></a>
</div>
<span ng-show="loading == item.id"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span> <span ng-show="loading == item.id"><i class="fi-bitcoin-circle icon-rotate spinner"></i></span>
<span ng-show="activeWallet == item.id">Active</span>
</td> </td>
</tr> </tr>
</tbody> </tbody>