From 36822dce49611f9fc85d5c8c4138928613851e7d Mon Sep 17 00:00:00 2001 From: Matias Pando Date: Wed, 26 Nov 2014 17:16:46 -0300 Subject: [PATCH] Added needBackup flag when importing a wallet --- js/controllers/import.js | 130 +++++++++++++++++++++------------------ js/models/Identity.js | 7 +++ 2 files changed, 77 insertions(+), 60 deletions(-) diff --git a/js/controllers/import.js b/js/controllers/import.js index 895bc5790..19ed84abf 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -18,71 +18,81 @@ angular.module('copayApp.controllers').controller('ImportController', $scope.$digest(); } - $scope.getFile = function() { - // If we use onloadend, we need to check the readyState. - reader.onloadend = function(evt) { - if (evt.target.readyState == FileReader.DONE) { // DONE == 2 - var encryptedObj = evt.target.result; + + $scope.getFile = function() { + // If we use onloadend, we need to check the readyState. + reader.onloadend = function(evt) { + if (evt.target.readyState == FileReader.DONE) { // DONE == 2 + var encryptedObj = evt.target.result; + updateStatus('Importing wallet - Procesing backup...'); + identityService.importWallet(encryptedObj, $scope.password, {}, function(err) { + if (err) { + $scope.loading = false; + $scope.error = 'Could not read wallet. Please check your password'; + } + }); + } + } + }; + + $scope.import = function(form) { + $scope.loading = true; + + if (form.$invalid) { + $scope.loading = false; + $scope.error = 'There is an error in the form'; + return; + } + + var backupFile = $scope.file; + var backupText = form.backupText.$modelValue; + var backupOldWallet = form.backupOldWallet.$modelValue; + var password = form.password.$modelValue; + + if (backupOldWallet) { + backupText = backupOldWallet.value; + } + + if (!backupFile && !backupText) { + $scope.loading = false; + $scope.error = 'Please, select your backup file'; + return; + } + + $scope.importOpts = {}; + + var skipFields = []; + + if ($scope.skipPublicKeyRing) + skipFields.push('publicKeyRing'); + + if ($scope.skipTxProposals) + skipFields.push('txProposals'); + + if (skipFields) + $scope.importOpts.skipFields = skipFields; + + + << << << < HEAD + if (backupFile) { + reader.readAsBinaryString(backupFile); + } else { updateStatus('Importing wallet - Procesing backup...'); - identityService.importWallet(encryptedObj, $scope.password, {}, function(err){ + identityService.importWallet(encryptedObj, $scope.password, $scope.importOpts, function(err) { if (err) { $scope.loading = false; $scope.error = 'Could not read wallet. Please check your password'; } + copay.Compatibility.deleteOldWallet(backupOldWallet); }); } }; - }; - - $scope.import = function(form) { - $scope.loading = true; - - if (form.$invalid) { - $scope.loading = false; - $scope.error = 'There is an error in the form'; - return; - } - - var backupFile = $scope.file; - var backupText = form.backupText.$modelValue; - var backupOldWallet = form.backupOldWallet.$modelValue; - var password = form.password.$modelValue; - - if (backupOldWallet) { - backupText = backupOldWallet.value; - } - - if (!backupFile && !backupText) { - $scope.loading = false; - $scope.error = 'Please, select your backup file'; - return; - } - - $scope.importOpts = {}; - - var skipFields = []; - - if ($scope.skipPublicKeyRing) - skipFields.push('publicKeyRing'); - - if ($scope.skipTxProposals) - skipFields.push('txProposals'); - - if (skipFields) - $scope.importOpts.skipFields = skipFields; - - - if (backupFile) { - reader.readAsBinaryString(backupFile); - } else { - updateStatus('Importing wallet - Procesing backup...'); - identityService.importWallet(encryptedObj, $scope.password, $scope.importOpts, function(err){ - if (err) { - $scope.loading = false; - $scope.error = 'Could not read wallet. Please check your password'; - } - copay.Compatibility.deleteOldWallet(backupOldWallet); - }); - } - }; -}); + }); === === = +if (backupFile) { + reader.readAsBinaryString(backupFile); +} else { + $scope._doImport(backupText, $scope.password); + copay.Compatibility.deleteOldWallet(backupOldWallet); +} +}; +}); >>> >>> > Added needBackup flag when importing a wallet diff --git a/js/models/Identity.js b/js/models/Identity.js index 8258d5d86..1f3c28fba 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -278,6 +278,13 @@ Identity.prototype.exportEncryptedWithWalletInfo = function(opts) { return crypto.encrypt(this.password, this.exportWithWalletInfo(opts)); }; +Identity.prototype.setBackupNeeded = function() { + this.backupNeeded = true; + this.store({ + noWallets: true + }, function() {}); +} + Identity.prototype.setBackupDone = function() { this.backupNeeded = false; this.store({