Merge pull request #423 from JDonadio/fix/encrypted-02

Fix export/import wallet with encrypted pk
This commit is contained in:
Matias Alejo Garcia 2016-10-13 16:02:12 -03:00 committed by GitHub
commit 9667aa8e24
5 changed files with 130 additions and 69 deletions

View file

@ -15,6 +15,53 @@ angular.module('copayApp.controllers').controller('exportController',
});
};
function prepareWallet(cb) {
if ($scope.password) return cb(null, $scope.password);
walletService.prepare(wallet, function(err, password) {
if (err) return cb(err);
$scope.password = password;
walletService.getEncodedWalletInfo(wallet, $scope.password, function(err, code) {
if (err) return cb(err);
if (!code)
$scope.formData.supported = false;
else {
$scope.formData.supported = true;
$scope.formData.exportWalletInfo = code;
}
return cb(null, password);
});
});
};
$scope.generateQrCode = function() {
if ($scope.formData.exportWalletInfo) {
$scope.file.value = false;
$timeout(function() {
$scope.$apply();
});
return;
}
prepareWallet(function(err, password) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
if (!password) return;
$scope.file.value = false;
$scope.password = password;
$timeout(function() {
$scope.$apply();
});
});
};
var init = function() {
$scope.formData = {};
$scope.isEncrypted = wallet.isPrivKeyEncrypted();
@ -24,24 +71,6 @@ angular.module('copayApp.controllers').controller('exportController',
$scope.showAdvanced = false;
$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 +96,32 @@ angular.module('copayApp.controllers').controller('exportController',
};
$scope.downloadWalletBackup = function() {
$scope.getAddressbook(function(err, localAddressBook) {
prepareWallet(function(err, password) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to export'));
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
var opts = {
noSign: $scope.formData.noSignEnabled,
addressBook: localAddressBook
};
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');
});
});
});
};
@ -104,21 +142,30 @@ angular.module('copayApp.controllers').controller('exportController',
};
$scope.getBackup = function(cb) {
$scope.getAddressbook(function(err, localAddressBook) {
prepareWallet(function(err, password) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to export'));
return cb(null);
popupService.showAlert(gettextCatalog.getString('Error'), err);
return;
}
var opts = {
noSign: $scope.formData.noSignEnabled,
addressBook: localAddressBook
};
if (!password) return;
var ew = backupService.walletExport($scope.formData.password, opts);
if (!ew) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to export'));
}
return cb(ew);
$scope.getAddressbook(function(err, localAddressBook) {
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to export'));
return cb(null);
}
var opts = {
noSign: $scope.formData.noSignEnabled,
addressBook: localAddressBook,
password: password
};
var ew = backupService.walletExport($scope.formData.password, opts);
if (!ew) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to export'));
}
return cb(ew);
});
});
};
@ -171,6 +218,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;
});
});

View file

@ -21,7 +21,8 @@ angular.module('copayApp.controllers').controller('preferencesDeleteWalletContro
if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), err.message || err);
} else {
$ionicHistory.removeBackView();
$ionicHistory.clearHistory();
$ionicHistory.clearCache();
$state.go('tabs.home');
}
});