diff --git a/js/controllers/import.js b/js/controllers/import.js index 22b4a50ae..33fa8df23 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -3,10 +3,11 @@ angular.module('copayApp.controllers').controller('ImportController', function($scope, $rootScope, $location, controllerUtils, notification, isMobile, Compatibility) { - $rootScope.title = 'Import a backup'; + $rootScope.title = 'Import wallet'; $scope.importStatus = 'Importing wallet - Reading backup...'; $scope.hideAdv = true; $scope.is_iOS = isMobile.iOS(); + $scope.importOpts = {}; Compatibility.check($scope); @@ -17,44 +18,6 @@ angular.module('copayApp.controllers').controller('ImportController', $scope.$digest(); } - var _importBackup = function(encryptedObj) { - var password = $scope.password; - updateStatus('Importing wallet - Setting things up...'); - var skipFields = []; - if ($scope.skipPublicKeyRing) - skipFields.push('publicKeyRing'); - - if ($scope.skipTxProposals) - skipFields.push('txProposals'); - - $rootScope.iden.importEncryptedWallet(encryptedObj, password, skipFields, opts, function(err, w) { - if (!w) { - $scope.loading = false; - $scope.error = 'Wrong password'; - $rootScope.$digest(); - return; - } - - // if wallet was never used, we're done - if (!w.isReady()) { - controllerUtils.installWalletHandlers($scope, w); - controllerUtils.setFocusedWallet(w); - return; - } - - // if it was used, we need to scan for indices - w.updateIndexes(function(err) { - updateStatus('Importing wallet - We are almost there...'); - if (err) { - $scope.loading = false; - $scope.error = 'Error updating indexes: ' + err; - } - controllerUtils.installWalletHandlers($scope, w); - controllerUtils.setFocusedWallet(w); - }); - }); - }; - $scope.openFileDialog = function() { if (window.cshell) { return cshell.send('backup:import'); @@ -62,72 +25,79 @@ angular.module('copayApp.controllers').controller('ImportController', $scope.choosefile = !$scope.choosefile; }; - $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; - copay.Compatibility.importEncryptedWallet($rootScope.iden, encryptedObj, $scope.password, {}, - function(err, wallet) { - if (err) { - $scope.loading = false; - $scope.error = 'Could not read wallet. Please check your password'; - } else { - controllerUtils.installWalletHandlers($scope, wallet); - controllerUtils.setFocusedWallet(wallet); - return; - } - } - ); - } - }; - }; + $scope._doImport = function(encryptedObj, password) { + updateStatus('Importing wallet - Procesing backup...'); - $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; - } - - if (backupFile) { - reader.readAsBinaryString(backupFile); - } else { - copay.Compatibility.importEncryptedWallet($rootScope.iden, backupText, $scope.password, {}, - function(err, wallet) { - if (err) { - $scope.error = 'Could not read wallet. Please check your password'; - } else { - copay.Compatibility.deleteOldWallet(backupOldWallet); - controllerUtils.installWalletHandlers($scope, wallet); + copay.Compatibility.importEncryptedWallet($rootScope.iden, encryptedObj, + $scope.password, $scope.importOpts, function(err, wallet) { + if (err) { + $scope.loading = false; + $scope.error = 'Could not read wallet. Please check your password'; + } else { + controllerUtils.installWalletHandlers($scope, wallet); + updateStatus('Importing wallet - Scanning for transactions...'); + wallet.updateIndexes(function(err) { controllerUtils.setFocusedWallet(wallet); - return; - } + }); } - ); - try { - _importBackup(backupText); - } catch (e) { - copay.Compatibility.importEncryptedWallet(backupText, $scope.password, $scope.skipPublicKeyRing, $scope.skipTxProposals); } + ); + }; + + $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._doImport(encryptedObj, $scope.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; + + + if (backupFile) { + reader.readAsBinaryString(backupFile); + } else { + $scope._doImport(backupText, $scope.password); + copay.Compatibility.deleteOldWallet(backupOldWallet); + } + }; +}); diff --git a/js/controllers/join.js b/js/controllers/join.js index 0a97826b1..799b28447 100644 --- a/js/controllers/join.js +++ b/js/controllers/join.js @@ -5,7 +5,7 @@ angular.module('copayApp.controllers').controller('JoinController', $rootScope.fromSetup = false; $scope.loading = false; $scope.isMobile = !!window.cordova; - $rootScope.title = 'Join an existent wallet'; + $rootScope.title = 'Join shared wallet'; // QR code Scanner var cameraInput; diff --git a/js/models/Identity.js b/js/models/Identity.js index 1c71beeba..937c8e380 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -289,8 +289,8 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) { var w = importFunction(obj, readOpts); if (!w) return cb(new Error('Could not decrypt')); - this._checkVersion(w.version); - this.addWallet(w); + self._checkVersion(w.version); + self.addWallet(w); self.bindWallet(w); self.storeWallet(w, function(err) { if (err) return cb(err); diff --git a/js/models/Wallet.js b/js/models/Wallet.js index b205515b9..0bd86cadf 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -2487,7 +2487,8 @@ Wallet.prototype.createTxSync = function(toAddress, amountSatStr, comment, utxos }; /** - * @desc Updates all the indexes for the current publicKeyRing + * @desc Updates all the indexes for the current publicKeyRing. This scans + * the blockchain looking for transactions on derived addresses. * * Triggers a wallet {@link Wallet#store} call * @param {Function} callback - called when all indexes have been updated. Receives an error, if any, as first argument diff --git a/views/import.html b/views/import.html index e5f49ed3a..d604661c3 100644 --- a/views/import.html +++ b/views/import.html @@ -1,7 +1,6 @@
- - {{ importStatus|translate }} + {{ importStatus|translate }}
@@ -10,49 +9,42 @@
-
- - {{error|translate}} -
- - +
+ {{error|translate}} +
+ +
- - Choose backup file from your computer + + Choose backup file from your computer - +
-
-
- - + +
- + Show Hide @@ -63,15 +55,13 @@
diff --git a/views/includes/head.html b/views/includes/head.html index 7f85fecfb..1fefbec00 100644 --- a/views/includes/head.html +++ b/views/includes/head.html @@ -27,10 +27,10 @@
  • {{'Create new wallet'|translate}}
  • -
  • - {{'Join an existent wallet'|translate}}
  • -
  • - {{'Import a backup'|translate}}
  • +
  • + {{'Join shared wallet'|translate}}
  • +
  • + {{'Import wallet'|translate}}
  • {{'Profile'|translate}}
  • diff --git a/views/includes/sidebar-mobile.html b/views/includes/sidebar-mobile.html index d8eab2f92..6e5d61498 100644 --- a/views/includes/sidebar-mobile.html +++ b/views/includes/sidebar-mobile.html @@ -89,12 +89,12 @@ {{'Create new wallet' | translate }}
  • - - {{'Join an existent wallet' | translate }} + + {{'Join shared wallet' | translate }}
  • - - {{'Import a backup' | translate }} + + {{'Import wallet' | translate }}