diff --git a/www/js/controllers/settings-controllers.js b/www/js/controllers/settings-controllers.js index 5d367b26d4bcc350e005d5c70f8e46888ce10f5a..245a393e5dc5e467328e9ba4fdae0ef46d1254ef 100644 --- a/www/js/controllers/settings-controllers.js +++ b/www/js/controllers/settings-controllers.js @@ -270,11 +270,8 @@ function SettingsController($scope, $q, $ionicHistory, $ionicPopup, $timeout, $t $timeout(function() { // Make sure to format helptip $scope.cleanupHelpTip(); - angular.merge(csSettings.data, $scope.formData); - // Manually removed some attributes - if (!$scope.formData.temporary) { - delete csSettings.data.node.temporary; - } + + csSettings.apply($scope.formData); csSettings.store(); $scope.saving = false; }, 100); diff --git a/www/js/directives.js b/www/js/directives.js index 297fc02d7b386f4da678a22cf785bd9e7b605871..2c9f1938e76a570073301986e7a492cdfa8f5232 100644 --- a/www/js/directives.js +++ b/www/js/directives.js @@ -409,15 +409,17 @@ angular.module('cesium.directives', []) // Un-authenticate when window closed // see: https://stackoverflow.com/questions/28197316/javascript-or-angularjs-defer-browser-close-or-tab-close-between-refresh - .directive('windowExitUnauth', function($window, csWallet) { + .directive('windowExitUnauth', function($window, csSettings, csWallet) { return { restrict: 'AE', link: function(element, attrs){ var myEvent = $window.attachEvent || $window.addEventListener, - chkevent = $window.attachEvent ? 'onunload' : 'unload'; /// make IE7, IE8 compatable + chkevent = $window.attachEvent ? 'onunload' : 'unload'; /// make IE7, IE8 compatible myEvent(chkevent, function (e) { // For >=IE7, Chrome, Firefox - return csWallet.unauth(); + if (csSettings.data && csSettings.data.keepAuthIdle != csSettings.constants.KEEP_AUTH_IDLE_SESSION) { + return csWallet.unauth(); + } }); } }; diff --git a/www/js/services/settings-services.js b/www/js/services/settings-services.js index 8c5f9298a10f8139ec97758535b5f645590dc60c..d6e9003508a9fd6f56f308d474fe6216fb902d8b 100644 --- a/www/js/services/settings-services.js +++ b/www/js/services/settings-services.js @@ -198,6 +198,9 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) // Apply stored settings angular.merge(data, newData); + // Delete temporary properties, if false + if (!data.node.temporary) delete data.node.temporary; + // Always force the usage of default settings // This is a workaround for DEV (TODO: implement edition in settings ?) data.timeWarningExpire = defaultSettings.timeWarningExpire; @@ -211,9 +214,8 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) data.userForumUrl = defaultSettings.userForumUrl; // Apply the new locale (only if need) - if (localeChanged) { - $translate.use(fixLocale(data.locale.id)); // will produce an event cached by onLocaleChange(); - } + // will produce an event cached by onLocaleChange(); + if (localeChanged) $translate.use(data.locale.id); }, @@ -321,6 +323,7 @@ angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) ready: ready, start: start, data: data, + apply: applyData, getByPath: getByPath, reset: reset, store: store, diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index 075420a8937089a7a9ef2d9e096c894c44455ba3..b5c237aa1e34d7cb0231b3615cbd61d919aa1a7d 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -312,7 +312,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se }, isAuth = function() { - return !!(data.pubkey && data.keypair && data.keypair.signSk); + return data.pubkey && data.keypair && data.keypair.signSk && true; }, getKeypair = function(options) { @@ -389,7 +389,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se var jobs = []; // Use session storage for secret key - fix #372 - if (settings.keepAuthIdle == constants.KEEP_AUTH_IDLE_SESSION && isAuth()) { + if (settings.keepAuthIdle == csSettings.constants.KEEP_AUTH_IDLE_SESSION && isAuth()) { jobs.push(sessionStorage.put(constants.STORAGE_SECKEY, CryptoUtils.base58.encode(data.keypair.signSk))); } else { @@ -580,8 +580,19 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se }) .then(function() { - // Successful restored: raise API event - if (isLogin()) { + // Successful restored: raise API events + if (isAuth()) { + return $q.all([ + api.data.raisePromise.login(data), + checkAuthIdle(true), + api.data.raisePromise.auth(data) + ]) + .catch(function(err) { + console.warn('Error during extension call [wallet.api.data.on.auth]', err); + // continue + }); + } + else if (isLogin()) { return api.data.raisePromise.login(data) .catch(function(err) { console.warn('Error during extension call [wallet.api.data.on.login]', err); @@ -2119,32 +2130,38 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se }); }, - checkAuthIdle = function(isAuthRes) { - isAuthRes = angular.isDefined(isAuthRes) ? isAuthRes : isAuth(); - var enable = isAuthRes && settings.keepAuthIdle > 0 && settings.keepAuthIdle != csSettings.constants.KEEP_AUTH_IDLE_SESSION; - var changed = (enableAuthIdle != enable); + checkAuthIdle = function(isAuthResult) { + isAuthResult = angular.isDefined(isAuthResult) ? isAuthResult : isAuth(); + const newEnableAuthIdle = isAuthResult && settings.keepAuthIdle > 0 && settings.keepAuthIdle != csSettings.constants.KEEP_AUTH_IDLE_SESSION; + const changed = (enableAuthIdle != newEnableAuthIdle); // need start/top watching if (changed) { // start idle - if (enable) { + if (newEnableAuthIdle) { console.debug("[wallet] Start idle (delay: {0}s)".format(settings.keepAuthIdle)); Idle.setIdle(settings.keepAuthIdle); Idle.watch(); } - // stop idle, if need + // stop idle, if was enable else if (enableAuthIdle){ console.debug("[wallet] Stop idle"); Idle.unwatch(); } - enableAuthIdle = enable; + enableAuthIdle = newEnableAuthIdle; } // if idle time changed: apply it - else if (enable && Idle.getIdle() !== settings.keepAuthIdle) { + else if (newEnableAuthIdle && Idle.getIdle() !== settings.keepAuthIdle) { console.debug("[idle] Updating auth idle (delay: {0}s)".format(settings.keepAuthIdle)); Idle.setIdle(settings.keepAuthIdle); } + + // Make sure to store seckey, in the session storage for secret key -fix #372 + const storeSecKey = isAuthResult && settings.keepAuthIdle == csSettings.constants.KEEP_AUTH_IDLE_SESSION && true; + if (storeSecKey) { + sessionStorage.put(constants.STORAGE_SECKEY, CryptoUtils.base58.encode(data.keypair.signSk)); + } }; function getWalletSettings(settings) {