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

@ -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) {