diff --git a/www/i18n/locale-en-GB.json b/www/i18n/locale-en-GB.json index 69087d7b6a84a43498222e19a522096967416d83..adc3ddfc00b88ddd03361be311a9e112a7038b8a 100644 --- a/www/i18n/locale-en-GB.json +++ b/www/i18n/locale-en-GB.json @@ -31,6 +31,7 @@ "BTN_ADD": "Add", "BTN_SEARCH": "Search", "BTN_REFRESH": "Refresh", + "BTN_RETRY": "Try again", "BTN_START": "Start", "BTN_CONTINUE": "Continue", "BTN_CREATE": "Create", @@ -672,7 +673,7 @@ "MEMBERSHIP_OUT": "This operation is <b>irreversible</b>.<br/></br/><b>Are you sure you want to terminate your membership?</b>", "MEMBERSHIP_OUT_2": "This operation is <b>irreversible</b>!<br/><br/>Are you sure you want to <b>terminate your membership</b>?", "LOGIN_UNUSED_WALLET_TITLE": "Typing error?", - "LOGIN_UNUSED_WALLET": "You are logged into an account that seems <b>inactive</b>.<br/><br/>If this account does not match yours, it's probably a <b>typing error</b> when sign in.<br/><br/><b>Would you still continue with this account?</b>", + "LOGIN_UNUSED_WALLET": "The account seems to be <b>inactive</b>.<br/><br/>It's probably a <b>typing error</b> when sign in. Please try again, checking that <b>public key is yours<b/>.", "FIX_IDENTITY": "The pseudonym <b>{{uid}}</b> will be published again, replacing the old publication that has expired.<br/></br/><b>Are you sure</b> you want to continue?", "FIX_MEMBERSHIP": "Your application for membership will be sent.<br/></br/><b>Are you sure?</b>", "RENEW_MEMBERSHIP": "Your membership will be renewed.<br/></br/><b>Are you sure?</b>", diff --git a/www/i18n/locale-en.json b/www/i18n/locale-en.json index 655497a53e4f389e3afba25ead5626ca525483d5..ffec30a4f462bbcea29d657f70222d2aa88769a4 100644 --- a/www/i18n/locale-en.json +++ b/www/i18n/locale-en.json @@ -31,6 +31,7 @@ "BTN_ADD": "Add", "BTN_SEARCH": "Search", "BTN_REFRESH": "Refresh", + "BTN_RETRY": "Retry", "BTN_START": "Start", "BTN_CONTINUE": "Continue", "BTN_CREATE": "Create", @@ -672,7 +673,7 @@ "MEMBERSHIP_OUT": "This operation is <b>irreversible</b>.<br/></br/><b>Are you sure you want to terminate your membership?</b>", "MEMBERSHIP_OUT_2": "This operation is <b>irreversible</b>!<br/><br/>Are you sure you want to <b>terminate your membership</b>?", "LOGIN_UNUSED_WALLET_TITLE": "Typing error?", - "LOGIN_UNUSED_WALLET": "You are logged into an account that seems <b>inactive</b>.<br/><br/>If this account does not match yours, it's probably a <b>typing error</b> when sign in.<br/><br/><b>Would you still continue with this account?</b>", + "LOGIN_UNUSED_WALLET": "The account seems to be <b>inactive</b>.<br/><br/>It's probably a <b>typing error</b> when sign in. Please try again, checking that <b>public key is yours<b/>.", "FIX_IDENTITY": "The pseudonym <b>{{uid}}</b> will be published again, replacing the old publication that has expired.<br/></br/><b>Are you sure</b> you want to continue?", "FIX_MEMBERSHIP": "Your application for membership will be sent.<br/></br/><b>Are you sure?</b>", "RENEW_MEMBERSHIP": "Your membership will be renewed.<br/></br/><b>Are you sure?</b>", diff --git a/www/i18n/locale-fr-FR.json b/www/i18n/locale-fr-FR.json index 3d6f6db29d679987c1299661a650f0874ffd4a0e..7ccee6f2356d570c134d3e0f081b95a8e3c1bb88 100644 --- a/www/i18n/locale-fr-FR.json +++ b/www/i18n/locale-fr-FR.json @@ -31,6 +31,7 @@ "BTN_ADD": "Ajouter", "BTN_SEARCH": "Rechercher", "BTN_REFRESH": "Actualiser", + "BTN_RETRY": "Recommencer", "BTN_START": "Commencer", "BTN_CONTINUE": "Continuer", "BTN_CREATE": "Créer", @@ -672,7 +673,7 @@ "MEMBERSHIP_OUT": "Cette opération est <b>irréversible</b>.<br/></br/>Etes-vous sûr de vouloir <b>résilier votre compte membre</b> ?", "MEMBERSHIP_OUT_2": "Cette opération est <b>irreversible</b> !<br/><br/>Etes-vous vraiment sûr de vouloir <b>résilier votre adhésion</b> comme membre ?", "LOGIN_UNUSED_WALLET_TITLE": "Erreur de saisie ?", - "LOGIN_UNUSED_WALLET": "Vous êtes connecté sur un compte qui parait <b>inactif</b>.<br/><br/>Si ce compte ne correspond pas au votre, il s'agit probablement d'une <b>erreur de saisie</b> de vos identifiants de connexion.<br/></br/><b>Voulez-vous néanmoins continuer avec ce compte ?</b>", + "LOGIN_UNUSED_WALLET": "Le compte connecté semble <b>inactif</b>.<br/><br/>Il s'agit probablement d'une <b>erreur de saisie</b> dans vos identifiants de connexion. Veuillez recommencer, en vérifiant que <b>la clé publique est celle de votre compte</b>.", "FIX_IDENTITY": "Le pseudonyme <b>{{uid}}</b> va être publiée à nouveau, en remplacement de l'ancienne publication qui a expirée.<br/></br/><b>Etes-vous sûr</b> de vouloir continuer ?", "FIX_MEMBERSHIP": "Votre demande d'adhésion comme membre va être renvoyée.<br/></br/><b>Etes-vous sûr</b> de vouloir continuer ?", "RENEW_MEMBERSHIP": "Votre adhésion comme membre va être renouvellée.<br/></br/><b>Etes-vous sûr</b> de vouloir continuer ?", diff --git a/www/js/app.js b/www/js/app.js index 09847dc07d7e446b97c8e04e2a91e405db674894..bcc256716449be2c3b46209c2d65d5d0b9c4ce43 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -141,62 +141,82 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht // removeIf(ios) // removeIf(firefoxos) // -- Automatic redirection to large state (if define) (keep this code for platforms web and ubuntu build) + var preventStateChange = false; // usefull to avoid duplicate login, when a first page with auth $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { - if (!event.defaultPrevented && next.data) { - var skip = $rootScope.tour || event.currentScope.tour; // disabled for help tour - if (skip) return; - var options; + if (event.defaultPrevented) return; - // Large screen: redirect to specific state - if (next.data.large && !UIUtils.screen.isSmall()) { - event.preventDefault(); - $state.go(next.data.large, nextParams); - } + var skip = !next.data || $rootScope.tour || event.currentScope.tour; // disabled for help tour + if (skip) return; - // If state need auth - else if (next.data.auth && !csWallet.isAuth()) { - event.preventDefault(); - options = next.data.minData ? {minData: true} : undefined; - return csWallet.auth(options) - .then(function() { - return $state.go(next.name, nextParams); - }) - .catch(function(err) { - // If cancel, redirect to home, if no current state - if (err == 'CANCELLED' && !$state.current.name) { - return $state.go('app.home'); - } - }); - } + if (preventStateChange) { + event.preventDefault(); + return; + } - // If state need login - else if (next.data.login && !csWallet.isLogin()) { + var options; + + // Large screen: redirect to specific state + if (next.data.large && !UIUtils.screen.isSmall()) { + event.preventDefault(); + $state.go(next.data.large, nextParams); + } + + // If state need auth + else if (next.data.auth && !csWallet.isAuth()) { + event.preventDefault(); + options = next.data.minData ? {minData: true} : undefined; + preventStateChange = true; + return csWallet.auth(options) + .then(function() { + preventStateChange = false; + return $state.go(next.name, nextParams); + }) + .catch(function(err) { + preventStateChange = false; + // If cancel, redirect to home, if no current state + if (err == 'CANCELLED' && !$state.current.name) { + return $state.go('app.home'); + } + }); + } + + // If state need login + else if (next.data.login && !csWallet.isLogin()) { + event.preventDefault(); + options = next.data.minData ? {minData: true} : undefined; + preventStateChange = true; + return csWallet.login(options) + .then(function() { + preventStateChange = false; + return $state.go(next.name, nextParams); + }) + .catch(function(err) { + preventStateChange = false; + // If cancel, redirect to home, if no current state + if (err == 'CANCELLED' && !$state.current.name) { + return $state.go('app.home'); + } + }); + } + + // If state need login or auth, make sure to load wallet data + else if (next.data.login || next.data.auth) { + options = next.data.minData ? {minData: true} : undefined; + if (!csWallet.isDataLoaded(options)) { event.preventDefault(); - options = next.data.minData ? {minData: true} : undefined; - return csWallet.login(options) + return csWallet.loadData(options) .then(function() { + preventStateChange = false; return $state.go(next.name, nextParams); - }) - .catch(function(err) { - // If cancel, redirect to home, if no current state - if (err == 'CANCELLED' && !$state.current.name) { - return $state.go('app.home'); - } }); } + } + }); - // If state need login or auth, make sure to load wallet data - else if (next.data.login || next.data.auth) { - options = next.data.minData ? {minData: true} : undefined; - if (!csWallet.isDataLoaded(options)) { - event.preventDefault(); - return csWallet.loadData(options) - .then(function() { - return $state.go(next.name, nextParams); - }); - } - } - + // Leave the current page, if auth was required to access it + csWallet.api.data.on.unauth($rootScope, function() { + if ($state.current && $state.current.data && $state.current.data.auth) { + $state.go('app.home'); } }); // endRemoveIf(firefoxos) @@ -247,8 +267,8 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht StatusBar.styleDefault(); } - // Make sure platform is ready - return csPlatform.ready(); + // Make sure platform is started + return csPlatform.start(); }); }) ; diff --git a/www/js/controllers/transfer-controllers.js b/www/js/controllers/transfer-controllers.js index fbeb2261dc11a1d63904f60b107d95a71f61d811..9c3c4fbca584721d2702672b37a43f26a92e3f7a 100644 --- a/www/js/controllers/transfer-controllers.js +++ b/www/js/controllers/transfer-controllers.js @@ -44,7 +44,7 @@ angular.module('cesium.transfer.controllers', ['cesium.services', 'cesium.curren .controller('TransferModalCtrl', TransferModalController) ; -function TransferController($scope, $controller, UIUtils, csWot) { +function TransferController($scope, $controller, UIUtils, csWot, csWallet) { 'ngInject'; // Initialize the super class and extend it. @@ -70,10 +70,9 @@ function TransferController($scope, $controller, UIUtils, csWot) { parameters.comment = state.stateParams.comment; } } - $scope.setParameters(parameters); // Make sure wallet is loaded - $scope.login({sources: true}) + csWallet.login({sources: true}) // If pubkey, get the uid (+ name, avatar) .then(function(data) { @@ -90,7 +89,7 @@ function TransferController($scope, $controller, UIUtils, csWot) { // Apply parameters, then recompute relative amount .then(function() { - + $scope.setParameters(parameters); $scope.onUseRelativeChanged(); UIUtils.loading.hide(); $scope.loading = false; @@ -159,10 +158,12 @@ function TransferModalController($scope, $q, $translate, $filter, BMA, csWallet, UIUtils.ink({selector: '.modal-transfer .ink'}); // Make to sure to load full wallet data (balance) - return csWallet.login({sources: true}) + return csWallet.login({sources: true, silent: true}) .then(function(data) { $scope.walletData = data; + $scope.onUseRelativeChanged(); $scope.loading = false; + UIUtils.ink({selector: '.modal-transfer .ink'}); }) .catch(function(err){ if (err == 'CANCELLED') return $scope.cancel(); // close the modal diff --git a/www/js/platform.js b/www/js/platform.js index 68956a18b2b24102b48fe5ea7b7a6c0e14e3d016..f126da8e19aa4ba53174731f4698b0e4820af195 100644 --- a/www/js/platform.js +++ b/www/js/platform.js @@ -10,12 +10,13 @@ angular.module('cesium.platform', ['cesium.config', 'cesium.services']) defaultSettingsNode, started = false, startPromise, + readyDeffered, listeners, removeChangeStateListener; function disableChangeState() { var remove = $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { - if (next.name !== 'app.home' && next.name !== 'app.settings') { + if (!event.defaultPrevented && next.name !== 'app.home' && next.name !== 'app.settings') { event.preventDefault(); if (startPromise) { startPromise.then(function() { @@ -86,7 +87,10 @@ angular.module('cesium.platform', ['cesium.config', 'cesium.services']) function ready() { if (started) return $q.when(); - return startPromise || start(); + if (startPromise) return startPromise; + if (readyDeffered) return readyDeffered.promise; + readyDeffered = $q.defer(); + return readyDeffered.promise; } function restart() { @@ -130,6 +134,8 @@ angular.module('cesium.platform', ['cesium.config', 'cesium.services']) addListeners(); startPromise = null; started = true; + if (readyDeffered) readyDeffered.resolve(); + readyDeffered = null; }) .catch(function(err) { startPromise = null; @@ -137,6 +143,8 @@ angular.module('cesium.platform', ['cesium.config', 'cesium.services']) if($state.current.name !== 'app.home') { $state.go('app.home', {error: 'peer'}); } + if (readyDeffered) readyDeffered.reject(err); + readyDeffered = null; throw err; }); @@ -158,11 +166,6 @@ angular.module('cesium.platform', ['cesium.config', 'cesium.services']) }, 500); } - // default action - start(); - - - return { isStarted: isStarted, ready: ready, diff --git a/www/js/services/utils-services.js b/www/js/services/utils-services.js index 3d157e4abab18e7e147f4e7e15d89d8d64d9754f..8fa58bbb9303f3b845f1b1c0be0ad41bf0187cef 100644 --- a/www/js/services/utils-services.js +++ b/www/js/services/utils-services.js @@ -437,7 +437,9 @@ angular.module('cesium.utils.services', []) } }) .then(function() { - popover.deferred.resolve(result); + if (popover.deferred) { + popover.deferred.resolve(result); + } delete popover.deferred; delete popover.options; }); diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index de44cd1966b6a96f295f5a1017a3c71b97cb1d4c..4b1d0481952eef08b18b38670ec1a0b4ed265a1d 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -110,10 +110,8 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // user already login if (!needLogin && !needAuth) { - // Load data - if (!data.loaded) { - var loadOptions = options && angular.isDefined(options.minData) ? {minData: true} : undefined; - return loadData(loadOptions); + if (!isDataLoaded(options)) { + return loadData(options); } return $q.when(data); } @@ -168,6 +166,14 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se } return keepAuth ? data : angular.merge({}, data, authData); + }) + .catch(function(err) { + if (err == 'RETRY') { + return $timeout(function(){ + return login(options); + }, 300); + } + throw err; }); }, @@ -572,7 +578,8 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se loadData = function(options) { var promise; - var alertIfUnusedWallet = !csCurrency.data.initPhase && (!csSettings.data.wallet || csSettings.data.wallet.alertIfUnusedWallet) && !data.loaded; + var alertIfUnusedWallet = !csCurrency.data.initPhase && (!csSettings.data.wallet || csSettings.data.wallet.alertIfUnusedWallet) && + !data.loaded && (!options || !options.minData); if (options && options.minData) { promise = loadMinData(options); } @@ -591,26 +598,31 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se var showAlert = alertIfUnusedWallet && !isNew() && isNeverUsed(); if (!showAlert) return true; return UIUtils.loading.hide() - .then(function(){ - return UIUtils.alert.confirm('CONFIRM.LOGIN_UNUSED_WALLET', 'CONFIRM.LOGIN_UNUSED_WALLET_TITLE',{ - okText: 'COMMON.BTN_CONTINUE' - }).then(function(confirm) { - if (confirm) return true; - return logout(); + .then(function() { + return UIUtils.alert.confirm('CONFIRM.LOGIN_UNUSED_WALLET', 'CONFIRM.LOGIN_UNUSED_WALLET_TITLE', { + cancelText: 'COMMON.BTN_CONTINUE', + okText: 'COMMON.BTN_RETRY' + }); + }) + .then(function(retry) { + if (retry) { + return logout().then(function() { + throw 'RETRY'; }); + } + return true; }); }) // Return wallet data - .then(function(res) { - if (res) { + .then(function(confirm) { + if (confirm) { return data; } else { // cancel throw 'CANCELLED'; } }); - }, loadFullData = function() { @@ -657,7 +669,11 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se if (!options.requirements) { return $q.when(data); } - return refreshData(options); + return refreshData(options) + .then(function(data) { + data.loaded = true; + return data; + }); }, refreshData = function(options) { @@ -1573,16 +1589,6 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // Restore .then(restore) -/* -// loading must be done by state definition - // Load data (if a wallet restored) - .then(function(data) { - if (data && data.pubkey) { - return loadData({minData: true}); - } - }) -*/ - // Emit ready event .then(function() { addListeners(); diff --git a/www/plugins/es/js/controllers/app-controllers.js b/www/plugins/es/js/controllers/app-controllers.js index 9d20838fc0eebe1ba0157172a10dc4a39a65a3b1..ba52ffc29d482e46efc0c99b38dbcd0246f01fcf 100644 --- a/www/plugins/es/js/controllers/app-controllers.js +++ b/www/plugins/es/js/controllers/app-controllers.js @@ -93,7 +93,7 @@ function ESMenuExtendController($scope, $state, PluginService, esSettings, UIUti $scope.showMessagesPopover = function(event) { // Make sure tobe auth before opening this popover if (!csWallet.isAuth()) { - return csWallet.auth().then(function(){ + return csWallet.auth({minData: true}).then(function(){ UIUtils.loading.hide(); return $scope.showMessagesPopover(event); // loop }); diff --git a/www/plugins/es/js/services/http-services.js b/www/plugins/es/js/services/http-services.js index bc23127a8754a5aefd91ca63e9067362065a9391..9756b492d65538f95b3d8113fcdb2f72bcf41e51 100644 --- a/www/plugins/es/js/services/http-services.js +++ b/www/plugins/es/js/services/http-services.js @@ -248,7 +248,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic function removeRecord(index, type, walletData) { return function(id) { - return (walletData ? csWallet.auth() : $q.when(walletData)) + return (!walletData ? csWallet.auth() : $q.when(walletData)) .then(function(walletData) { var obj = { diff --git a/www/plugins/es/js/services/message-services.js b/www/plugins/es/js/services/message-services.js index eabf40975f44979442362dcf7548ad93d51467af..6f3580469839a99d29931ed8f44bf364f5344e64 100644 --- a/www/plugins/es/js/services/message-services.js +++ b/www/plugins/es/js/services/message-services.js @@ -100,7 +100,6 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', csWot.extend(notification, 'issuer') .then(function() { - csWallet.data.messages = csWallet.data.messages || {}; csWallet.data.messages.unreadCount++; diff --git a/www/templates/wallet/transfer_form.html b/www/templates/wallet/transfer_form.html index 509d7d6340c58fbd939cf5c4fce8123a6025afda..01ac4890e1e1cba4b8b59a69943dc39408428840 100644 --- a/www/templates/wallet/transfer_form.html +++ b/www/templates/wallet/transfer_form.html @@ -24,7 +24,7 @@ <span class="item item-text-wrap"> <span class="gray" translate>TRANSFER.FROM</span> - <span class="badge animate-fade-in animate-show-hide ng-hide" ng-show="!$root.loading && !loading" + <span class="badge animate-fade-in animate-show-hide ng-hide" ng-show="!loading" ng-class="{'badge-assertive': (convertedBalance <= 0 || (formData.amount && convertedBalance < formData.amount)), 'badge-balanced': (convertedBalance > 0 && (!formData.amount || convertedBalance >= formData.amount)) }"> <ion-spinner icon="android" ng-if="!walletData.pubkey"></ion-spinner> <span ng-if="walletData.pubkey && !walletData.isMember"> @@ -35,6 +35,7 @@ </span> <span ng-bind-html="walletData.balance|formatAmount:{useRelative: formData.useRelative, currency:currency}"></span> </span> + </span> <!-- Amount -->