fix export wallet

This commit is contained in:
Javier 2016-10-12 18:11:02 -03:00
commit 696c5bbd18
3 changed files with 97 additions and 54 deletions

View file

@ -15,6 +15,54 @@ angular.module('copayApp.controllers').controller('exportController',
});
};
function prepareWallet(cb) {
if ($scope.password) return cb($scope.password);
walletService.prepare(wallet, function(err, password) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
return cb();
}
$scope.password = password;
walletService.getEncodedWalletInfo(wallet, $scope.password, function(err, code) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Could not decrypt private key'));
return cb(password);
}
$scope.file.value = false;
if (!code)
$scope.formData.supported = false;
else {
$scope.formData.supported = true;
$scope.formData.exportWalletInfo = code;
}
$timeout(function() {
$scope.$apply();
});
return cb(password);
});
});
};
$scope.generateQrCode = function() {
if ($scope.formData.exportWalletInfo) {
$scope.file.value = false;
$timeout(function() {
$scope.$apply();
});
return;
}
prepareWallet(function(password) {
if (!password) return;
$scope.password = password;
});
};
var init = function() {
$scope.formData = {};
$scope.isEncrypted = wallet.isPrivKeyEncrypted();
@ -25,23 +73,6 @@ angular.module('copayApp.controllers').controller('exportController',
$scope.wallet = wallet;
$scope.canSign = wallet.canSign();
walletService.getEncodedWalletInfo(wallet, function(err, code) {
if (err || !code) {
$log.warn(err);
return $ionicHistory.goBack();
}
if (!code)
$scope.formData.supported = false;
else {
$scope.formData.supported = true;
$scope.formData.exportWalletInfo = code;
}
$timeout(function() {
$scope.$apply();
}, 1);
});
};
/*
@ -67,23 +98,28 @@ angular.module('copayApp.controllers').controller('exportController',
};
$scope.downloadWalletBackup = function() {
$scope.getAddressbook(function(err, localAddressBook) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to export'));
return;
}
var opts = {
noSign: $scope.formData.noSignEnabled,
addressBook: localAddressBook
};
prepareWallet(function(password) {
if (!password) return;
backupService.walletDownload($scope.formData.password, opts, function(err) {
$scope.getAddressbook(function(err, localAddressBook) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to export'));
return;
}
$ionicHistory.removeBackView();
$state.go('tabs.home');
var opts = {
noSign: $scope.formData.noSignEnabled,
addressBook: localAddressBook,
password: password
};
backupService.walletDownload($scope.formData.password, opts, function(err) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to export'));
return;
}
$ionicHistory.removeBackView();
$state.go('tabs.home');
});
});
});
};
@ -171,6 +207,11 @@ angular.module('copayApp.controllers').controller('exportController',
$scope.$on("$ionicView.beforeEnter", function(event, data) {
init();
$scope.file = {
value: true
};
$scope.formData.exportWalletInfo = null;
$scope.password = null;
});
});