diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index e4e51c406..6a88af443 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -481,7 +481,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r }); }; - self.clientError = function(err) { if (isCordova) { navigator.notification.confirm( @@ -549,9 +548,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r c.startScan({ includeCopayerBranches: true, }, function(err) { - if (err) { - if (self.walletId == walletId) - self.setOngoingProcess('scanning', false); + if (err && self.walletId == walletId) { + self.setOngoingProcess('scanning', false); self.handleError(err); $rootScope.$apply(); } @@ -624,6 +622,22 @@ angular.module('copayApp.controllers').controller('indexController', function($r $rootScope.$on('Local/BWSUpdated', function(event) { profileService.applyConfig(); + storageService.setCleanAndScanAddresses(function() {}); + }); + + $rootScope.$on('Local/CleanAndScanAddresses', function(event) { + storageService.getCleanAndScanAddresses(function(err, val) { + if (val) { + $log.debug('Clear last address cache and Scan'); + var wallets = profileService.walletClients; + for (var walletId in wallets) { + storageService.clearLastAddress(walletId, function(err) { + self.startScan(walletId); + }); + } + storageService.removeCleanAndScanAddresses(function() {}); + } + }); }); $rootScope.$on('Local/WalletCompleted', function(event) { diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 6b8132e8e..d55516589 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -130,6 +130,7 @@ angular.module('copayApp.services') storageService.getFocusedWalletId(function(err, focusedWalletId) { if (err) return cb(err); root._setFocus(focusedWalletId, cb); + $rootScope.$emit('Local/CleanAndScanAddresses'); }); }); }; diff --git a/src/js/services/storageService.js b/src/js/services/storageService.js index f53bfd064..91b780ae3 100644 --- a/src/js/services/storageService.js +++ b/src/js/services/storageService.js @@ -151,6 +151,18 @@ angular.module('copayApp.services') storage.get('backup-' + walletId, cb); }; + root.setCleanAndScanAddresses = function(cb) { + storage.set('CleanAndScanAddresses', Date.now(), cb); + }; + + root.getCleanAndScanAddresses = function(cb) { + storage.get('CleanAndScanAddresses', cb); + }; + + root.removeCleanAndScanAddresses = function(cb) { + storage.remove('CleanAndScanAddresses', cb); + }; + root.getConfig = function(cb) { storage.get('config', cb); };