diff --git a/js/controllers/createProfile.js b/js/controllers/createProfile.js index 5dae983b9..34997f5a7 100644 --- a/js/controllers/createProfile.js +++ b/js/controllers/createProfile.js @@ -2,9 +2,7 @@ angular.module('copayApp.controllers').controller('CreateProfileController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager, identityService) { controllerUtils.redirIfLogged(); - $scope.retreiving = true; - - identityService.check($scope); + $scope.retreiving = false; $scope.createProfile = function(form) { if (form && form.$invalid) { diff --git a/js/controllers/home.js b/js/controllers/home.js index fdc4f7e92..657102d3d 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -1,11 +1,11 @@ 'use strict'; -angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager, identityService) { +angular.module('copayApp.controllers').controller('HomeController', function($scope, $rootScope, $location, notification, controllerUtils, pluginManager, identityService, Compatibility) { controllerUtils.redirIfLogged(); - $scope.retreiving = true; - - identityService.check($scope); $scope.confirmedEmail = getParam('confirmed'); + $scope.retreiving = false; + Compatibility.check($scope); + $scope.openProfile = function(form) { if (form && form.$invalid) { notification.error('Error', 'Please enter the required fields'); diff --git a/js/controllers/import.js b/js/controllers/import.js index b6e17f8c0..7b898bf09 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -8,6 +8,8 @@ angular.module('copayApp.controllers').controller('ImportController', $scope.hideAdv = true; $scope.is_iOS = isMobile.iOS(); + Compatibility.check($scope); + var reader = new FileReader(); var updateStatus = function(status) { @@ -65,7 +67,7 @@ angular.module('copayApp.controllers').controller('ImportController', reader.onloadend = function(evt) { if (evt.target.readyState == FileReader.DONE) { // DONE == 2 var encryptedObj = evt.target.result; - Compatibility.importEncryptedWallet($rootScope.iden, encryptedObj, $scope.password, {}, + copay.Compatibility.importEncryptedWallet($rootScope.iden, encryptedObj, $scope.password, {}, function(err, wallet){ if (err) { notification.error('Error', 'Could not read wallet. Please check your password'); @@ -91,8 +93,13 @@ angular.module('copayApp.controllers').controller('ImportController', 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; notification.error('Error', 'Please, select your backup file'); @@ -104,11 +111,12 @@ angular.module('copayApp.controllers').controller('ImportController', reader.readAsBinaryString(backupFile); } else { - Compatibility.importEncryptedWallet($rootScope.iden, backupText, $scope.password, {}, + copay.Compatibility.importEncryptedWallet($rootScope.iden, backupText, $scope.password, {}, function(err, wallet){ if (err) { notification.error('Error', 'Could not read wallet. Please check your password'); } else { + copay.Compatibility.deleteOldWallet(backupOldWallet); controllerUtils.installWalletHandlers($scope, wallet); controllerUtils.setFocusedWallet(wallet); return; @@ -118,7 +126,7 @@ angular.module('copayApp.controllers').controller('ImportController', try { _importBackup(backupText); } catch(e) { - Compatibility.importEncryptedWallet(backupText, $scope.password, $scope.skipPublicKeyRing, $scope.skipTxProposals); + copay.Compatibility.importEncryptedWallet(backupText, $scope.password, $scope.skipPublicKeyRing, $scope.skipTxProposals); } } }; diff --git a/js/models/Compatibility.js b/js/models/Compatibility.js index c455d4dd0..0a136391b 100644 --- a/js/models/Compatibility.js +++ b/js/models/Compatibility.js @@ -20,6 +20,7 @@ Compatibility._getWalletIds = function(cb) { preconditions.checkArgument(cb); var walletIds = []; var uniq = {}; + var key; for (key in localStorage) { var split = key.split('::'); if (split.length == 2) { @@ -111,7 +112,9 @@ Compatibility.getWallets_Old = function(cb) { Compatibility.getWallets2 = function(cb) { var self = this; var re = /wallet::([^_]+)(_?(.*))/; + var va = /^{+/; + var key; var keys = []; for (key in localStorage) { keys.push(key); @@ -120,11 +123,15 @@ Compatibility.getWallets2 = function(cb) { if (key.indexOf('wallet::') !== 0) return null; var match = key.match(re); + var matchValue = localStorage[key].match(va); if (match.length != 4) return null; + if (matchValue) + return null; return { id: match[1], name: match[3] ? match[3] : undefined, + value: localStorage[key] }; })); @@ -186,7 +193,7 @@ Compatibility.readWalletPre8 = function(walletId, password, cb) { }; Compatibility.importEncryptedWallet = function(identity, cypherText, password, opts, cb) { - var crypto = opts.cryptoUtil || cryptoUtils; + var crypto = (opts && opts.cryptoUtil) || cryptoUtils; var key = crypto.kdf(password); var obj = crypto.decrypt(key, cypherText); if (!obj) { @@ -227,5 +234,10 @@ Compatibility.kdf = function(password) { return sbase64; }; +Compatibility.deleteOldWallet = function(walletObj) { + localStorage.removeItem('wallet::'+walletObj.id+'_'+walletObj.name); + log.info('Old wallet ' + walletObj.name + ' deleted: ' + walletObj.id); +}; + module.exports = Compatibility; diff --git a/js/models/Identity.js b/js/models/Identity.js index dfd7d2c30..d89ebe62e 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -490,20 +490,6 @@ Identity.prototype.addWallet = function(wallet, cb) { this.storage.setItem(wallet.getStorageKey(), wallet.toObj(), cb); }; -/** - * check if any profile exists on storage - * @param opts.storageOpts - * @param cb - */ -Identity.checkIfExistsAny = function(opts, cb) { - var storage = opts.storage || opts.pluginManager.get('DB'); - storage.getFirst(Identity.getStoragePrefix(), { - onlyKey: true - }, function(err, v, k) { - return cb(k ? true : false); - }); -}; - /** * @desc Checks if a version is compatible with the current version * @param {string} inVersion - a version, with major, minor, and revision, period-separated (x.y.z) diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 609698d0a..1910f066f 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -178,20 +178,6 @@ Wallet.prototype.getStorageKey = function() { return Wallet.getStorageKey(this.getId()); }; -/** - * check if any wallet exists on storage - * @param opts.storageOpts - * @param cb - */ -Wallet.checkIfExistsAny = function(opts, cb) { - var storage = opts.storage || opts.pluginManager.get('DB'); - storage.getFirst(Wallet.getStoragePrefix(), { - onlyKey: true - }, function(err, v, k) { - return cb(k ? true : false); - }); -}; - /* for stubbing */ Wallet._newInsight = function(opts) { return new Insight(opts); diff --git a/js/services/compatibility.js b/js/services/compatibility.js index 3eec17b51..904ccc501 100644 --- a/js/services/compatibility.js +++ b/js/services/compatibility.js @@ -1,5 +1,13 @@ 'use strict'; -angular.module('copayApp.services').factory('Compatibility', function() { - return require('copay').Compatibility; +angular.module('copayApp.services').factory('Compatibility', function($rootScope) { + var root = {}; + + root.check = function (scope) { + copay.Compatibility.listWalletsPre8(function(wallets) { + scope.anyWallet = wallets.length > 0 ? true : false; + scope.oldWallets = wallets; + }); + }; + return root; }); diff --git a/js/services/identityService.js b/js/services/identityService.js index 4b184a3ed..603986ac1 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -4,24 +4,6 @@ angular.module('copayApp.services') .factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) { var root = {}; - root.check = function (scope) { - copay.Identity.checkIfExistsAny({ - pluginManager: pluginManager, - }, function(anyProfile) { - copay.Wallet.checkIfExistsAny({ - pluginManager: pluginManager, - }, function(anyWallet) { - scope.retreiving = false; - scope.anyProfile = anyProfile ? true : false; - scope.anyWallet = anyWallet ? true : false; - - if (!scope.anyProfile) { - $location.path('/createProfile'); - } - }); - }); - }; - root.create = function(scope, form) { var iden = copay.Identity.create({ email: form.email.$modelValue, diff --git a/views/createProfile.html b/views/createProfile.html index d457d66b3..d0cfa2d42 100644 --- a/views/createProfile.html +++ b/views/createProfile.html @@ -8,16 +8,7 @@
Copay
-
-
-
- -
-
- Copay now needs a profile to access wallets. - You can import your current wallets after creating your frofile -
-
+

Create Profile

@@ -62,11 +53,7 @@