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,21 +15,23 @@ angular.module('copayApp.controllers').controller('exportController',
}); });
}; };
var init = function() { function prepareWallet(cb) {
$scope.formData = {}; if ($scope.password) return cb($scope.password);
$scope.isEncrypted = wallet.isPrivKeyEncrypted();
$scope.isCordova = platformInfo.isCordova;
$scope.isSafari = platformInfo.isSafari;
$scope.formData.noSignEnabled = false;
$scope.showAdvanced = false;
$scope.wallet = wallet;
$scope.canSign = wallet.canSign();
walletService.getEncodedWalletInfo(wallet, function(err, code) { walletService.prepare(wallet, function(err, password) {
if (err || !code) { if (err) {
$log.warn(err); popupService.showAlert(gettextCatalog.getString('Error'), err);
return $ionicHistory.goBack(); 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) if (!code)
$scope.formData.supported = false; $scope.formData.supported = false;
@ -40,8 +42,37 @@ angular.module('copayApp.controllers').controller('exportController',
$timeout(function() { $timeout(function() {
$scope.$apply(); $scope.$apply();
}, 1);
}); });
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();
$scope.isCordova = platformInfo.isCordova;
$scope.isSafari = platformInfo.isSafari;
$scope.formData.noSignEnabled = false;
$scope.showAdvanced = false;
$scope.wallet = wallet;
$scope.canSign = wallet.canSign();
}; };
/* /*
@ -67,6 +98,9 @@ angular.module('copayApp.controllers').controller('exportController',
}; };
$scope.downloadWalletBackup = function() { $scope.downloadWalletBackup = function() {
prepareWallet(function(password) {
if (!password) return;
$scope.getAddressbook(function(err, localAddressBook) { $scope.getAddressbook(function(err, localAddressBook) {
if (err) { if (err) {
popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to export')); popupService.showAlert(gettextCatalog.getString('Error'), gettextCatalog.getString('Failed to export'));
@ -74,7 +108,8 @@ angular.module('copayApp.controllers').controller('exportController',
} }
var opts = { var opts = {
noSign: $scope.formData.noSignEnabled, noSign: $scope.formData.noSignEnabled,
addressBook: localAddressBook addressBook: localAddressBook,
password: password
}; };
backupService.walletDownload($scope.formData.password, opts, function(err) { backupService.walletDownload($scope.formData.password, opts, function(err) {
@ -86,6 +121,7 @@ angular.module('copayApp.controllers').controller('exportController',
$state.go('tabs.home'); $state.go('tabs.home');
}); });
}); });
});
}; };
$scope.getAddressbook = function(cb) { $scope.getAddressbook = function(cb) {
@ -171,6 +207,11 @@ angular.module('copayApp.controllers').controller('exportController',
$scope.$on("$ionicView.beforeEnter", function(event, data) { $scope.$on("$ionicView.beforeEnter", function(event, data) {
init(); init();
$scope.file = {
value: true
};
$scope.formData.exportWalletInfo = null;
$scope.password = null;
}); });
}); });

View file

@ -869,10 +869,9 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (!root.isEncrypted(wallet)) return cb(); if (!root.isEncrypted(wallet)) return cb();
askPassword(wallet.name, gettext('Enter Spending Password'), function(password) { askPassword(wallet.name, gettext('Enter Spending Password'), function(password) {
if (!password) return cb('no password'); if (!password) return cb('No password');
if (!wallet.checkPassword(password)) return cb('wrong password'); if (!wallet.checkPassword(password)) return cb('Wrong password');
wallet.credentials.decryptPrivateKey(password);
return cb(null, password); return cb(null, password);
}); });
}; };
@ -990,8 +989,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
}); });
}; };
root.getEncodedWalletInfo = function(wallet, cb) { root.getEncodedWalletInfo = function(wallet, password, cb) {
var derivationPath = wallet.credentials.getBaseAddressDerivationPath(); var derivationPath = wallet.credentials.getBaseAddressDerivationPath();
var encodingType = { var encodingType = {
mnemonic: 1, mnemonic: 1,
@ -1004,8 +1002,7 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
if (wallet.credentials.derivationStrategy != 'BIP44' || !wallet.canSign()) if (wallet.credentials.derivationStrategy != 'BIP44' || !wallet.canSign())
return null; return null;
root.getKeys(wallet, function(err, keys) { var keys = root.getKeysWithPassword(wallet, password);
if (err || !keys) return cb(err);
if (keys.mnemonic) { if (keys.mnemonic) {
info = { info = {
@ -1018,9 +1015,8 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
data: keys.xPrivKey data: keys.xPrivKey
} }
} }
return cb(null, info.type + '|' + info.data + '|' + wallet.credentials.network.toLowerCase() + '|' + derivationPath + '|' + (wallet.credentials.mnemonicHasPassphrase));
}); return cb(null, info.type + '|' + info.data + '|' + wallet.credentials.network.toLowerCase() + '|' + derivationPath + '|' + (wallet.credentials.mnemonicHasPassphrase));
}; };
root.setTouchId = function(wallet, enabled, cb) { root.setTouchId = function(wallet, enabled, cb) {
@ -1055,6 +1051,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
}); });
}; };
root.getKeysWithPassword = function(wallet, password) {
try {
return wallet.getKeys(password);
} catch (e) {}
}
root.getViewStatus = function(wallet, txp) { root.getViewStatus = function(wallet, txp) {
var status = txp.status; var status = txp.status;
var type; var type;

View file

@ -5,17 +5,17 @@
</ion-nav-back-button> </ion-nav-back-button>
</ion-nav-bar> </ion-nav-bar>
<ion-content ng-init="file = true"> <ion-content>
<div class="row text-center top-tabs"> <div class="row text-center">
<div class="col" ng-click="file = true" ng-style="file && {'border-bottom-style': 'solid'}"> <div class="col" ng-click="file.value = true" ng-style="file.value && {'border-bottom': '2px solid'}">
<span class="" translate>File/Text</span> <span class="" translate>File/Text</span>
</div> </div>
<div class="col" ng-click="file = false" ng-style="!file && {'border-bottom-style': 'solid'}"> <div class="col" ng-click="generateQrCode();" ng-style="!file.value && {'border-bottom': '2px solid'}">
<span class="" translate>QR Code</span> <span class="" translate>QR Code</span>
</div> </div>
</div> </div>
<div ng-include="'views/tab-export-file.html'" ng-if="file"></div> <div ng-include="'views/tab-export-file.html'" ng-if="file.value"></div>
<div ng-include="'views/tab-export-qrCode.html'" ng-if="!file"></div> <div ng-include="'views/tab-export-qrCode.html'" ng-if="!file.value"></div>
</ion-content> </ion-content>
</ion-view> </ion-view>