From 45d44a927b3a5ec99d87223c3922771a3e9f9cd7 Mon Sep 17 00:00:00 2001 From: Javier Date: Mon, 27 Jun 2016 16:01:06 -0300 Subject: [PATCH] fix wallet lock - add tabs in export wallet --- public/views/export.html | 139 +++++++++++++++++++---------------- src/js/controllers/backup.js | 8 +- src/js/controllers/export.js | 89 +++++++++++++++++----- 3 files changed, 148 insertions(+), 88 deletions(-) diff --git a/public/views/export.html b/public/views/export.html index 7aa69fae8..32dbaa08b 100644 --- a/public/views/export.html +++ b/public/views/export.html @@ -5,89 +5,99 @@
-

-
-
- - Failed to export +
+
+ +
+ QR Code +
+
+
+
+
+ + Failed to export +
+ +
-
- - A spending password is set for this wallet. Exporting keeps the spending password in the export archive. + +
+ +
+ + +
+
+ -
-
-
- -
- -
+

- -
- -
-
-
-
+ + Do not include private key + -

- - - Do not include private key - - -
- - - - 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 funds will not be accessible from the export. - +
+ + + + 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 funds will not be accessible from the export. -
+
+
- -
- - - - 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 funds will not be accessible from the export. - +
+ + + + 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 funds will not be accessible from the export. -
+
+
-
-
- + +
+

Export options

+ - + -
-

Export options

- - -
+ ng-click="sendWalletBackup()"> + Send by email
+
+
+
+ +
@@ -102,6 +112,5 @@
-
diff --git a/src/js/controllers/backup.js b/src/js/controllers/backup.js index 320144800..84008adf4 100644 --- a/src/js/controllers/backup.js +++ b/src/js/controllers/backup.js @@ -23,8 +23,7 @@ angular.module('copayApp.controllers').controller('backupController', handleEncryptedWallet(fc, function(err) { if (err) { - $scope.error = bwsError.msg(err, gettext('Could not decrypt')); - $log.warn('Error decrypting credentials:', $scope.error); + go.path(prevState); return; } $scope.credentialsEncrypted = false; @@ -69,10 +68,13 @@ angular.module('copayApp.controllers').controller('backupController', }; $scope.goBack = function() { - walletService.lock(fc); go.path(prevState || 'walletHome'); }; + $scope.$on('$destroy', function() { + walletService.lock(fc); + }); + $scope.goToStep = function(n) { if (n == 1) $scope.initFlow(); diff --git a/src/js/controllers/export.js b/src/js/controllers/export.js index cea7af04a..cb7561458 100644 --- a/src/js/controllers/export.js +++ b/src/js/controllers/export.js @@ -1,39 +1,88 @@ 'use strict'; 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 isAndroid = platformInfo.isAndroid; - var isCordova = platformInfo.isCordova; - - $scope.error = null; - $scope.success = null; var fc = profileService.focusedClient; $scope.isEncrypted = fc.isPrivKeyEncrypted(); - $scope.touchidSuccess = null; - $scope.touchidEnabled = null; + $scope.isCordova = platformInfo.isCordova; + $scope.isSafari = platformInfo.isSafari; $scope.error = null; $scope.init = function(state) { - if (!isCordova) return; - - var config = configService.getSync(); - var touchidAvailable = fingerprintService.isAvailable(); - var touchidEnabled = $scope.touchidEnabled = config.touchIdFor ? config.touchIdFor[fc.credentials.walletId] : null; - - if (!touchidAvailable || !touchidEnabled) return; + $scope.QROpts = false; + prevState = state || 'walletHome'; fingerprintService.check(fc, function(err) { - if (err) - go.path(state || 'walletHome'); + if (err) { + go.path(prevState); + return; + } - $scope.touchidSuccess = true; - $timeout(function() { - $scope.$apply(); - }, 10); + handleEncryptedWallet(fc, function(err) { + if (err) { + go.path(prevState); + 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.getAddressbook(function(err, localAddressBook) { if (err) {