diff --git a/src/js/controllers/index.js b/src/js/controllers/index.js index 05f3e4077..4a735ec34 100644 --- a/src/js/controllers/index.js +++ b/src/js/controllers/index.js @@ -1427,6 +1427,19 @@ angular.module('copayApp.controllers').controller('indexController', function($r self.tab = 'walletHome'; }); + $rootScope.$on('Local/ValidatingWallet', function() { + if (isCordova) { + window.plugins.spinnerDialog.hide(); + window.plugins.spinnerDialog.show(null, gettext('Validating wallet integrity...'), true); + } + }); + + $rootScope.$on('Local/ProfileBound', function() { + if (isCordova) { + window.plugins.spinnerDialog.hide(); + } + }); + $rootScope.$on('Local/ClearHistory', function(event) { $log.debug('The wallet transaction history has been deleted'); self.txHistory = self.completeHistory = self.txHistorySearchResults = []; diff --git a/src/js/routes.js b/src/js/routes.js index 0da8607e8..a756e7f42 100644 --- a/src/js/routes.js +++ b/src/js/routes.js @@ -614,7 +614,6 @@ angular.module('copayApp').config(function(historicLogProvider, $provide, $logPr } else { if (profileService.focusedClient && !profileService.focusedClient.isComplete() && toState.walletShouldBeComplete) { - event.preventDefault(); $state.transitionTo('copayers'); } } diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 769cc1d1c..3f46cd2fe 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -123,9 +123,9 @@ angular.module('copayApp.services') // Used when reading wallets from the profile - root.bindWallet = function(credentials) { + root.bindWallet = function(credentials, cb) { if (!credentials.walletId) - throw 'bindWallet should receive credentials JSON'; + return cb('bindWallet should receive credentials JSON'); // Create the client @@ -136,16 +136,21 @@ angular.module('copayApp.services') }; var skipKeyValidation = root.profile.isChecked(platformInfo.ua, credentials.walletId); - $log.info('Binding wallet:' + credentials.walletId + ' Validating?:' + !skipKeyValidation); - var client = bwcService.getClient(JSON.stringify(credentials), { - bwsurl: getBWSURL(credentials.walletId), - skipKeyValidation: skipKeyValidation, - }); + if (!skipKeyValidation) { + $rootScope.$emit('Local/ValidatingWallet'); + } + $timeout(function() { + $log.info('Binding wallet:' + credentials.walletId + ' Validating?:' + !skipKeyValidation); + var client = bwcService.getClient(JSON.stringify(credentials), { + bwsurl: getBWSURL(credentials.walletId), + skipKeyValidation: skipKeyValidation, + }); - if (!skipKeyValidation && !client.incorrectDerivation) - root.profile.setChecked(platformInfo.ua, credentials.walletId); + if (!skipKeyValidation && !client.incorrectDerivation) + root.profile.setChecked(platformInfo.ua, credentials.walletId); - return root.bindWalletClient(client); + return cb(null, root.bindWalletClient(client)); + }, 1); }; root.bindProfile = function(profile, cb) { @@ -155,26 +160,42 @@ angular.module('copayApp.services') $log.debug('Preferences read'); if (err) return cb(err); - lodash.each(root.profile.credentials, function(credentials) { - root.bindWallet(credentials); - }); - $rootScope.$emit('Local/WalletListUpdated'); + function bindWallets(cb) { + var l = root.profile.credentials.length; + var i = 0, totalBound = 0; - storageService.getFocusedWalletId(function(err, focusedWalletId) { - if (err) return cb(err); - root._setFocus(focusedWalletId, function() { - if (usePushNotifications) - root.pushNotificationsInit(); - root.isDisclaimerAccepted(function(val) { - if (!val) { - return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); + lodash.each(root.profile.credentials, function(credentials) { + root.bindWallet(credentials, function(err, bound) { + i++; + totalBound += bound; + if (i == l) { + $log.info('Bound ' + totalBound + ' out of ' + l + ' wallets'); + if (totalBound) + $rootScope.$emit('Local/WalletListUpdated'); + return cb(); } + }); + }); + } + + bindWallets(function() { + storageService.getFocusedWalletId(function(err, focusedWalletId) { + if (err) return cb(err); + root._setFocus(focusedWalletId, function() { + if (usePushNotifications) + root.pushNotificationsInit(); root.isBound = true; $rootScope.$emit('Local/ProfileBound'); - return cb(); + + root.isDisclaimerAccepted(function(val) { + if (!val) { + return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer')); + } + return cb(); + }); }); - }); + }) }); }); }; @@ -348,8 +369,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) { @@ -709,7 +730,7 @@ angular.module('copayApp.services') return (w.n == n); }); } - + return lodash.sortBy(ret, 'name'); };