diff --git a/css/src/main.css b/css/src/main.css index 0e3574011..97d1e9dc4 100644 --- a/css/src/main.css +++ b/css/src/main.css @@ -180,8 +180,6 @@ a:hover { .open input, .join input, .setup input, -.import input, -.import textarea, .settings input { border-radius: 2px; background: #EDEDED; @@ -268,19 +266,6 @@ a:hover { color: #fff; } -.import fieldset, .settings fieldset { - border: 1px solid #3C5269; -} - -.import fieldset legend, .settings fieldset legend { - background: transparent; - color: #fff; - font-weight: normal; -} - -.import input[type="file"], -.import label, -.import label small, .settings label, .settings label small { color: #fff; diff --git a/js/controllers/import.js b/js/controllers/import.js index 49c4d9c58..717935593 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -1,8 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('ImportController', - function($scope, $rootScope, $location, identity, controllerUtils, Passphrase, notification, isMobile) { - controllerUtils.redirIfLogged(); + function($scope, $rootScope, $location, controllerUtils, Passphrase, notification, isMobile) { $scope.title = 'Import a backup'; $scope.importStatus = 'Importing wallet - Reading backup...'; @@ -17,38 +16,30 @@ angular.module('copayApp.controllers').controller('ImportController', } var _importBackup = function(encryptedObj) { - Passphrase.getBase64Async($scope.password, function(passphrase) { - updateStatus('Importing wallet - Setting things up...'); - var w, errMsg; + var password = $scope.password; + updateStatus('Importing wallet - Setting things up...'); + var skipFields = []; + if ($scope.skipPublicKeyRing) + skipFields.push('publicKeyRing'); - var skipFields = []; - if ($scope.skipPublicKeyRing) - skipFields.push('publicKeyRing'); - - if ($scope.skipTxProposals) - skipFields.push('txProposals'); - - // try to import encrypted wallet with passphrase - try { - w = identity.fromEncryptedObj(encryptedObj, passphrase, skipFields); - } catch (e) { - errMsg = e.message; - } + if ($scope.skipTxProposals) + skipFields.push('txProposals'); + $rootScope.iden.importWallet(encryptedObj, password, skipFields, function(err, w) { if (!w) { $scope.loading = false; - notification.error('Error', errMsg || 'Wrong password'); + notification.error('Error', err || 'Wrong password'); $rootScope.$digest(); return; } // if wallet was never used, we're done if (!w.isReady()) { - $rootScope.wallet = w; - controllerUtils.startNetwork($rootScope.wallet, $scope); + 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...'); @@ -56,11 +47,10 @@ angular.module('copayApp.controllers').controller('ImportController', $scope.loading = false; notification.error('Error', 'Error updating indexes: ' + err); } - $rootScope.wallet = w; - controllerUtils.startNetwork($rootScope.wallet, $scope); + controllerUtils.installWalletHandlers($scope, w); + controllerUtils.setFocusedWallet(w); }); - - }); + }); }; $scope.openFileDialog = function() { diff --git a/js/models/Identity.js b/js/models/Identity.js index 15e7953b7..73e27818a 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -60,8 +60,8 @@ Identity._newWallet = function(opts) { return new Wallet(opts); }; -Identity._walletFromObj = function(o, s, n, b, skip) { - return Wallet.fromObj(o, s, n, b, skip); +Identity._walletFromObj = function(o, readOpts) { + return Wallet.fromObj(o, readOpts); }; Identity._walletRead = function(id, r, cb) { @@ -299,6 +299,7 @@ Identity.prototype.close = function(cb) { * @return {Wallet} */ Identity.prototype.importWallet = function(base64, password, skipFields, cb) { + var self = this; preconditions.checkArgument(password); preconditions.checkArgument(cb); @@ -307,13 +308,22 @@ Identity.prototype.importWallet = function(base64, password, skipFields, cb) { var obj = this.storage.decrypt(base64); this.storage.restorePassphrase(); - if (!obj) return false; - var w = Identity._walletFromObj(obj, this.storage, this.networkOpts, this.blockchainOpts); - console.log('[Identity.js.307:Identity:]', w); //TODO + var readOpts = { + storage: this.storage, + networkOpts: this.networkOpts, + blockchainOpts: this.blockchainOpts, + skipFields: skipFields + }; + + if (!obj) return cb(null); + var w = Identity._walletFromObj(obj, readOpts); this._checkVersion(w.version); this.addWallet(w, function(err) { - if (err) return cb(err); - w.store(cb); + if (err) return cb(err, null); + self.openWallets.push(w); + self.store(null, function(err) { + return cb(err, w); + }); }); }; diff --git a/js/models/Storage.js b/js/models/Storage.js index 7714bb2fa..e0f771e85 100644 --- a/js/models/Storage.js +++ b/js/models/Storage.js @@ -98,6 +98,7 @@ Storage.prototype._decrypt = function(base64) { decryptedStr = decrypted.toString(CryptoJS.enc.Utf8); } catch (e) { // Error while decrypting + log.debug(e.message); return null; } return decryptedStr; diff --git a/js/services/passphrase.js b/js/services/passphrase.js index 00ff9e2be..3b8f3d86c 100644 --- a/js/services/passphrase.js +++ b/js/services/passphrase.js @@ -1,4 +1,4 @@ 'use strict'; angular.module('copayApp.services') - .value('Passphrase', new copay.Passphrase(config.passphrase)); + .value('Passphrase', new copay.Passphrase(config.passphraseConfig)); diff --git a/views/import.html b/views/import.html index 839950501..2ba4255e2 100644 --- a/views/import.html +++ b/views/import.html @@ -4,15 +4,10 @@ {{ importStatus|translate }} -
-
- Copay -
-
-
+
+
-
-

{{title|translate}}

+

{{title|translate}}

@@ -72,7 +67,6 @@
-