From 49205a76a073681b01b9da8fff0c21f87282ed04 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 30 Nov 2014 04:42:39 -0300 Subject: [PATCH] fix import / logs --- js/controllers/importProfile.js | 22 +++----------- js/models/Identity.js | 54 +++++++++++---------------------- js/models/Insight.js | 3 +- js/models/PublicKeyRing.js | 3 -- js/models/Wallet.js | 2 +- js/services/identityService.js | 4 +-- 6 files changed, 27 insertions(+), 61 deletions(-) diff --git a/js/controllers/importProfile.js b/js/controllers/importProfile.js index 1c36c934a..c83013104 100644 --- a/js/controllers/importProfile.js +++ b/js/controllers/importProfile.js @@ -18,18 +18,10 @@ angular.module('copayApp.controllers').controller('ImportProfileController', var password = $scope.password; updateStatus('Importing profile - Setting things up...'); - identityService.importProfile(str,password, function(err){ - }) - copay.Identity.importFromEncryptedFullJson(str, password, { - pluginManager: pluginManager, - network: config.network, - networkName: config.networkName, - walletDefaults: config.wallet, - passphraseConfig: config.passphraseConfig, - }, function(err, iden) { + identityService.importProfile(str,password, function(err, iden) { + $scope.loading = false; if (err) { - $scope.loading = false; - + copay.logger.warn(err); if ((err.toString() || '').match('BADSTR')) { $scope.error = 'Bad password or corrupt profile file'; } else if ((err.toString() || '').match('EEXISTS')) { @@ -37,12 +29,8 @@ angular.module('copayApp.controllers').controller('ImportProfileController', } else { $scope.error = 'Unknown error'; } - $scope.$digest(); - - } else { - var firstWallet = iden.getLastFocusedWallet(); - root.bind($scope, iden, firstWallet); - } + $rootScope.$digest(); + } }); }; diff --git a/js/models/Identity.js b/js/models/Identity.js index 1b8ff7632..23329ca77 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -108,7 +108,7 @@ Identity.create = function(opts, cb) { * * After opening a profile, and setting its wallet event handlers, * the client must run .netStart on each - * wallet (or call Identity.netStart()) + * (probably on iden's newWallet handler * * @param {Object} opts * @param {Object} opts.storage @@ -322,7 +322,6 @@ Identity.prototype.close = function() { }; -// TODO: Add feedback function Identity.prototype.importWalletFromObj = function(obj, opts, cb) { var self = this; preconditions.checkArgument(cb); @@ -336,28 +335,30 @@ Identity.prototype.importWalletFromObj = function(obj, opts, cb) { var w = importFunction(obj, readOpts); if (!w) return cb(new Error('Could not decrypt')); - log.debug('Wallet decryped:' + w.getName()); + log.debug('Wallet decrypted:' + w.getName()); self._checkVersion(w.version); log.debug('Updating Indexes for wallet:' + w.getName()); w.updateIndexes(function(err) { log.debug('Adding wallet to profile:' + w.getName()); self.bindWallet(w); - self.updateFocusedTimestamp(w.getId()); - - var writeOpts = _.extend({ - noWallets: true - }, opts); - - self.storeWallet(w, function(err) { - if (err) return cb(err); - self.store(writeOpts, function(err) { - return cb(err, w); - }); - }); + self.storeWallet(w, cb); }); }; + +Identity.prototype.importMultipleWalletsFromObj = function(objs, opts) { + var self = this; + opts = opts || {}; + + async.eachSeries(objs, function(walletData, cb) { + if (!walletData) + return cb(); + self.importWalletFromObj(walletData, opts, cb); + }); +}; + + /** * @param {Wallet} wallet * @param {Function} cb @@ -414,30 +415,11 @@ Identity.importFromFullJson = function(str, password, opts, cb) { iden.store(opts, function(err) { if (err) return cb(err); //profile already exists - opts.failIfExists = false; - async.map(json.wallets, function(walletData, cb) { - - if (!walletData) - return cb(); - - iden.importWalletFromObj(walletData, opts, function(err, w) { - if (err) return cb(err); - log.debug('Wallet ' + w.getId() + ' imported'); - cb(); - }); - }, function(err, results) { - if (err) return cb(err); - - iden.store(opts, function(err) { - return cb(err, iden); - }); - }); - + return cb(null, iden, json.wallets); }); - - }; + /** * @desc binds a wallet's events and emits 'newWallet' * @param {string} walletId Wallet id to be binded diff --git a/js/models/Insight.js b/js/models/Insight.js index c62e7777e..e1cde179a 100644 --- a/js/models/Insight.js +++ b/js/models/Insight.js @@ -220,8 +220,7 @@ Insight.prototype.subscribe = function(addresses) { if (!self.subscribed[address]) { var handler = handlerFor(self, address); self.subscribed[address] = handler; - log.debug('Subscribe to: ', address); - +// log.debug('Subscribe to: ', address); s.emit('subscribe', address); s.on(address, handler); } diff --git a/js/models/PublicKeyRing.js b/js/models/PublicKeyRing.js index b4ee1529f..6963e8bab 100644 --- a/js/models/PublicKeyRing.js +++ b/js/models/PublicKeyRing.js @@ -497,8 +497,6 @@ PublicKeyRing.prototype.getCosigner = function(pubKey) { PublicKeyRing.prototype.buildAddressCache = function() { var ret = []; var self = this; - - log.info('Rebuilding Address Cache...this will take a while'); _.each(this.indexes, function(index) { for (var i = 0; i < index.receiveIndex; i++) { self._getAddress(i, false, index.copayerIndex); @@ -507,7 +505,6 @@ PublicKeyRing.prototype.buildAddressCache = function() { self._getAddress(i, true, index.copayerIndex); } }); - log.info('...done!'); }; diff --git a/js/models/Wallet.js b/js/models/Wallet.js index 395f00639..e2382ef10 100644 --- a/js/models/Wallet.js +++ b/js/models/Wallet.js @@ -1986,7 +1986,7 @@ Wallet.prototype.subscribeToAddresses = function() { var addresses = this.getAddresses(); this.blockchain.subscribe(addresses); - log.debug('Subscribed to ' + addresses.length + ' addresses'); + log.debug('Wallet:' + this.getName() + ' Subscribed to:' + addresses.length + ' addresses'); }; /** diff --git a/js/services/identityService.js b/js/services/identityService.js index 4a0096e7f..f5cc5c84c 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -310,10 +310,10 @@ angular.module('copayApp.services') networkName: config.networkName, walletDefaults: config.wallet, passphraseConfig: config.passphraseConfig, - }, function(err, iden) { + }, function(err, iden, walletObjs) { if (err) return cb(err); root.bind(iden); - iden.openWallets(); + iden.importMultipleWalletsFromObj(walletObjs); return cb(); }); };