diff --git a/www/js/controllers/wallets-controllers.js b/www/js/controllers/wallets-controllers.js index 6d93dc140b4ddb0e210837a3c78f30ccb7e1a7d5..61dcd44f506d0a85500879aa2adb808e0868037e 100644 --- a/www/js/controllers/wallets-controllers.js +++ b/www/js/controllers/wallets-controllers.js @@ -96,7 +96,7 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl return $scope.load() .then(function() { UIUtils.loading.hide(); - if (!$scope.wallets) return; // user cancel + if (!$scope.wallets) return; // user cancel, or error $scope.addListeners(); $scope.showFab('fab-add-wallet'); }); @@ -489,33 +489,52 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl }, api: true }; + var hasLoadError = false; + var loadCounter = 0; + var now = Date.now(); return $q.all(jobs) // Load wallet data (apply a timeout between each wallet) .then(function() { - var counter = 0; - return $q.all( - $scope.wallets.reduce(function(res, wallet){ - return wallet.isDataLoaded(options) ? - res : res.concat( - $timeout(function(){ - return wallet.loadData(options); - }, loadWalletWaitTime * counter++)); - }, []) - ); + console.debug("[wallets] Loading {0} wallets in {1}ms".format(loadCounter, Date.now() - now)); + return $scope.wallets.reduce(function(res, wallet) { + var loaded = wallet.isDataLoaded(options); + if (loaded) { + console.debug("[wallets] Wallet #{0} already loaded. Skipping".format(wallet.id), options); + return res; + } + loadCounter++; + return res.then(function() { + return $timeout(function() { + return wallet.loadData(options) + .catch(function(err) { + console.error("[wallets] Error while loading data of wallet #{0}".format(wallet.id), err); + hasLoadError = true; + }); + }, loadWalletWaitTime); + }); + }, $q.when()); }) .then(function() { + if (hasLoadError) { + return UIUtils.alert.error('ERROR.LOAD_WALLET_LIST_FAILED') + .then(function() { + $scope.resetData(); + $scope.cancel(); + }); + } + if (loadCounter) { + console.debug("[wallets] Loaded data of {0} wallet(s) in {1}ms".format(loadCounter, (Date.now() - now))); + } $scope.loading = false; UIUtils.loading.hide(); $scope.updateView(); }) .catch(function(err) { + $scope.resetData(); if (err && err === 'CANCELLED') { - $scope.loading = true; $scope.cancel(); throw err; } - $scope.wallets = []; - $scope.loading = false; UIUtils.onError('ERROR.LOAD_WALLET_LIST_FAILED')(err); }); }; @@ -536,7 +555,7 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl }; $scope.updateView = function() { - if (!$scope.wallets.length) return; + if (!$scope.wallets || !$scope.wallets.length) return; if ($scope.motion) { $scope.motion.show({selector: '.list .item.item-wallet', ink: true}); @@ -604,7 +623,7 @@ function PopoverWalletSelectModalController($scope, $controller, UIUtils) { }); $scope.updateView = function() { - if (!$scope.wallets.length) return; + if (!$scope.wallets || !$scope.wallets.length) return; UIUtils.ink({selector: '.popover-wallets .list .item'}); }; diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index 4b4cccc06dc0be76a310b3b55e8bdd147809c330..01885a9bd9dc6f9bbc7fd6ae0c27b3ca0ff7770b 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -341,12 +341,12 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se isDataLoaded = function(options) { if (options) { - if (options.minData) return data.loaded; + if (options.minData && !options.sources) return data.loaded; if (options.requirements && !data.requirements) return false; if (options.tx && options.tx.enable && (!data.tx.fromTime || data.tx.fromTime == 'pending')) return false; if (options.sigStock && !data.sigStock) return false; } - return data.loaded && data.sources; + return data.loaded && data.sources && true; }, isNeverUsed = function() { @@ -391,7 +391,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // Use session storage for secret key - fix #372 if (settings.keepAuthIdle == csSettings.constants.KEEP_AUTH_IDLE_SESSION && isAuth()) { - jobs.push(sessionStorage.put(constants.STORAGE_SECKEY, CryptoUtils.base58.encode(data.keypair.signSk))); + jobs.push(sessionStorage.put(constants.STORAGE_SECKEY, CryptoUtils.util.encode_base58(data.keypair.signSk))); } else { jobs.push(sessionStorage.put(constants.STORAGE_SECKEY, null)); @@ -1064,7 +1064,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se var sources = []; var minBase = filterBase; var maxBase = filterBase; - _.find(data.sources, function(source) { + _.find(data.sources || [], function(source) { if (!source.consumed && source.base == filterBase){ sourcesAmount += powBase(source.amount, source.base); sources.push(source); @@ -2161,7 +2161,11 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // Make sure to store seckey, in the session storage for secret key -fix #372 var storeSecKey = isAuthResult && settings.keepAuthIdle == csSettings.constants.KEEP_AUTH_IDLE_SESSION && true; if (storeSecKey) { - sessionStorage.put(constants.STORAGE_SECKEY, CryptoUtils.base58.encode(data.keypair.signSk)); + sessionStorage.put(constants.STORAGE_SECKEY, CryptoUtils.util.encode_base58(data.keypair.signSk)); + } + // Make sure to clean previous seckey, if exists in session storage + else if (changed) { + sessionStorage.put(constants.STORAGE_SECKEY, null); } };