From 8c18995ae0ff6cec3a35cbcf6942b44fc49d6a1c Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sat, 14 Nov 2015 17:29:45 -0300 Subject: [PATCH] refactor scan after importing a wallet --- src/js/controllers/create.js | 5 ----- src/js/controllers/index.js | 8 +++----- src/js/controllers/join.js | 5 ----- src/js/services/profileService.js | 27 ++++++++++++++++++++++----- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/js/controllers/create.js b/src/js/controllers/create.js index f873625ad..1433ccdb9 100644 --- a/src/js/controllers/create.js +++ b/src/js/controllers/create.js @@ -170,11 +170,6 @@ angular.module('copayApp.controllers').controller('createController', return; } - if (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey) { - if (opts.n == 1) { - $rootScope.$emit('Local/WalletImported', walletId); - } - } }); }, 100); } diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 194c2884c..46d7c2e42 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -923,9 +923,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r } profileService.setWalletClients(); - $timeout(function() { - $rootScope.$emit('Local/WalletImported', self.walletId); - }, 100); + self.startScan(self.walletId); }); }; @@ -1176,10 +1174,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.debouncedUpdate(); }); - $rootScope.$on('Local/BackupDone', function(event) { + $rootScope.$on('Local/BackupDone', function(event, walletId) { self.needsBackup = false; $log.debug('Backup done'); - storageService.setBackupFlag(self.walletId, function(err) { + storageService.setBackupFlag(walletId || self.walletId, function(err) { $log.debug('Backup done stored'); }); }); diff --git a/src/js/controllers/join.js b/src/js/controllers/join.js index 2c5227ecf..a0647c687 100644 --- a/src/js/controllers/join.js +++ b/src/js/controllers/join.js @@ -129,11 +129,6 @@ angular.module('copayApp.controllers').controller('joinController', return; } - $timeout(function() { - var fc = profileService.focusedClient; - if (fc.isComplete() && (opts.mnemonic || opts.externalSource || opts.extendedPrivateKey)) - $rootScope.$emit('Local/WalletImported', fc.credentials.walletId); - }, 2000); }); }, 100); }; diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index f159deeaf..3463318d8 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -276,8 +276,8 @@ angular.module('copayApp.services') // check if exist if (lodash.find(root.profile.credentials, { - 'walletId': walletData.walletId - })) { + 'walletId': walletData.walletId + })) { return cb(gettext('Cannot join the same wallet more that once')); } } catch (ex) { @@ -379,9 +379,26 @@ angular.module('copayApp.services') root.profile.credentials.push(JSON.parse(walletClient.export())); root.setWalletClients(); - root.setAndStoreFocus(walletId, function() { - storageService.storeProfile(root.profile, function(err) { - return cb(err, walletId); + + var handleImport = function(cb) { + var isImport = opts.mnemonic || opts.externalSource || opts.extendedPrivateKey; + + if (!isImport) + return cb(); + + $rootScope.$emit('Local/BackupDone', walletId); + + if (!walletClient.isComplete()) + return cb(); + + storageService.setCleanAndScanAddresses(walletId, cb); + }; + + handleImport(function() { + root.setAndStoreFocus(walletId, function() { + storageService.storeProfile(root.profile, function(err) { + return cb(err, walletId); + }); }); }); });