fix wallet lock - add tabs in export wallet

This commit is contained in:
Javier 2016-06-27 16:01:06 -03:00
commit 45d44a927b
3 changed files with 146 additions and 86 deletions

View file

@ -5,89 +5,99 @@
</div> </div>
<div class="content preferences" ng-controller="exportController" ng-init="init(index.prevState)"> <div class="content preferences" ng-controller="exportController" ng-init="init(index.prevState)">
<h4></h4> <div class="create-tab small-only-text-center">
<div ng-show="!backupWalletPlainText"> <div class="row">
<div class="text-warning size-14 m20b" ng-show="error"> <div class="tab-container small-6 medium-3 large-2"
<i class="fi-alert size-12"></i> ng-class="{'selected':!exportQR}"
<span translate>Failed to export</span> ng-style="{'border-color':!exportQR ? index.backgroundColor: 'inherit'}"
ng-click="exportQR = false">
<a href ng-style="{'color':!exportQR ? index.backgroundColor: 'inherit'}" translate>File/Text</a>
</div> </div>
<div class="tab-container small-6 medium-3 large-2"
ng-class="{'selected':exportQR}"
ng-style="{'border-color':exportQR ? index.backgroundColor: 'inherit'}"
ng-click="exportQR = true">
<a href ng-style="{'color':exportQR ? index.backgroundColor: 'inherit'}" translate>QR Code</a>
</div>
</div>
</div>
<div ng-show="!backupWalletPlainText && !exportQR">
<div class="text-warning size-14 m20b" ng-show="error">
<i class="fi-alert size-12"></i>
<span translate>Failed to export</span>
</div>
<form>
<div class="row"> <div class="row">
<div class="columns"> <div class="columns">
<div class="text-warning size-14 m20b" ng-show="isEncrypted"> <label for="password" translate>Set up a password </label>
<i class="fi-alert size-12"></i> <div class="input">
<span translate> A spending password is set for this wallet. Exporting keeps the spending password in the export archive.</span> <input type="password" class="form-control" placeholder="{{'Your password'|translate}}" name="password" ng-model="password">
</div>
<label for="password" translate>Repeat the password</label>
<div class="input">
<input type="password" class="form-control" placeholder="{{'Repeat password'|translate}}" name="password" ng-model="repeatpassword">
</div> </div>
</div> </div>
</div> </div>
</form>
<form ng-hide="touchidEnabled && !touchidSuccess"> <h4></h4>
<div class="row">
<div class="columns">
<label for="password" translate>Set up a password </label>
<div class="input">
<input type="password" class="form-control" placeholder="{{'Your password'|translate}}" name="password" ng-model="password">
</div>
<label for="password" translate>Repeat the password</label> <ion-toggle ng-model="noSignEnabled" toggle-class="toggle-balanced" class="r0">
<div class="input"> <span class="toggle-label" translate>Do not include private key</span>
<input type="password" class="form-control" placeholder="{{'Repeat password'|translate}}" name="password" ng-model="repeatpassword"> </ion-toggle>
</div>
</div>
</div>
</form>
<h4></h4> <div class="box-notification" ng-show="!index.canSign">
<span class="text-warning size-14">
<ion-toggle ng-model="noSignEnabled" toggle-class="toggle-balanced" class="r0"> <i class="fi-alert"></i>
<span class="toggle-label" translate>Do not include private key</span> <span translate>
</ion-toggle> WARNING: The private key of this wallet is not available. The export allows to check the wallet balance, transaction history, and create spend proposals from the export. However, does not allow to approve (sign) proposals, so <b>funds will not be accessible from the export</b>.
<div class="box-notification" ng-show="!index.canSign">
<span class="text-warning size-14">
<i class="fi-alert"></i>
<span translate>
WARNING: The private key of this wallet is not available. The export allows to check the wallet balance, transaction history, and create spend proposals from the export. However, does not allow to approve (sign) proposals, so <b>funds will not be accessible from the export</b>.
</span>
</span> </span>
</div> </span>
</div>
<div class="box-notification" ng-show="noSign">
<div class="box-notification" ng-show="noSign"> <span class="text-warning size-14">
<span class="text-warning size-14"> <i class="fi-alert"></i>
<i class="fi-alert"></i> <span translate>
<span translate> WARNING: Not including the private key allows to check the wallet balance, transaction history, and create spend proposals from the export. However, does not allow to approve (sign) proposals, so <b>funds will not be accessible from the export</b>.
WARNING: Not including the private key allows to check the wallet balance, transaction history, and create spend proposals from the export. However, does not allow to approve (sign) proposals, so <b>funds will not be accessible from the export</b>.
</span>
</span> </span>
</div> </span>
</div>
<div class="row"> <div class="row">
<div class="columns"> <div class="columns">
<button class="black round expand m20t" ng-click="downloadWalletBackup()" <button class="black round expand m20t" ng-click="downloadWalletBackup()"
ng-disabled="(!password || password != repeatpassword)" ng-disabled="(!password || password != repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-show="!isSafari && !isCordova"><i class="fi-download"></i>
<span translate>Download</span></button>
<button class="black round expand m20t" ng-click="viewWalletBackup()"
ng-disabled="(!password || password != repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-show="isSafari && !isCordova"><i class="fi-eye"></i>
<span translate>View</span></button>
<div ng-show="isCordova">
<h4 translate>Export options</h4>
<button class="black round expand" ng-disabled="(!password || password != repeatpassword)"
ng-style="{'background-color':index.backgroundColor}" ng-style="{'background-color':index.backgroundColor}"
ng-show="!index.isSafari && !index.isCordova"><i class="fi-download"></i> ng-click="copyWalletBackup()"><i class="fi-clipboard-pencil"></i>
<span translate>Download</span></button> <span translate>Copy to clipboard</span></button>
<button class="black round expand m20t" ng-click="viewWalletBackup()" <button class="black round expand" ng-disabled="(!password || password != repeatpassword)"
ng-disabled="(!password || password != repeatpassword)"
ng-style="{'background-color':index.backgroundColor}" ng-style="{'background-color':index.backgroundColor}"
ng-show="index.isSafari && !index.isCordova"><i class="fi-eye"></i> ng-click="sendWalletBackup()"><i class="fi-mail"></i>
<span translate>View</span></button> <span translate>Send by email</span></button>
<div ng-show="index.isCordova">
<h4 translate>Export options</h4>
<button class="black round expand" ng-disabled="(!password || password != repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-click="copyWalletBackup()"><i class="fi-clipboard-pencil"></i>
<span translate>Copy to clipboard</span></button>
<button class="black round expand" ng-disabled="(!password || password != repeatpassword)"
ng-style="{'background-color':index.backgroundColor}"
ng-click="sendWalletBackup()"><i class="fi-mail"></i>
<span translate>Send by email</span></button>
</div>
</div> </div>
</div> </div>
</div>
</div>
<div class="containter text-center p50t" ng-show="exportQR">
<qrcode size="220" version="7" error-correction-level="M" data="{{exportWalletInfo}}"></qrcode>
<span translate></span>
</div> </div>
<div class="row" ng-show="backupWalletPlainText"> <div class="row" ng-show="backupWalletPlainText">
@ -102,6 +112,5 @@
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="extra-margin-bottom"></div> <div class="extra-margin-bottom"></div>

View file

@ -23,8 +23,7 @@ angular.module('copayApp.controllers').controller('backupController',
handleEncryptedWallet(fc, function(err) { handleEncryptedWallet(fc, function(err) {
if (err) { if (err) {
$scope.error = bwsError.msg(err, gettext('Could not decrypt')); go.path(prevState);
$log.warn('Error decrypting credentials:', $scope.error);
return; return;
} }
$scope.credentialsEncrypted = false; $scope.credentialsEncrypted = false;
@ -69,10 +68,13 @@ angular.module('copayApp.controllers').controller('backupController',
}; };
$scope.goBack = function() { $scope.goBack = function() {
walletService.lock(fc);
go.path(prevState || 'walletHome'); go.path(prevState || 'walletHome');
}; };
$scope.$on('$destroy', function() {
walletService.lock(fc);
});
$scope.goToStep = function(n) { $scope.goToStep = function(n) {
if (n == 1) if (n == 1)
$scope.initFlow(); $scope.initFlow();

View file

@ -1,39 +1,88 @@
'use strict'; 'use strict';
angular.module('copayApp.controllers').controller('exportController', angular.module('copayApp.controllers').controller('exportController',
function($scope, $timeout, $log, backupService, fingerprintService, configService, storageService, profileService, platformInfo, notification, go, gettext, gettextCatalog) { function($rootScope, $scope, $timeout, $log, lodash, backupService, walletService, fingerprintService, configService, storageService, profileService, platformInfo, notification, go, gettext, gettextCatalog) {
var prevState;
var isWP = platformInfo.isWP; var isWP = platformInfo.isWP;
var isAndroid = platformInfo.isAndroid; var isAndroid = platformInfo.isAndroid;
var isCordova = platformInfo.isCordova;
$scope.error = null;
$scope.success = null;
var fc = profileService.focusedClient; var fc = profileService.focusedClient;
$scope.isEncrypted = fc.isPrivKeyEncrypted(); $scope.isEncrypted = fc.isPrivKeyEncrypted();
$scope.touchidSuccess = null; $scope.isCordova = platformInfo.isCordova;
$scope.touchidEnabled = null; $scope.isSafari = platformInfo.isSafari;
$scope.error = null; $scope.error = null;
$scope.init = function(state) { $scope.init = function(state) {
if (!isCordova) return; $scope.QROpts = false;
prevState = state || 'walletHome';
var config = configService.getSync();
var touchidAvailable = fingerprintService.isAvailable();
var touchidEnabled = $scope.touchidEnabled = config.touchIdFor ? config.touchIdFor[fc.credentials.walletId] : null;
if (!touchidAvailable || !touchidEnabled) return;
fingerprintService.check(fc, function(err) { fingerprintService.check(fc, function(err) {
if (err) if (err) {
go.path(state || 'walletHome'); go.path(prevState);
return;
}
$scope.touchidSuccess = true; handleEncryptedWallet(fc, function(err) {
$timeout(function() { if (err) {
$scope.$apply(); go.path(prevState);
}, 10); return;
}
$scope.exportWalletInfo = encodeWalletInfo();
$timeout(function() {
$scope.$apply();
}, 1);
});
}); });
}; };
$scope.$on('$destroy', function() {
walletService.lock(fc);
});
function handleEncryptedWallet(client, cb) {
if (!walletService.isEncrypted(client)) {
$scope.credentialsEncrypted = false;
return cb();
}
$rootScope.$emit('Local/NeedsPassword', false, function(err, password) {
if (err) return cb(err);
return cb(walletService.unlock(client, password));
});
};
function encodeWalletInfo() {
var c = fc.credentials;
var encodingType = {
mnemonic: 1,
xpriv: 2,
xpub: 3
};
var info;
if (c.canSign()) {
if (c.mnemonic) {
info = {
type: encodingType.mnemonic,
data: c.mnemonic
}
} else {
info = {
type: encodingType.xpriv,
data: c.xPrivKey
}
}
} else {
info = {
type: encodingType.xpub,
data: c.xPubKey
}
}
var code = info.type + c.network.charAt(0).toLowerCase() + info.data;
return code;
};
$scope.downloadWalletBackup = function() { $scope.downloadWalletBackup = function() {
$scope.getAddressbook(function(err, localAddressBook) { $scope.getAddressbook(function(err, localAddressBook) {
if (err) { if (err) {