diff --git a/www/i18n/locale-en-GB.json b/www/i18n/locale-en-GB.json index f4a7da74cd12da0b8ce36eb0a356e5f9dcbb33a5..ba0f96abbd7c4508a16d60dbf72d1fbb6b985f04 100644 --- a/www/i18n/locale-en-GB.json +++ b/www/i18n/locale-en-GB.json @@ -109,7 +109,6 @@ "MESSAGE_SHORT": "Watch your <a href=\"http://duniter.org\" target=\"_blank\">Duniter</a> wallets<br/>in real time!", "BTN_REGISTRY": "Registry", "BTN_MARKET": "Market place", - "BTN_CURRENCIES": "Explore currencies", "BTN_CURRENCY": "Explore currency", "BTN_ABOUT": "about", "BTN_HELP": "Help", @@ -121,6 +120,7 @@ "TITLE": "Settings", "NETWORK_SETTINGS": "Network", "PEER": "Duniter peer address", + "PEER_CHANGED_TEMPORARY": "Address used temporarily", "USE_LOCAL_STORAGE": "Enable local storage", "USE_LOCAL_STORAGE_HELP": "Allows you to save your settings", "ENABLE_HELPTIP": "Enable contextual help tips", @@ -521,7 +521,6 @@ "SEND_MEMBERSHIP_OUT_FAILED": "Error while sending membership revocation.", "REFRESH_WALLET_DATA": "Could not refresh wallet.", "GET_CURRENCY_PARAMETER": "Could not get currency parameters.", - "GET_CURRENCIES_FAILED": "Unable to load currencies. Please retry later.", "GET_CURRENCY_FAILED": "Could not load currency. Please retry later.", "SEND_TX_FAILED": "Could not send transaction.", "ALL_SOURCES_USED": "Please wait the next block computation (All transaction sources has been used).", @@ -570,7 +569,8 @@ "ONLY_TEXT_FILE": "You have to select a text file", "EXISTING_ACCOUNT": "Your identifiers correspond to an already existing account, whose <a ng-click=\"showHelpModal('pubkey')\">public key</a> is:", "EXISTING_ACCOUNT_REQUEST": "Please modify your credentials so that they correspond to an unused account.", - "GET_LICENSE_FILE_FAILED": "Unable to get license file" + "GET_LICENSE_FILE_FAILED": "Unable to get license file", + "CHECK_NETWORK_CONNECTION": "No peer appears to be accessible.<br/><br/>Please <b>check your Internet connection</b>." }, "INFO": { "POPUP_TITLE": "Information", @@ -604,7 +604,8 @@ "NOT_NEED_RENEW_MEMBERSHIP": "Your membership does not need to be renewed (it will only expire in {{membershipExpiresIn|formatDuration}}).<br/></br/><b>Are you sure you</b> want to renew your membership?", "SAVE_BEFORE_LEAVE": "Do you want to <b>save your changes</b> before leaving the page?", "SAVE_BEFORE_LEAVE_TITLE": "Changes not saved", - "LOGOUT": "Are you sure you want to logout?" + "LOGOUT": "Are you sure you want to logout?", + "USE_FALLBACK_NODE": "Peer <b>{{old}}</b> unreachable or invalid address.<br/><br/>Do you want to temporarily use the <b>{{new}}</b> node?" }, "DOWNLOAD": { "POPUP_TITLE": "<b>Revocation file</b>", diff --git a/www/i18n/locale-en.json b/www/i18n/locale-en.json index 979d581f5c724b9e2f6d0d8bc1c4e26aa21690fe..2e49643902102d4f5258fb5db65d4eb37176a4a9 100644 --- a/www/i18n/locale-en.json +++ b/www/i18n/locale-en.json @@ -109,7 +109,6 @@ "MESSAGE_SHORT": "Watch your <a href=\"http://duniter.org\" target=\"_blank\">Duniter</a> wallets<br/>in real time!", "BTN_REGISTRY": "Registry", "BTN_MARKET": "Market place", - "BTN_CURRENCIES": "Explore currencies", "BTN_CURRENCY": "Explore currency", "BTN_ABOUT": "about", "BTN_HELP": "Help", @@ -121,6 +120,7 @@ "TITLE": "Settings", "NETWORK_SETTINGS": "Network", "PEER": "Duniter peer address", + "PEER_CHANGED_TEMPORARY": "Address used temporarily", "USE_LOCAL_STORAGE": "Enable local storage", "USE_LOCAL_STORAGE_HELP": "Allows you to save your settings", "ENABLE_HELPTIP": "Enable contextual help tips", @@ -521,7 +521,6 @@ "SEND_MEMBERSHIP_OUT_FAILED": "Error while sending membership revocation.", "REFRESH_WALLET_DATA": "Could not refresh wallet.", "GET_CURRENCY_PARAMETER": "Could not get currency parameters.", - "GET_CURRENCIES_FAILED": "Unable to load currencies. Please retry later.", "GET_CURRENCY_FAILED": "Could not load currency. Please retry later.", "SEND_TX_FAILED": "Could not send transaction.", "ALL_SOURCES_USED": "Please wait the next block computation (All transaction sources has been used).", @@ -570,7 +569,8 @@ "ONLY_TEXT_FILE": "You have to select a text file", "EXISTING_ACCOUNT": "Your identifiers correspond to an already existing account, whose <a ng-click=\"showHelpModal('pubkey')\">public key</a> is:", "EXISTING_ACCOUNT_REQUEST": "Please modify your credentials so that they correspond to an unused account.", - "GET_LICENSE_FILE_FAILED": "Unable to get license file" + "GET_LICENSE_FILE_FAILED": "Unable to get license file", + "CHECK_NETWORK_CONNECTION": "No peer appears to be accessible.<br/><br/>Please <b>check your Internet connection</b>." }, "INFO": { "POPUP_TITLE": "Information", @@ -604,7 +604,8 @@ "NOT_NEED_RENEW_MEMBERSHIP": "Your membership does not need to be renewed (it will only expire in {{membershipExpiresIn|formatDuration}}).<br/></br/><b>Are you sure you</b> want to renew your membership?", "SAVE_BEFORE_LEAVE": "Do you want to <b>save your changes</b> before leaving the page?", "SAVE_BEFORE_LEAVE_TITLE": "Changes not saved", - "LOGOUT": "Are you sure you want to logout?" + "LOGOUT": "Are you sure you want to logout?", + "USE_FALLBACK_NODE": "Peer <b>{{old}}</b> unreachable or invalid address.<br/><br/>Do you want to temporarily use the <b>{{new}}</b> node?" }, "DOWNLOAD": { "POPUP_TITLE": "<b>Revocation file</b>", diff --git a/www/i18n/locale-es-ES.json b/www/i18n/locale-es-ES.json index 29f30038ca200b50733242faae067282c2e10868..0ed58a86f99076394bf6f8e2918312506ec2b73c 100644 --- a/www/i18n/locale-es-ES.json +++ b/www/i18n/locale-es-ES.json @@ -120,6 +120,7 @@ "TITLE": "Configuraciónes", "NETWORK_SETTINGS": "Red", "PEER": "Dirección del nodo Duniter", + "PEER_CHANGED_TEMPORARY": "Dirección utiliza temporalmente", "USE_LOCAL_STORAGE": "Activar el almacenamiento local", "USE_LOCAL_STORAGE_HELP": "Permitir el ahorro de almacenamiento local", "ENABLE_HELPTIP": "Activar bocadillos contextuales de ayuda", @@ -520,7 +521,6 @@ "SEND_MEMBERSHIP_OUT_FAILED": "Fracaso en la interrupción de adhesión.", "REFRESH_WALLET_DATA": "Fracaso en la actualización del monedero.", "GET_CURRENCY_PARAMETER": "Fracaso en la recuperación de las reglas de moneda.", - "GET_CURRENCIES_FAILED": "Imposible de cargar la lista de las monedas. For favor, reintenta más tarde.", "GET_CURRENCY_FAILED": "Carga de la moneda imposible. Por favor, intenta más tarde.", "SEND_TX_FAILED": "Fracaso en la transferencia.", "ALL_SOURCES_USED": "Por favor, espera el cálculo del bloque siguiente (Todas sus fuentes de moneda fueron utilizada).", @@ -569,7 +569,8 @@ "ONLY_TEXT_FILE": "Debe seleccionar un fichero texto", "EXISTING_ACCOUNT": "Su contraseña corresponde a una cuenta existente, la <a ng-click=\"showHelpModal('pubkey')\">clave pública</a> es:", "EXISTING_ACCOUNT_REQUEST": "Por favor, cambie su contraseña para que coincida con una cuenta sin usar.", - "GET_LICENSE_FILE_FAILED": "Obtener el archivo de licencia no puede" + "GET_LICENSE_FILE_FAILED": "Obtener el archivo de licencia no puede", + "CHECK_NETWORK_CONNECTION": "Sin nodo parece alcanzable.<br/><br/><b>Comprobar la conexión a Internet</b>." }, "INFO": { "POPUP_TITLE": "Información", @@ -603,7 +604,8 @@ "NOT_NEED_RENEW_MEMBERSHIP": "Su adhesión no necesita estar renovada (solo va a caducar en {{membershipExpiresIn|formatDuration}}).<br/></br/><b>Está usted seguro</b> querer renovar su adhesión ?", "SAVE_BEFORE_LEAVE": "Quiere usted <b>guardar sus modificaciónes</b> antes dejar la página ?", "SAVE_BEFORE_LEAVE_TITLE": "Modificaciónes no registradas", - "LOGOUT": "Está usted seguro querer desconectarse ?" + "LOGOUT": "Está usted seguro querer desconectarse ?", + "USE_FALLBACK_NODE": "Nodo <b>{{edad}}</ b> dirección inalcanzable o no válido.<br/><br/>Se desea utilizar temporalmente el nodo <b>{{nuevo}}</b> ?" }, "DOWNLOAD": { "POPUP_TITLE": "<b>Revocación del archivo</b>", diff --git a/www/i18n/locale-fr-FR.json b/www/i18n/locale-fr-FR.json index fddd366963a6c95c7641058bb7fcf9165f2553b9..df8c3ce8bc38ad9760e4f03b2fbc7e0e2a5ec3e5 100644 --- a/www/i18n/locale-fr-FR.json +++ b/www/i18n/locale-fr-FR.json @@ -120,6 +120,7 @@ "TITLE": "Paramètres", "NETWORK_SETTINGS": "Réseau", "PEER": "Adresse du nœud Duniter", + "PEER_CHANGED_TEMPORARY": "Adresse utilisée temporairement", "USE_LOCAL_STORAGE": "Activer le stockage local", "USE_LOCAL_STORAGE_HELP": "Permet de sauvegarder vos paramètres", "ENABLE_HELPTIP": "Activer les bulles d'aide contextuelles", @@ -520,7 +521,6 @@ "SEND_MEMBERSHIP_OUT_FAILED": "Echec de l'arret de l'adhésion.", "REFRESH_WALLET_DATA": "Echec du rafraichissement du portefeuille.", "GET_CURRENCY_PARAMETER": "Echec de la récupération des règles de la monnaie.", - "GET_CURRENCIES_FAILED": "Impossible de charger la liste des monnaies. Veuillez ressayer plus tard.", "GET_CURRENCY_FAILED": "Chargement de la monnaie impossible. Veuillez ressayer plus tard.", "SEND_TX_FAILED": "Echec du virement.", "ALL_SOURCES_USED": "Veuillez attendre le calcul du prochain bloc (Toutes vos sources de monnaie ont été utilisées).", @@ -569,7 +569,8 @@ "ONLY_TEXT_FILE": "Vous devez selectionner un fichier texte", "EXISTING_ACCOUNT": "Vos identifiants correspondent à un compte déjà existant, dont la <a ng-click=\"showHelpModal('pubkey')\">clef publique</a> est :", "EXISTING_ACCOUNT_REQUEST": "Veuillez modifier vos identifiants afin qu'ils correspondent à un compte non utilisé.", - "GET_LICENSE_FILE_FAILED": "Récupérer du fichier de license impossible" + "GET_LICENSE_FILE_FAILED": "Récupérer du fichier de license impossible", + "CHECK_NETWORK_CONNECTION": "Aucun nœud ne semble accessible.<br/><br/>Veuillez <b>vérifier votre connection Internet</b>." }, "INFO": { "POPUP_TITLE": "Information", @@ -603,7 +604,8 @@ "NOT_NEED_RENEW_MEMBERSHIP": "Votre adhésion n'a pas besoin d'être renouvellée (elle n'expirera que dans {{membershipExpiresIn|formatDuration}}).<br/></br/><b>Etes-vous sûr</b> de vouloir renouveler votre adhésion ?", "SAVE_BEFORE_LEAVE": "Voulez-vous <b>sauvegarder vos modifications</b> avant de quitter la page ?", "SAVE_BEFORE_LEAVE_TITLE": "Modifications non enregistrées", - "LOGOUT": "Etes-vous de vouloir vous déconnecter ?" + "LOGOUT": "Etes-vous de vouloir vous déconnecter ?", + "USE_FALLBACK_NODE": "Nœud <b>{{old}}</b> injoignable ou adresse invalide.<br/><br/>Voulez-vous temporairement utiliser le nœud <b>{{new}}</b> ?" }, "DOWNLOAD": { "POPUP_TITLE": "<b>Fichier de révocation</b>", diff --git a/www/index.html b/www/index.html index 503ff4adae795371ab162841f28eda1aa6e04a2c..2ceb65ec00f018db08a9f252e60c21590b7ec9de 100644 --- a/www/index.html +++ b/www/index.html @@ -94,6 +94,9 @@ <script src="dist/dist_js/app/services/plugin-services.js"></script> <script src="dist/dist_js/app/services.js"></script> + <script src="dist/dist_js/app/platform.js"></script> + <script src="dist/dist_js/app/filters.js"></script> + <!-- entities --> <script src="dist/dist_js/app/entities/peer.js"></script> <script src="dist/dist_js/app/entities/block.js"></script> diff --git a/www/js/app.js b/www/js/app.js index 253c6e44586cee5d8514be26621861186028cb2f..15bcf40a736793226b1efdbbd1e923415bd32560 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -5,306 +5,16 @@ // the 2nd parameter is an array of 'requires' // 'starter.controllers' is found in controllers.js angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht.translate', - 'ngApi', 'angular-cache', 'angular.screenmatch', 'angular.bind.notifier','ImageCropper', 'ngFileSaver', + 'ngApi', 'angular-cache', 'angular.screenmatch', 'angular.bind.notifier', 'ImageCropper', 'ngFileSaver', // removeIf(no-device) 'ngCordova', // endRemoveIf(no-device) // removeIf(no-plugin) 'cesium.plugins', // endRemoveIf(no-plugin) - 'cesium.controllers', 'cesium.templates', 'cesium.translations' + 'cesium.filters', 'cesium.config', 'cesium.platform', 'cesium.controllers', 'cesium.templates', 'cesium.translations' ]) - .filter('formatInteger', function() { - return function(input) { - return !input ? '0' : (input < 10000000 ? numeral(input).format('0,0') : numeral(input).format('0,0.000 a')); - }; - }) - - .filter('formatAmount', function(csConfig, csSettings, csWallet, $filter) { - var minValue = 1 / Math.pow(10, csConfig.decimalCount || 4); - var format = '0,0.0' + Array(csConfig.decimalCount || 4).join('0'); - var currencySymbol = $filter('currencySymbol'); - - function formatRelative(input, options) { - var currentUD = options && options.currentUD ? options.currentUD : csWallet.data.currentUD; - if (!currentUD) { - console.warn("formatAmount: currentUD not defined"); - return; - } - var amount = input / currentUD; - if (Math.abs(amount) < minValue && input !== 0) { - amount = '~ 0'; - } - else { - amount = numeral(amount).format(format); - } - if (options && options.currency) { - return amount + ' ' + currencySymbol(options.currency, true); - } - return amount; - } - - function formatQuantitative(input, options) { - var amount = numeral(input/100).format((input > -1000000000 && input < 1000000000) ? '0,0.00' : '0,0.000 a'); - if (options && options.currency) { - return amount + ' ' + currencySymbol(options.currency, false); - } - return amount; - } - - return function(input, options) { - if (input === undefined) return; - return (options && angular.isDefined(options.useRelative) ? options.useRelative : csSettings.data.useRelative) ? - formatRelative(input, options) : - formatQuantitative(input, options); - }; - }) - - .filter('formatAmountNoHtml', function(csConfig, csSettings, csWallet, $filter) { - var minValue = 1 / Math.pow(10, csConfig.decimalCount || 4); - var format = '0,0.0' + Array(csConfig.decimalCount || 4).join('0'); - var currencySymbol = $filter('currencySymbolNoHtml'); - - function formatRelative(input, options) { - var currentUD = options && options.currentUD ? options.currentUD : csWallet.data.currentUD; - if (!currentUD) { - console.warn("formatAmount: currentUD not defined"); - return; - } - var amount = input / currentUD; - if (Math.abs(amount) < minValue && input !== 0) { - amount = '~ 0'; - } - else { - amount = numeral(amount).format(format); - } - if (options && options.currency) { - return amount + ' ' + currencySymbol(options.currency, true); - } - return amount; - } - - function formatQuantitative(input, options) { - var amount = numeral(input/100).format((input > -1000000000 && input < 1000000000) ? '0,0.00' : '0,0.000 a'); - if (options && options.currency) { - return amount + ' ' + currencySymbol(options.currency, false); - } - return amount; - } - - return function(input, options) { - if (input === undefined) return; - return (options && angular.isDefined(options.useRelative) ? options.useRelative : csSettings.data.useRelative) ? - formatRelative(input, options) : - formatQuantitative(input, options); - }; - }) - - - .filter('currencySymbol', function($rootScope, $filter, csSettings) { - return function(input, useRelative) { - if (!input) return ''; - return (angular.isDefined(useRelative) ? useRelative : csSettings.data.useRelative) ? - ($rootScope.translations.UD + '<sub>' + $filter('abbreviate')(input) + '</sub>') : - $filter('abbreviate')(input); - }; - }) - - .filter('currencySymbolNoHtml', function($rootScope, $filter, csSettings) { - return function(input, useRelative) { - if (!input) return ''; - return (angular.isDefined(useRelative) ? useRelative : csSettings.data.useRelative) ? - ($rootScope.translations.UD + ' ' + $filter('abbreviate')(input)) : - $filter('abbreviate')(input); - }; - }) - - - .filter('formatDecimal', function(csConfig, $rootScope) { - var minValue = 1 / Math.pow(10, csConfig.decimalCount || 4); - var format = '0,0.0' + Array(csConfig.decimalCount || 4).join('0'); - - return function(input) { - if (input === undefined) return '0'; - if (input === Infinity || input === -Infinity) { - console.warn("formatDecimal: division by zero ? (is currentUD defined ?) = " + $rootScope.walletData.currentUD); - return 'error'; - } - if (Math.abs(input) < minValue) return '~ 0'; - return numeral(input/*-0.00005*/).format(format); - }; - }) - - .filter('formatNumeral', function() { - return function(input, pattern) { - if (input === undefined) return '0'; - // for DEBUG only - //if (isNaN(input)) { - // return 'NaN'; - //} - if (Math.abs(input) < 0.0001) return '~ 0'; - return numeral(input).format(pattern); - }; - }) - - .filter('formatDate', function($rootScope) { - return function(input) { - return input ? moment.unix(parseInt(input)).local().format($rootScope.translations.DATE_PATTERN || 'YYYY-MM-DD HH:mm') : ''; - }; - }) - - .filter('formatDateShort', function($rootScope) { - return function(input) { - return input ? moment.unix(parseInt(input)).local().format($rootScope.translations.DATE_SHORT_PATTERN || 'YYYY-MM-DD') : ''; - }; - }) - - .filter('formatDateMonth', function($rootScope) { - return function(input) { - return input ? moment.unix(parseInt(input)).local().format($rootScope.translations.DATE_MONTH_YEAR_PATTERN || 'MMM YY') : ''; - }; - }) - - .filter('formatTime', function() { - return function(input) { - return input ? moment.unix(parseInt(input)).local().format('HH:mm') : ''; - }; - }) - - .filter('formatFromNow', function() { - return function(input) { - return input ? moment.unix(parseInt(input)).fromNow() : ''; - }; - }) - - - .filter('formatDurationTo', function() { - return function(input) { - return input ? moment.unix(moment().utc().unix() + parseInt(input)).fromNow() : ''; - }; - }) - - .filter('formatDuration', function() { - return function(input) { - return input ? moment(0).from(moment.unix(parseInt(input)), true) : ''; - }; - }) - - // Display time in ms or seconds (see i18n label 'COMMON.EXECUTION_TIME') - .filter('formatDurationMs', function() { - return function(input) { - return input ? ( - (input < 1000) ? - (input + 'ms') : - (input/1000 + 's') - ) : ''; - }; - }) - - .filter('formatPeriod', function() { - return function(input) { - if (!input) {return null;} - var duration = moment(0).from(moment.unix(parseInt(input)), true); - return duration.split(' ').slice(-1)[0]; // keep only last words (e.g. remove "un" "a"...) - }; - }) - - .filter('formatFromNowShort', function() { - return function(input) { - return input ? moment.unix(parseInt(input)).fromNow(true) : ''; - }; - }) - - .filter('capitalize', function() { - return function(input) { - if (!input) return ''; - input = input.toLowerCase(); - return input.substring(0,1).toUpperCase()+input.substring(1); - }; - }) - - .filter('abbreviate', function() { - var _cache = {}; - return function(input) { - var currency = input || ''; - if (_cache[currency]) return _cache[currency]; - if (currency.length > 3) { - var unit = '', sepChars = ['-', '_', ' ']; - for (var i = 0; i < currency.length; i++) { - var c = currency[i]; - if (i === 0) { - unit = (c === 'g' || c === 'G') ? 'Ğ' : c ; - } - else if (i > 0 && sepChars.indexOf(currency[i-1]) != -1) { - unit += c; - } - } - currency = unit.toUpperCase(); - } - else { - currency = currency.toUpperCase(); - if (currency.charAt(0) === 'G') { - currency = 'Ğ' + (currency.length > 1 ? currency.substr(1) : ''); - } - } - - _cache[input] = currency; - return currency; - }; - }) - -.filter('upper', function() { - return function(input) { - if (!input) return ''; - return input.toUpperCase(); - }; - }) - - .filter('formatPubkey', function() { - return function(input) { - return input ? input.substr(0,8) : ''; - }; - }) - - .filter('formatHash', function() { - return function(input) { - return input ? input.substr(0,4) + input.substr(input.length-4) : ''; - }; - }) - - .filter('formatCategory', function() { - return function(input) { - return input && input.length > 28 ? input.substr(0,25)+'...' : input; - }; - }) - - // Convert to user friendly URL (e.g. "Like - This" -> "like-this") - .filter('formatSlug', function() { - return function(input) { - return input ? encodeURIComponent(input - .toLowerCase() - .replace(/<[^>]+>/g,'') // Remove tag (like HTML tag) - .replace(/[^\w ]+/g,'') - .replace(/ +/g,'-')) - : ''; - }; - }) - - // Convert a URI into parameter (e.g. "http://hos/path" -> "http%3A%2F%2Fhost%2Fpath") - .filter('formatEncodeURI', function() { - return function(input) { - return input ? encodeURIComponent(input): ''; - }; - }) - - .filter('truncText', function() { - return function(input, size) { - size = size || 500; - return !input || input.length <= size ? input : (input.substr(0, size) + '...'); - }; - }) - // Translation i18n .config(function ($translateProvider, csConfig) { 'ngInject'; @@ -375,9 +85,21 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht IdleProvider.timeout(csConfig.logoutTimeout||15); // display warning during 15s }) -.run(function($rootScope, $translate, $state, $window, ionicReady, localStorage, Device, UIUtils, $ionicConfig, PluginService, csWallet, csSettings, csConfig, csCurrency) { + .factory('$exceptionHandler', function($log) { + 'ngInject'; + + return function(exception, cause) { + $log.error(exception, cause); + }; + }) + + + +.run(function($rootScope, $translate, $state, $window, ionicReady, localStorage, + filterTranslations, Device, BMA, UIUtils, csHttp, $ionicConfig, PluginService, csPlatform, csWallet, csSettings, csConfig, csCurrency) { 'ngInject'; + // Allow access to service data, from HTML templates $rootScope.config = csConfig; $rootScope.settings = csSettings.data; $rootScope.currency = csCurrency.data; @@ -389,25 +111,8 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht $rootScope.rootPath = (hashIndex != -1) ? $window.location.href.substr(0, hashIndex) : $window.location.href; console.debug('[app] Root path is [' + $rootScope.rootPath + ']'); - // removeIf(android) - // removeIf(ios) - // removeIf(firefoxos) - // Automatic redirection to large state (if define) (keep this code for platforms web and ubuntu build) - $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { - if (next.data.large && !UIUtils.screen.isSmall()) { - var redirect = !$rootScope.tour && !event.currentScope.tour; // disabled for help tour - if (redirect) { - event.preventDefault(); - $state.go(next.data.large, nextParams); - } - } - }); - // endRemoveIf(firefoxos) - // endRemoveIf(ios) - // endRemoveIf(android) - // removeIf(device) - // Automatic redirection to HTTPS + // -- Automatic redirection to HTTPS if ((csConfig.httpsMode === true || csConfig.httpsMode == 'true' ||csConfig.httpsMode === 'force') && $window.location.protocol != 'https:') { $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { @@ -423,89 +128,57 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht } // endRemoveIf(device) - // Update some translations, when locale changed - function onLocaleChange() { - console.debug('[app] Loading cached translations for locale [{0}]'.format($translate.use())); - $translate(['COMMON.DATE_PATTERN', 'COMMON.DATE_SHORT_PATTERN', 'COMMON.UD']) - .then(function(translations) { - $rootScope.translations = $rootScope.translations || {}; - $rootScope.translations.DATE_PATTERN = translations['COMMON.DATE_PATTERN']; - if ($rootScope.translations.DATE_PATTERN === 'COMMON.DATE_PATTERN') { - $rootScope.translations.DATE_PATTERN = 'YYYY-MM-DD HH:mm'; - } - $rootScope.translations.DATE_SHORT_PATTERN = translations['COMMON.DATE_SHORT_PATTERN']; - if ($rootScope.translations.DATE_SHORT_PATTERN === 'COMMON.DATE_SHORT_PATTERN') { - $rootScope.translations.DATE_SHORT_PATTERN = 'YYYY-MM-DD'; - } - $rootScope.translations.DATE_MONTH_YEAR_PATTERN = translations['COMMON.DATE_MONTH_YEAR_PATTERN']; - if ($rootScope.translations.DATE_MONTH_YEAR_PATTERN === 'COMMON.DATE_MONTH_YEAR_PATTERN') { - $rootScope.translations.DATE_MONTH_YEAR_PATTERN = 'MMM YY'; - } - - $rootScope.translations.UD = translations['COMMON.UD']; - if ($rootScope.translations.UD === 'COMMON.UD') { - $rootScope.translations.UD = 'UD'; - } - }); - } - csSettings.api.locale.on.changed($rootScope, onLocaleChange, this); + // removeIf(android) + // removeIf(ios) + // removeIf(firefoxos) + // -- Automatic redirection to large state (if define) (keep this code for platforms web and ubuntu build) + $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { + if (next.data && next.data.large && !UIUtils.screen.isSmall()) { + var redirect = !$rootScope.tour && !event.currentScope.tour; // disabled for help tour + if (redirect) { + event.preventDefault(); + $state.go(next.data.large, nextParams); + } + } + }); + // endRemoveIf(firefoxos) + // endRemoveIf(ios) + // endRemoveIf(android) // Start plugins eager services PluginService.start(); - // Force at least on call - onLocaleChange(); - // We use 'ionicReady()' instead of '$ionicPlatform.ready()', because this one is callable many times - ionicReady() - .then(function() { - - // Keyboard - if (Device.keyboard.enable) { - // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard - // for form inputs) - Device.keyboard.hideKeyboardAccessoryBar(true); - - // iOS: do not push header up when opening keyboard - // (see http://ionicframework.com/docs/api/page/keyboard/) - if (ionic.Platform.isIOS()) { - Device.keyboard.disableScroll(true); - } - } + ionicReady().then(function() { - // Ionic Platform Grade is not A, disabling views transitions - if (ionic.Platform.grade.toLowerCase()!='a') { - console.log('[app] Disabling UI effects, because plateform\'s grade is [' + ionic.Platform.grade + ']'); - UIUtils.setEffects(false); - } + // Keyboard + if (Device.keyboard.enable) { + // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard + // for form inputs) + Device.keyboard.hideKeyboardAccessoryBar(true); - // Status bar style - if (window.StatusBar) { - // org.apache.cordova.statusbar required - StatusBar.styleDefault(); + // iOS: do not push header up when opening keyboard + // (see http://ionicframework.com/docs/api/page/keyboard/) + if (ionic.Platform.isIOS()) { + Device.keyboard.disableScroll(true); } + } - // Start local storage - return localStorage.ready(); - }) - - // Force to start settings - .then(csSettings.ready) - - // Load currency - .then(csCurrency.get) - .then(function(currency){ - $rootScope.currency = currency; - }) - - // Trying to restore wallet - .then(csWallet.restore) + // Ionic Platform Grade is not A, disabling views transitions + if (ionic.Platform.grade.toLowerCase() != 'a') { + console.log('[app] Disabling UI effects, because plateform\'s grade is [' + ionic.Platform.grade + ']'); + UIUtils.setEffects(false); + } - // Storing wallet to root scope - .then(function(walletData){ - $rootScope.walletData = walletData; - }); + // Status bar style + if (window.StatusBar) { + // org.apache.cordova.statusbar required + StatusBar.styleDefault(); + } + // Make sure platform is ready + return csPlatform.ready(); + }); }) ; diff --git a/www/js/config.js b/www/js/config.js index 7d7b10e7a5a4fc46fbee458b0279425af735286e..53f20a3baa72f223f6389585d9f54f62823707de 100644 --- a/www/js/config.js +++ b/www/js/config.js @@ -19,7 +19,6 @@ angular.module("cesium.config", []) "logoutIlde": 600, "useLocalStorage": true, "useRelative": false, - "initPhase": false, "expertMode": false, "decimalCount": 2, "httpsMode": false, @@ -35,6 +34,15 @@ angular.module("cesium.config", []) "host": "g1.duniter.org", "port": "443" }, + "fallbackNodes": [{ + "host": "g1.duniter.org", + "port": "443" + }, + { + "host": "g1.duniter.fr", + "port": "443" + } + ], "plugins": { "es": { "enable": true, diff --git a/www/js/controllers.js b/www/js/controllers.js index 84e04c422ba63c5d822e8a6c8608397bd21e45f5..a612166287398398363b2d659baf4dfc0c8f2367 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -6,7 +6,6 @@ angular.module('cesium.controllers', [ 'cesium.help.controllers', 'cesium.wallet.controllers', 'cesium.currency.controllers', - /*'cesium.currency-charts.controllers',*/ 'cesium.wot.controllers', 'cesium.transfer.controllers', 'cesium.settings.controllers', diff --git a/www/js/controllers/app-controllers.js b/www/js/controllers/app-controllers.js index e52206a821d3dcd4645c9f649fb08303af9ca487..15ab560523ab107bc56dc82c8975b042b5bd7880 100644 --- a/www/js/controllers/app-controllers.js +++ b/www/js/controllers/app-controllers.js @@ -1,4 +1,4 @@ -angular.module('cesium.app.controllers', ['ngIdle', 'cesium.services']) +angular.module('cesium.app.controllers', ['ngIdle', 'cesium.platform', 'cesium.services']) .config(function($httpProvider) { 'ngInject'; @@ -88,8 +88,8 @@ function PluginExtensionPointController($scope, PluginService) { * Abstract controller (inherited by other controllers) */ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $timeout, - $ionicHistory, $controller, $window, - UIUtils, BMA, csWallet, Device, Modals, csSettings, csConfig + $ionicHistory, $controller, $window, csPlatform, + UIUtils, BMA, csWallet, csCurrency, Device, Modals, csSettings, csConfig ) { 'ngInject'; @@ -99,7 +99,6 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ $scope.search = {}; $scope.login = csWallet.isLogin(); $scope.motion = UIUtils.motion.default; - $scope.initPhase = csConfig.initPhase; $scope.showHome = function() { $ionicHistory.nextViewOptions({ @@ -212,7 +211,7 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ .then(function(walletData) { // Warn if wallet has been never used - see #167 - var showAlert = !csConfig.initPhase && csWallet.isNew() && csWallet.isNeverUsed() && (!csSettings.data.wallet || csSettings.data.wallet.alertIfUnusedWallet); + var showAlert = !csCurrency.data.initPhase && !csWallet.isNew() && csWallet.isNeverUsed() && (!csSettings.data.wallet || csSettings.data.wallet.alertIfUnusedWallet); if (!showAlert) return walletData; // Alert: wallet is empty ! @@ -242,6 +241,14 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ // Login and load wallet $scope.loadWallet = function(options) { + + // Make the platform is ready + if (!csPlatform.isStarted()) { + return csPlatform.ready().then(function(){ + return $scope.loadWallet(options); + }); + } + if (!csWallet.isLogin()) { return $scope.showLoginModal() .then(function (walletData) { @@ -445,8 +452,18 @@ function AboutController($scope, csConfig) { } -function HomeController($scope) { +function HomeController($scope, csPlatform) { 'ngInject'; + + $scope.loading = true; + + $scope.$on('$ionicView.enter', function(e, state) { + csPlatform.ready() + .then(function() { + $scope.loading = false; + }); + }); + } diff --git a/www/js/controllers/currency-charts-controllers.js b/www/js/controllers/currency-charts-controllers.js deleted file mode 100644 index 3e9f4f43e97a6b743b47acf53595c49e46d0d188..0000000000000000000000000000000000000000 --- a/www/js/controllers/currency-charts-controllers.js +++ /dev/null @@ -1,77 +0,0 @@ - -angular.module('cesium.currency-charts.controllers', ['cesium.services']) - -.config(function($stateProvider) { - 'ngInject'; - - $stateProvider - - .state('app.currency_ud', { - url: "/currency/ud", - nativeTransitions: { - "type": "flip", - "direction": "up" - }, - views: { - 'menuContent': { - templateUrl: "templates/currency/charts/ud.html", - controller: 'CurrencyUdCtrl' - } - } - }) - ; -}) - -.controller('CurrencyUdCtrl', CurrencyUdController) - -; - -function CurrencyUdController($scope, BMA, $q) { - 'ngInject'; - - $scope.$on('$ionicView.enter', function() { - $scope.loadUds() - .then(function (dataXY) { - // TODO: plot - }); - }); - - $scope.loadUds = function() { - return $q(function(resolve, reject) { - BMA.blockchain.stats.ud() - .then(function (res) { - if (res.result.blocks.length) { - var uds = []; - var blockRequests = []; - res.result.blocks.forEach(function(number) { - blockRequests.push( - BMA.blockchain.block({ block: number }) - .then(function(block){ - uds.push({ - number: block.number, - dividend: block.dividend, - medianTime: block.medianTime - }); - }) - ); - }); - $q.all(blockRequests) - .then(function() { - _.sortBy(uds, function(b){return b.number;}); - var x = uds.reduce(function(values, block) { - return values.concat(block.medianTime); - }, []); - var y = uds.reduce(function(values, block) { - return values.concat(block.dividend); - }, []); - resolve({x: x, y: y}); - }); - } - else { - resolve([]); - } - }); - }); - }; - -} diff --git a/www/js/controllers/currency-controllers.js b/www/js/controllers/currency-controllers.js index 863d2158e660cf786720fed678fdbd02515cff0d..1a23d5254ee5d512bf8922e2f6cbca963b6974c2 100644 --- a/www/js/controllers/currency-controllers.js +++ b/www/js/controllers/currency-controllers.js @@ -116,8 +116,6 @@ function CurrencyViewController($scope, $q, $timeout, $ionicPopover, Modals, BMA $scope.enter = function(e, state) { if ($scope.loading) { // run only once (first enter) - UIUtils.loading.show(); - csCurrency.get() .then($scope.load) .then(function() { @@ -182,9 +180,11 @@ function CurrencyViewController($scope, $q, $timeout, $ionicPopover, Modals, BMA .catch(function(err){ // Special case for currency init (root block not exists): use fixed values if (err && err.ucode == BMA.errorCodes.NO_CURRENT_BLOCK) { + M = 0; data.N = 0; data.medianTime = Math.trunc(new Date().getTime() / 1000); data.difficulty = 0; + data.blockUid = null; return; } throw err; @@ -217,10 +217,10 @@ function CurrencyViewController($scope, $q, $timeout, $ionicPopover, Modals, BMA // Process loaded data .then(function(){ var Mprev = M - data.currentUD * data.Nprev; // remove fresh money - var MoverNprev = Mprev / data.Nprev; + var MoverNprev = data.Nprev ? (Mprev / data.Nprev) : 0; data.cactual = MoverNprev ? 100 * data.currentUD / MoverNprev : 0; data.M = M; - data.MoverN = (Mprev ? Mprev : M/*need at currency start only*/) / data.Nprev; + data.MoverN = data.Nprev ? ((Mprev ? Mprev : M/*need at currency start only*/) / data.Nprev) : 0; data.UD = data.currentUD; data.durationFromLastUD = lastUDTime ? data.medianTime - lastUDTime : 0; data.sentries = Math.ceil(Math.pow(data.N, 1/ data.stepMax)); diff --git a/www/js/controllers/help-controllers.js b/www/js/controllers/help-controllers.js index a76a801f310c28bbbe4fe89a01a3ed783510fdc5..5ab6f53977d4b1a5e3a3df0064da3bd421e5a7b4 100644 --- a/www/js/controllers/help-controllers.js +++ b/www/js/controllers/help-controllers.js @@ -655,7 +655,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe $ionicSideMenuDelegate.toggleLeft(true); return $scope.showHelpTip('helptip-menu-btn-account', { bindings: { - content: $rootScope.walletData.isMember ? 'HELP.TIP.MENU_BTN_ACCOUNT_MEMBER' : 'HELP.TIP.MENU_BTN_ACCOUNT', + content: 'HELP.TIP.MENU_BTN_ACCOUNT', icon: { position: 'left' }, @@ -682,7 +682,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe $ionicSideMenuDelegate.toggleLeft(true); return $scope.showHelpTip('helptip-menu-btn-account', { bindings: { - content: $rootScope.walletData.isMember ? 'HELP.TIP.MENU_BTN_ACCOUNT_MEMBER' : 'HELP.TIP.MENU_BTN_ACCOUNT', + content: csWallet.data.isMember ? 'HELP.TIP.MENU_BTN_ACCOUNT_MEMBER' : 'HELP.TIP.MENU_BTN_ACCOUNT', icon: { position: 'left' } @@ -873,7 +873,7 @@ function HelpTipController($scope, $rootScope, $state, $window, $ionicSideMenuDe $ionicSideMenuDelegate.toggleLeft(true); return $scope.showHelpTip('helptip-menu-btn-tx', { bindings: { - content: $rootScope.walletData.isMember ? 'HELP.TIP.MENU_BTN_TX_MEMBER' : 'HELP.TIP.MENU_BTN_TX', + content: csWallet.data.isMember ? 'HELP.TIP.MENU_BTN_TX_MEMBER' : 'HELP.TIP.MENU_BTN_TX', icon: { position: 'left' } diff --git a/www/js/controllers/join-controllers.js b/www/js/controllers/join-controllers.js index 71476558b6542eaaf767826fc6ed1fc801925f61..29a6340aea86385e00031fe22154d6c06d7f09a1 100644 --- a/www/js/controllers/join-controllers.js +++ b/www/js/controllers/join-controllers.js @@ -55,7 +55,7 @@ function JoinChooseAccountTypeModalController($scope, $state, Modals, UIUtils, c $scope.formData.currency = currency.name; $scope.loading = false; }) - .catch(UIUtils.onError('ERROR.GET_CURRENCIES_FAILED')); + .catch(UIUtils.onError('ERROR.GET_CURRENCY_FAILED')); } }; $scope.$on('modal.shown', $scope.load); diff --git a/www/js/controllers/login-controllers.js b/www/js/controllers/login-controllers.js index 27854b8d07bf5ac5d2d093cf3fdba396109562ae..1b80bcd0429e8bb68333e515a446c0343ec1fc0f 100644 --- a/www/js/controllers/login-controllers.js +++ b/www/js/controllers/login-controllers.js @@ -4,7 +4,7 @@ angular.module('cesium.login.controllers', ['cesium.services']) .controller('LoginModalCtrl', LoginModalController) ; -function LoginModalController($scope, $timeout, CryptoUtils, UIUtils, Modals, csSettings, Device) { +function LoginModalController($scope, $timeout, CryptoUtils, UIUtils, Modals, csPlatform, csSettings, Device) { 'ngInject'; $scope.computing = false; @@ -16,7 +16,7 @@ function LoginModalController($scope, $timeout, CryptoUtils, UIUtils, Modals, cs $scope.showPubkeyButton = false; $scope.autoComputePubkey = false; - Device.ready().then(function() { + csPlatform.ready().then(function() { $scope.autoComputePubkey = ionic.Platform.grade.toLowerCase()==='a' && !UIUtils.screen.isSmall(); }); diff --git a/www/js/controllers/settings-controllers.js b/www/js/controllers/settings-controllers.js index 85158edd54a69d226c5da825d9c6885e61406b37..c62153bb876066ed70d7cc86540b6a6fd1efbe86 100644 --- a/www/js/controllers/settings-controllers.js +++ b/www/js/controllers/settings-controllers.js @@ -120,7 +120,9 @@ function SettingsController($scope, $q, $ionicHistory, $ionicPopup, $timeout, $t } UIUtils.loading.hide(); $scope.formData.node = newNode; + delete $scope.formData.temporary; BMA.copy(nodeBMA); + $scope.bma = BMA; // Reset history cache return $ionicHistory.clearCache(); @@ -210,6 +212,10 @@ function SettingsController($scope, $q, $ionicHistory, $ionicPopup, $timeout, $t // 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.store(); $scope.saving = false; }, 100); diff --git a/www/js/controllers/transfer-controllers.js b/www/js/controllers/transfer-controllers.js index c16b68b4d8c3aa48b9ca683295a521b5ed0aa863..e8b49260624909c4c9ec27df2ef12cbe1866bac5 100644 --- a/www/js/controllers/transfer-controllers.js +++ b/www/js/controllers/transfer-controllers.js @@ -106,7 +106,7 @@ function TransferController($scope, $controller, UIUtils, csWot) { } function TransferModalController($scope, $rootScope, $translate, $filter, BMA, csWallet, UIUtils, Modals, - csSettings, parameters) { + csCurrency, csSettings, parameters) { 'ngInject'; $scope.convertedBalance = 0; @@ -119,6 +119,7 @@ function TransferModalController($scope, $rootScope, $translate, $filter, BMA, c }; $scope.udAmount = null; $scope.commentPattern = BMA.regexp.COMMENT; + $scope.currency = csCurrency.data.name; $scope.setParameters = function(parameters) { if (!parameters) return; @@ -155,12 +156,12 @@ function TransferModalController($scope, $rootScope, $translate, $filter, BMA, c // When changing use relative UD $scope.onUseRelativeChanged = function() { - $scope.currency = $rootScope.walletData.currency; + $scope.currency = csCurrency.data.name; if ($scope.formData.useRelative) { - $scope.convertedBalance = $rootScope.walletData.balance / $rootScope.walletData.currentUD; - $scope.udAmount = $scope.amount * $rootScope.walletData.currentUD; + $scope.convertedBalance = csWallet.data.balance / csCurrency.data.currentUD; + $scope.udAmount = $scope.amount * csCurrency.data.currentUD; } else { - $scope.convertedBalance = $rootScope.walletData.balance; + $scope.convertedBalance = csWallet.data.balance; // Convert to number $scope.formData.amount = (!!$scope.formData.amount && typeof $scope.formData.amount == "string") ? Math.floor(parseFloat($scope.formData.amount.replace(new RegExp('[,]'), '.'))) : @@ -168,9 +169,9 @@ function TransferModalController($scope, $rootScope, $translate, $filter, BMA, c // Compute UD $scope.udAmount = (!!$scope.formData.amount && typeof $scope.formData.amount == "number" && - !!$rootScope.walletData.currentUD && - typeof $rootScope.walletData.currentUD == "number") ? - $scope.formData.amount / $rootScope.walletData.currentUD :null; + !!csCurrency.data.currentUD && + typeof csCurrency.data.currentUD == "number") ? + $scope.formData.amount / csCurrency.data.currentUD :null; } }; $scope.$watch('formData.useRelative', $scope.onUseRelativeChanged, true); @@ -201,7 +202,7 @@ function TransferModalController($scope, $rootScope, $translate, $filter, BMA, c amount = parseFloat(amount.replace(new RegExp('[.,]'), '.')); } if ($scope.formData.useRelative) { - amount = $rootScope.walletData.currentUD * amount; + amount = csWallet.data.currentUD * amount; } else { amount = amount * 100; // remove 2 decimals of quantitative mode @@ -221,10 +222,10 @@ function TransferModalController($scope, $rootScope, $translate, $filter, BMA, c return $translate(['COMMON.UD', 'COMMON.EMPTY_PARENTHESIS']) .then(function(translations) { return $translate('CONFIRM.TRANSFER', { - from: $rootScope.walletData.isMember ? $rootScope.walletData.uid : $filter('formatPubkey')($rootScope.walletData.pubkey), + from: csWallet.data.isMember ? csWallet.data.uid : $filter('formatPubkey')(csWallet.data.pubkey), to: $scope.destUid ? $scope.destUid : $scope.destPub, amount: $scope.formData.amount, - unit: $scope.formData.useRelative ? translations['COMMON.UD'] : $filter('abbreviate')($rootScope.walletData.parameters.currency), + unit: $scope.formData.useRelative ? translations['COMMON.UD'] : $filter('abbreviate')($scope.currency), comment: (!$scope.formData.comment || $scope.formData.comment.trim().length === 0) ? translations['COMMON.EMPTY_PARENTHESIS'] : $scope.formData.comment }); }) diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js index a63b0ed2b686dfefdb1185fc0598373c3338c4f5..97bf3873bc5376101e1002e39098cfa63b0ad265 100644 --- a/www/js/controllers/wallet-controllers.js +++ b/www/js/controllers/wallet-controllers.js @@ -405,7 +405,7 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state, // Transfer $scope.showTransferModal = function() { - var hasCredit = (!!$scope.walletData.balance && $scope.walletData.balance > 0); + var hasCredit = (!!$scope.formData.balance && $scope.formData.balance > 0); if (!hasCredit) { UIUtils.alert.info('INFO.NOT_ENOUGH_CREDIT'); return; @@ -524,7 +524,7 @@ function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state, } -function WalletTxController($scope, $rootScope, $timeout, $filter, $ionicPopover, $state, UIUtils, csWallet, Modals, csSettings, BMA) { +function WalletTxController($scope, $filter, $ionicPopover, $state, UIUtils, csWallet, Modals, csSettings, BMA) { 'ngInject'; $scope.loading = true; @@ -616,7 +616,7 @@ function WalletTxController($scope, $rootScope, $timeout, $filter, $ionicPopover $scope.showMoreTx = function(fromTime) { fromTime = fromTime || - ($rootScope.walletData.tx.fromTime - csSettings.data.walletHistoryTimeSecond) || + ($scope.formData.tx.fromTime - csSettings.data.walletHistoryTimeSecond) || (Math.trunc(new Date().getTime() / 1000) - 2 * csSettings.data.walletHistoryTimeSecond); UIUtils.loading.show(); @@ -758,7 +758,7 @@ function WalletTxErrorController($scope, UIUtils, csWallet) { } -function WalletSecurityModalController($scope, $rootScope, UIUtils, csWallet, $translate, CryptoUtils){ +function WalletSecurityModalController($scope, UIUtils, csWallet, $translate, CryptoUtils){ $scope.slides = { slider: null, @@ -1036,7 +1036,7 @@ function WalletSecurityModalController($scope, $rootScope, UIUtils, csWallet, $t * Revoke identity */ $scope.revokeIdentity = function (confirm, confirmAgain) { - if ($rootScope.walletData.requirements.needSelf) { + if (!$scope.hasSelf) { return UIUtils.alert.error("ERROR.ONLY_SELF_CAN_EXECUTE_THIS_ACTION"); } if (!confirm) { diff --git a/www/js/controllers/wot-controllers.js b/www/js/controllers/wot-controllers.js index 3ceec54d495438ac9824fd591a24d04004bb5c8d..f2d6aca5f860eb1cb1037da33ab51f71d1b83b63 100644 --- a/www/js/controllers/wot-controllers.js +++ b/www/js/controllers/wot-controllers.js @@ -97,7 +97,7 @@ angular.module('cesium.wot.controllers', ['cesium.services']) ; function WotLookupController($scope, $state, $timeout, $focus, $ionicPopover, $ionicHistory, - UIUtils, csConfig, csSettings, Device, BMA, csWallet, csWot) { + UIUtils, csConfig, csCurrency, csSettings, Device, BMA, csWallet, csWot) { 'ngInject'; var defaultSearchLimit = 10; @@ -133,7 +133,7 @@ function WotLookupController($scope, $state, $timeout, $focus, $ionicPopover, $i else { $timeout(function() { // Init phase - if (csConfig.initPhase && !state.stateParams.type) { + if (csCurrency.data.initPhase && !state.stateParams.type) { $scope.doGetPending(0, undefined, true/*skipLocationUpdate*/); } // get new comers @@ -272,7 +272,7 @@ function WotLookupController($scope, $state, $timeout, $focus, $ionicPopover, $i $scope.search.loading = (offset === 0); $scope.search.type = 'pending'; - var searchFunction = csConfig.initPhase ? + var searchFunction = csCurrency.data.initPhase ? csWot.all : csWot.pending; @@ -286,7 +286,7 @@ function WotLookupController($scope, $state, $timeout, $focus, $ionicPopover, $i if ($scope.search.type != 'pending') return false; // could have change $scope.doDisplayResult(idties, offset, size); // Always disable "more" on initphase - $scope.search.hasMore = !csConfig.initPhase && $scope.search.hasMore; + $scope.search.hasMore = !csCurrency.data.initPhase && $scope.search.hasMore; return true; }) .catch(function(err) { @@ -581,13 +581,13 @@ function WotIdentityAbstractController($scope, $rootScope, $state, $translate, $ .then(function() { UIUtils.loading.hide(); - if (!csConfig.initPhase && !$rootScope.walletData.isMember) { + if (!csCurrency.data.initPhase && !$rootScope.walletData.isMember) { UIUtils.alert.error($rootScope.walletData.requirements.needSelf ? 'ERROR.NEED_MEMBER_ACCOUNT_TO_CERTIFY' : 'ERROR.NEED_MEMBER_ACCOUNT_TO_CERTIFY_HAS_SELF'); return; } - if (!csConfig.initPhase && !$scope.formData.hasSelf) { + if (!csCurrency.data.initPhase && !$scope.formData.hasSelf) { UIUtils.alert.error('ERROR.IDENTITY_TO_CERTIFY_HAS_NO_SELF'); return; } @@ -656,7 +656,7 @@ function WotIdentityAbstractController($scope, $rootScope, $state, $translate, $ $scope.loadWallet() .catch(UIUtils.onError('ERROR.LOGIN_FAILED')) .then(function() { - if (!csConfig.initPhase && !$rootScope.walletData.isMember) { + if (!csCurrency.data.initPhase && !$rootScope.walletData.isMember) { UIUtils.alert.error($rootScope.walletData.requirements.needSelf || $rootScope.walletData.requirements.needMembership ? 'ERROR.NEED_MEMBER_ACCOUNT_TO_CERTIFY' : 'ERROR.NEED_MEMBER_ACCOUNT_TO_CERTIFY_HAS_SELF'); return; diff --git a/www/js/filters.js b/www/js/filters.js new file mode 100644 index 0000000000000000000000000000000000000000..eddc66acf40c76389a3b02a2320d525d6bcf1f63 --- /dev/null +++ b/www/js/filters.js @@ -0,0 +1,349 @@ +// Cesium filters +angular.module('cesium.filters', ['cesium.config', 'cesium.settings.services', 'pascalprecht.translate', 'cesium.translations' +]) + + .service('filterTranslations', function($rootScope, csSettings, $translate) { + 'ngInject'; + + var + started = false, + startPromise, + that = this; + + // Update some translations, when locale changed + function onLocaleChange() { + console.debug('[filter] Loading translations for locale [{0}]'.format($translate.use())); + return $translate(['COMMON.DATE_PATTERN', 'COMMON.DATE_SHORT_PATTERN', 'COMMON.UD']) + .then(function(translations) { + that.DATE_PATTERN = translations['COMMON.DATE_PATTERN']; + if (that.DATE_PATTERN === 'COMMON.DATE_PATTERN') { + that.DATE_PATTERN = 'YYYY-MM-DD HH:mm'; + } + that.DATE_SHORT_PATTERN = translations['COMMON.DATE_SHORT_PATTERN']; + if (that.DATE_SHORT_PATTERN === 'COMMON.DATE_SHORT_PATTERN') { + that.DATE_SHORT_PATTERN = 'YYYY-MM-DD'; + } + that.DATE_MONTH_YEAR_PATTERN = translations['COMMON.DATE_MONTH_YEAR_PATTERN']; + if (that.DATE_MONTH_YEAR_PATTERN === 'COMMON.DATE_MONTH_YEAR_PATTERN') { + that.DATE_MONTH_YEAR_PATTERN = 'MMM YY'; + } + + that.UD = translations['COMMON.UD']; + if (that.UD === 'COMMON.UD') { + that.UD = 'UD'; + } + }); + } + csSettings.api.locale.on.changed($rootScope, onLocaleChange, this); + + that.ready = function() { + if (started) return $q.when(data); + return startPromise || that.start(); + }; + + that.start = function() { + startPromise = csSettings.ready() + .then(onLocaleChange) + .then(function() { + started = true; + }); + return startPromise; + }; + + // Default action + that.start(); + + return that; + }) + + .filter('formatInteger', function() { + return function(input) { + return !input ? '0' : (input < 10000000 ? numeral(input).format('0,0') : numeral(input).format('0,0.000 a')); + }; + }) + + .filter('formatAmount', function(csConfig, csSettings, csCurrency, $filter) { + var minValue = 1 / Math.pow(10, csConfig.decimalCount || 4); + var format = '0,0.0' + Array(csConfig.decimalCount || 4).join('0'); + var currencySymbol = $filter('currencySymbol'); + + function formatRelative(input, options) { + var currentUD = options && options.currentUD ? options.currentUD : csCurrency.data.currentUD; + if (!currentUD) { + console.warn("formatAmount: currentUD not defined"); + return; + } + var amount = input / currentUD; + if (Math.abs(amount) < minValue && input !== 0) { + amount = '~ 0'; + } + else { + amount = numeral(amount).format(format); + } + if (options && options.currency) { + return amount + ' ' + currencySymbol(options.currency, true); + } + return amount; + } + + function formatQuantitative(input, options) { + var amount = numeral(input/100).format((input > -1000000000 && input < 1000000000) ? '0,0.00' : '0,0.000 a'); + if (options && options.currency) { + return amount + ' ' + currencySymbol(options.currency, false); + } + return amount; + } + + return function(input, options) { + if (input === undefined) return; + return (options && angular.isDefined(options.useRelative) ? options.useRelative : csSettings.data.useRelative) ? + formatRelative(input, options) : + formatQuantitative(input, options); + }; + }) + + .filter('formatAmountNoHtml', function(csConfig, csSettings, csCurrency, $filter) { + var minValue = 1 / Math.pow(10, csConfig.decimalCount || 4); + var format = '0,0.0' + Array(csConfig.decimalCount || 4).join('0'); + var currencySymbol = $filter('currencySymbolNoHtml'); + + function formatRelative(input, options) { + var currentUD = options && options.currentUD ? options.currentUD : csCurrency.data.currentUD; + if (!currentUD) { + console.warn("formatAmount: currentUD not defined"); + return; + } + var amount = input / currentUD; + if (Math.abs(amount) < minValue && input !== 0) { + amount = '~ 0'; + } + else { + amount = numeral(amount).format(format); + } + if (options && options.currency) { + return amount + ' ' + currencySymbol(options.currency, true); + } + return amount; + } + + function formatQuantitative(input, options) { + var amount = numeral(input/100).format((input > -1000000000 && input < 1000000000) ? '0,0.00' : '0,0.000 a'); + if (options && options.currency) { + return amount + ' ' + currencySymbol(options.currency, false); + } + return amount; + } + + return function(input, options) { + if (input === undefined) return; + return (options && angular.isDefined(options.useRelative) ? options.useRelative : csSettings.data.useRelative) ? + formatRelative(input, options) : + formatQuantitative(input, options); + }; + }) + + + .filter('currencySymbol', function(filterTranslations, $filter, csSettings) { + return function(input, useRelative) { + if (!input) return ''; + return (angular.isDefined(useRelative) ? useRelative : csSettings.data.useRelative) ? + (filterTranslations.UD + '<sub>' + $filter('abbreviate')(input) + '</sub>') : + $filter('abbreviate')(input); + }; + }) + + .filter('currencySymbolNoHtml', function(filterTranslations, $filter, csSettings) { + return function(input, useRelative) { + if (!input) return ''; + return (angular.isDefined(useRelative) ? useRelative : csSettings.data.useRelative) ? + (filterTranslations.UD + ' ' + $filter('abbreviate')(input)) : + $filter('abbreviate')(input); + }; + }) + + + .filter('formatDecimal', function(csConfig, csCurrency) { + var minValue = 1 / Math.pow(10, csConfig.decimalCount || 4); + var format = '0,0.0' + Array(csConfig.decimalCount || 4).join('0'); + + return function(input) { + if (input === undefined) return '0'; + if (input === Infinity || input === -Infinity) { + console.warn("formatDecimal: division by zero ? (is currentUD defined ?) = " + csCurrency.data.currentUD); + return 'error'; + } + if (Math.abs(input) < minValue) return '~ 0'; + return numeral(input/*-0.00005*/).format(format); + }; + }) + + .filter('formatNumeral', function() { + return function(input, pattern) { + if (input === undefined) return '0'; + // for DEBUG only + //if (isNaN(input)) { + // return 'NaN'; + //} + if (Math.abs(input) < 0.0001) return '~ 0'; + return numeral(input).format(pattern); + }; + }) + + .filter('formatDate', function(filterTranslations) { + return function(input) { + return input ? moment.unix(parseInt(input)).local().format(filterTranslations.DATE_PATTERN || 'YYYY-MM-DD HH:mm') : ''; + }; + }) + + .filter('formatDateShort', function(filterTranslations) { + return function(input) { + return input ? moment.unix(parseInt(input)).local().format(filterTranslations.DATE_SHORT_PATTERN || 'YYYY-MM-DD') : ''; + }; + }) + + .filter('formatDateMonth', function(filterTranslations) { + return function(input) { + return input ? moment.unix(parseInt(input)).local().format(filterTranslations.DATE_MONTH_YEAR_PATTERN || 'MMM YY') : ''; + }; + }) + + .filter('formatTime', function() { + return function(input) { + return input ? moment.unix(parseInt(input)).local().format('HH:mm') : ''; + }; + }) + + .filter('formatFromNow', function() { + return function(input) { + return input ? moment.unix(parseInt(input)).fromNow() : ''; + }; + }) + + + .filter('formatDurationTo', function() { + return function(input) { + return input ? moment.unix(moment().utc().unix() + parseInt(input)).fromNow() : ''; + }; + }) + + .filter('formatDuration', function() { + return function(input) { + return input ? moment(0).from(moment.unix(parseInt(input)), true) : ''; + }; + }) + + // Display time in ms or seconds (see i18n label 'COMMON.EXECUTION_TIME') + .filter('formatDurationMs', function() { + return function(input) { + return input ? ( + (input < 1000) ? + (input + 'ms') : + (input/1000 + 's') + ) : ''; + }; + }) + + .filter('formatPeriod', function() { + return function(input) { + if (!input) {return null;} + var duration = moment(0).from(moment.unix(parseInt(input)), true); + return duration.split(' ').slice(-1)[0]; // keep only last words (e.g. remove "un" "a"...) + }; + }) + + .filter('formatFromNowShort', function() { + return function(input) { + return input ? moment.unix(parseInt(input)).fromNow(true) : ''; + }; + }) + + .filter('capitalize', function() { + return function(input) { + if (!input) return ''; + input = input.toLowerCase(); + return input.substring(0,1).toUpperCase()+input.substring(1); + }; + }) + + .filter('abbreviate', function() { + var _cache = {}; + return function(input) { + var currency = input || ''; + if (_cache[currency]) return _cache[currency]; + if (currency.length > 3) { + var unit = '', sepChars = ['-', '_', ' ']; + for (var i = 0; i < currency.length; i++) { + var c = currency[i]; + if (i === 0) { + unit = (c === 'g' || c === 'G') ? 'Ğ' : c ; + } + else if (i > 0 && sepChars.indexOf(currency[i-1]) != -1) { + unit += c; + } + } + currency = unit.toUpperCase(); + } + else { + currency = currency.toUpperCase(); + if (currency.charAt(0) === 'G') { + currency = 'Ğ' + (currency.length > 1 ? currency.substr(1) : ''); + } + } + + _cache[input] = currency; + return currency; + }; + }) + + .filter('upper', function() { + return function(input) { + if (!input) return ''; + return input.toUpperCase(); + }; + }) + + .filter('formatPubkey', function() { + return function(input) { + return input ? input.substr(0,8) : ''; + }; + }) + + .filter('formatHash', function() { + return function(input) { + return input ? input.substr(0,4) + input.substr(input.length-4) : ''; + }; + }) + + .filter('formatCategory', function() { + return function(input) { + return input && input.length > 28 ? input.substr(0,25)+'...' : input; + }; + }) + + // Convert to user friendly URL (e.g. "Like - This" -> "like-this") + .filter('formatSlug', function() { + return function(input) { + return input ? encodeURIComponent(input + .toLowerCase() + .replace(/<[^>]+>/g,'') // Remove tag (like HTML tag) + .replace(/[^\w ]+/g,'') + .replace(/ +/g,'-')) + : ''; + }; + }) + + // Convert a URI into parameter (e.g. "http://hos/path" -> "http%3A%2F%2Fhost%2Fpath") + .filter('formatEncodeURI', function() { + return function(input) { + return input ? encodeURIComponent(input): ''; + }; + }) + + .filter('truncText', function() { + return function(input, size) { + size = size || 500; + return !input || input.length <= size ? input : (input.substr(0, size) + '...'); + }; + }) + +; diff --git a/www/js/platform.js b/www/js/platform.js new file mode 100644 index 0000000000000000000000000000000000000000..9ea3fb1db3f78b01c55920c40a16c9dd10d918bf --- /dev/null +++ b/www/js/platform.js @@ -0,0 +1,163 @@ + +angular.module('cesium.platform', ['cesium.config', 'cesium.services']) + + .factory('csPlatform', function (ionicReady, $rootScope, $q, $state, $translate, $timeout, UIUtils, + BMA, Device, csHttp, csConfig, csSettings, csCurrency, csWallet) { + + 'ngInject'; + var + fallbackNodeIndex = 0, + defaultSettingsNode, + started = false, + startPromise, + listeners, + removeChangeStateListener; + + function disableChangeState() { + var remove = $rootScope.$on('$stateChangeStart', function (event, next, nextParams, fromState) { + if (startPromise && next.name !== 'app.home') { + event.preventDefault(); + startPromise.then(function() { + $state.go(next.name, nextParams); + }); + } + }); + + // store remove listener function + removeChangeStateListener = remove; + } + + function enableChangeState() { + if (removeChangeStateListener) removeChangeStateListener(); + removeChangeStateListener = null; + } + + // Alert user if node not reached - fix issue # + function checkBmaNodeAlive(alive) { + if (alive) return true; + + // Remember the default node + defaultSettingsNode = defaultSettingsNode || csSettings.data.node; + + var fallbackNode = csSettings.data.fallbackNodes && fallbackNodeIndex < csSettings.data.fallbackNodes.length && csSettings.data.fallbackNodes[fallbackNodeIndex++]; + if (!fallbackNode) { + return UIUtils.alert.error('ERROR.CHECK_NETWORK_CONNECTION') + .then(function() { + fallbackNodeIndex = 0; + // loop + return BMA.copy(defaultSettingsNode) + .then(checkBmaNodeAlive); + }); + } + var newServer = fallbackNode.host + ((!fallbackNode.port && fallbackNode.port != 80 && fallbackNode.port != 443) ? (':' + fallbackNode.port) : ''); + return $translate('CONFIRM.USE_FALLBACK_NODE', {old: BMA.server, new: newServer}) + .then(function(msg) { + return UIUtils.alert.confirm(msg); + }) + .then(function (confirm) { + if (!confirm) return; + + csSettings.data.node = fallbackNode; + csSettings.data.node.temporary = true; + csHttp.cache.clear(); + + // loop + return BMA.copy(fallbackNode) + .then(checkBmaNodeAlive); + }); + } + + function isStarted() { + return started; + } + + function addListeners() { + listeners = [ + // Listen if node changed + BMA.api.node.on.restart($rootScope, restart, this) + ]; + } + + function removeListeners() { + _.forEach(listeners, function(remove){ + remove(); + }); + listeners = []; + } + + function ready() { + if (started) return $q.when(); + return startPromise || start(); + } + + function restart() { + console.debug('[platform] restarting csPlatform'); + return stop() + .then(function () { + return $timeout(start, 200); + }); + } + + function start() { + // Avoid change state + disableChangeState(); + + // We use 'ionicReady()' instead of '$ionicPlatform.ready()', because this one is callable many times + startPromise = ionicReady() + + .then($q.all([ + // Load device + Device.ready(), + + // Start settings + csSettings.start() + ])) + + // Load BMA + .then(function(){ + return BMA.start().then(checkBmaNodeAlive); + }) + + // Load currency + .then(csCurrency.start) + + // Trying to restore wallet + .then(csWallet.start) + + .then(function(){ + enableChangeState(); + addListeners(); + startPromise = null; + started = true; + }); + + return startPromise; + } + + function stop() { + if (!started) return $q.when(); + removeListeners(); + + csWallet.stop(); + csCurrency.stop(); + BMA.stop(); + + return $timeout(function() { + enableChangeState(); + started = false; + startPromise = null; + }, 500); + } + + // default action + start(); + + + + return { + isStarted: isStarted, + ready: ready, + stop: stop + }; + }) +; diff --git a/www/js/services.js b/www/js/services.js index 56c84de8cb4e2845a0e942409744019ce73d04c9..c1b012d221006f26ed2636451982198a7aae3748 100644 --- a/www/js/services.js +++ b/www/js/services.js @@ -1,5 +1,4 @@ angular.module('cesium.services', [ - 'cesium.config', 'cesium.settings.services', 'cesium.http.services', 'cesium.network.services', diff --git a/www/js/services/bma-services.js b/www/js/services/bma-services.js index 9c0351fe1b3c52c9c47bd7e87757e53d294cbfe0..c632e369aa26ebcbf3890accaf96b30512210512 100644 --- a/www/js/services/bma-services.js +++ b/www/js/services/bma-services.js @@ -1,6 +1,6 @@ //var Base58, Base64, scrypt_module_factory = null, nacl_factory = null; -angular.module('cesium.bma.services', ['ngResource', 'ngApi', 'cesium.http.services', 'cesium.settings.services']) +angular.module('cesium.bma.services', ['ngApi', 'cesium.http.services', 'cesium.settings.services']) .factory('BMA', function($q, $window, $rootScope, $timeout, Api, Device, csConfig, csSettings, csHttp) { 'ngInject'; @@ -271,7 +271,6 @@ angular.module('cesium.bma.services', ['ngResource', 'ngApi', 'cesium.http.servi .then(function(res) { that.alive = res[1]; if (!that.alive) { - // TODO : alert user ? console.error('[BMA] Could not start [{0}]: node unreachable'.format(that.server)); that.started = true; delete that._startPromise; @@ -304,13 +303,18 @@ angular.module('cesium.bma.services', ['ngResource', 'ngApi', 'cesium.http.servi that.restart = function() { csHttp.cache.clear(); that.stop(); - return $timeout(function() { - that.start(); - }, 200); + return $timeout(that.start, 200) + .then(function(alive) { + if (alive) { + that.api.node.raise.restart(); + } + return alive; + }); }; that.api.registerEvent('node', 'start'); that.api.registerEvent('node', 'stop'); + that.api.registerEvent('node', 'restart'); var exports = { errorCodes: errorCodes, @@ -804,7 +808,7 @@ angular.module('cesium.bma.services', ['ngResource', 'ngApi', 'cesium.http.servi }; // default action - service.start(); + //service.start(); return service; }) diff --git a/www/js/services/cache-services.js b/www/js/services/cache-services.js index 24836804067b9b6eab34c1031a58d9f5a65190af..310d58a23a40de888a74e24719ace0e9be6e82bc 100644 --- a/www/js/services/cache-services.js +++ b/www/js/services/cache-services.js @@ -1,4 +1,4 @@ -angular.module('cesium.cache.services', ['ngResource', 'angular-cache']) +angular.module('cesium.cache.services', ['angular-cache']) .factory('csCache', function($http, csSettings, CacheFactory) { 'ngInject'; diff --git a/www/js/services/crypto-services.js b/www/js/services/crypto-services.js index af3291b4695ce9da147e35a05cecb25a2e9cc48d..c93ccaf0dc796a21a6465a6ed0831f343a275f2c 100644 --- a/www/js/services/crypto-services.js +++ b/www/js/services/crypto-services.js @@ -1,6 +1,6 @@ //var Base58, Base64, scrypt_module_factory = null, nacl_factory = null; -angular.module('cesium.crypto.services', ['ngResource', 'cesium.device.services']) +angular.module('cesium.crypto.services', ['cesium.utils.services']) .factory('CryptoUtils', function($q, $timeout, ionicReady) { 'ngInject'; @@ -629,6 +629,8 @@ angular.module('cesium.crypto.services', ['ngResource', 'cesium.device.services' isDevice = false; // endRemoveIf(device) + console.debug("[crypto] Created CyprotUils service. device=" + isDevice); + ionicReady().then(function() { console.debug('[crypto] Starting...'); var now = new Date().getTime(); diff --git a/www/js/services/currency-services.js b/www/js/services/currency-services.js index c2818e68513c587e9a48e8c3de7dd1645df47952..15a06d087a8aaaa59bd5b975b429cf4145ab9113 100644 --- a/www/js/services/currency-services.js +++ b/www/js/services/currency-services.js @@ -1,7 +1,7 @@ -angular.module('cesium.currency.services', ['ngResource', 'ngApi', 'cesium.bma.services']) +angular.module('cesium.currency.services', ['ngApi', 'cesium.bma.services']) -.factory('csCurrency', function($q, BMA, Api) { +.factory('csCurrency', function($rootScope, $q, $timeout, BMA, Api) { 'ngInject'; function factory(id, BMA) { @@ -16,6 +16,9 @@ angular.module('cesium.currency.services', ['ngResource', 'ngApi', 'cesium.bma.s }, data = {}, + started = false, + startPromise, + listeners, api = new Api(this, "csCurrency-" + id); function powBase(amount, base) { @@ -23,7 +26,6 @@ angular.module('cesium.currency.services', ['ngResource', 'ngApi', 'cesium.bma.s } function resetData() { - data.loaded = false; data.name = null; data.parameters = null; data.firstBlockTime = null; @@ -31,16 +33,15 @@ angular.module('cesium.currency.services', ['ngResource', 'ngApi', 'cesium.bma.s data.cache = {}; data.node = BMA; data.currentUD = null; + started = false; + startPromise = undefined; api.data.raise.reset(data); } function loadData() { - console.debug('[currency] Starting...'); - var now = new Date().getTime(); - // Load currency from default node - data.cache.loadPromise = $q.all([ + return $q.all([ // get parameters loadParameters() @@ -55,18 +56,10 @@ angular.module('cesium.currency.services', ['ngResource', 'ngApi', 'cesium.bma.s // call extensions api.data.raisePromise.load(data) ]) - .then(function() { - console.debug('[currency] Loaded in ' + (new Date().getTime() - now) + 'ms'); - data.loaded = true; - delete data.cache.loadPromise; - return data; - }) - .catch(function(err) { - resetData(); - throw err; - }); - - return data.cache.loadPromise; + .catch(function(err) { + resetData(); + throw err; + }); } function loadParameters() { @@ -94,6 +87,8 @@ angular.module('cesium.currency.services', ['ngResource', 'ngApi', 'cesium.bma.s // Special case, when currency not started yet if (err && err.ucode === BMA.errorCodes.BLOCK_NOT_FOUND) { data.firstBlockTime = 0; + data.initPhase = true; + console.warn('[currency] Blockchain not launched: Enable init phase mode'); return; } throw err; @@ -129,48 +124,104 @@ angular.module('cesium.currency.services', ['ngResource', 'ngApi', 'cesium.bma.s } function getData() { - if (data.loaded) { // load only once + if (started) { // load only once return $q.when(data); } // Previous load not finished: return the existing promise - fix #452 - if (data.cache.loadPromise) { // load only once - return $q.when(data.cache.loadPromise); - } - - return loadData(); + return startPromise || start(); } function getDataField(field) { return function() { - if (data.loaded) { // load only once + if (started) { // load only once return $q.when(data[field]); } // Previous load not finished: return the existing promise - fix #452 - if (data.cache.loadPromise) { // load only once - return $q.when(data.cache.loadPromise) + return startPromise || start() // load only once .then(function(){ return data[field]; }); - } + }; + } - return loadData().then(function(){ - return data[field]; + function addListeners() { + listeners = [ + // Listen if node changed + BMA.api.node.on.restart($rootScope, restart, this) + ]; + } + + function removeListeners() { + _.forEach(listeners, function(remove){ + remove(); + }); + listeners = []; + } + + function ready() { + if (started) return $q.when(data); + return startPromise || start(); + } + + function stop() { + console.debug('[currency] Stopping...'); + removeListeners(); + resetData(); + } + + function restart() { + stop(); + return $timeout(start, 200); + } + + function start() { + console.debug('[currency] Starting...'); + var now = new Date().getTime(); + + startPromise = BMA.ready() + + // Load data + .then(loadData) + + // Emit ready event + .then(function() { + addListeners(); + + console.debug('[currency] Started in ' + (new Date().getTime() - now) + 'ms'); + + started = true; + startPromise = null; + + // Emit event (used by plugins) + api.data.raise.ready(data); + }) + .then(function(){ + return data; }); - }; + + return startPromise; } // TODO register new block event, to get new UD value // Register extension points + api.registerEvent('data', 'ready'); api.registerEvent('data', 'load'); api.registerEvent('data', 'reset'); // init data resetData(); + // Default action + //start(); + return { + ready: ready, + start: start, + stop: stop, + data: data, get: getData, parameters: getDataField('parameters'), currentUD: getDataField('currentUD'), diff --git a/www/js/services/device-services.js b/www/js/services/device-services.js index d3e950365ea8b6a2d57320754104827779c09656..f4ea519633a63ca3dbabd584823117cf9b21100e 100644 --- a/www/js/services/device-services.js +++ b/www/js/services/device-services.js @@ -1,25 +1,12 @@ -angular.module('cesium.device.services', ['ngResource', 'cesium.utils.services', 'cesium.settings.services']) - - // Replace the '$ionicPlatform.ready()', to enable multiple calls - // See http://stealthcode.co/multiple-calls-to-ionicplatform-ready/ - .factory('ionicReady', function($ionicPlatform) { - var readyPromise; - - return function () { - if (!readyPromise) { - readyPromise = $ionicPlatform.ready(); - } - return readyPromise; - }; - }) +angular.module('cesium.device.services', ['cesium.utils.services', 'cesium.settings.services']) .factory('Device', function($translate, $ionicPopup, $q, // removeIf(no-device) $cordovaClipboard, $cordovaBarcodeScanner, $cordovaCamera, // endRemoveIf(no-device) - ionicReady, csSettings) { + ionicReady) { 'ngInject'; var @@ -30,7 +17,9 @@ angular.module('cesium.device.services', ['ngResource', 'cesium.utils.services', exports = { // workaround to quickly no is device or not (even before the ready() event) enable: true - }; + }, + started = false, + startPromise; // removeIf(device) // workaround to quickly no is device or not (even before the ready() event) @@ -39,7 +28,7 @@ angular.module('cesium.device.services', ['ngResource', 'cesium.utils.services', function getPicture(options) { if (!exports.camera.enable) { - return $q.reject("Camera not enable. Please call 'Device.ready()' once before use (e.g in app.js)."); + return $q.reject("Camera not enable. Please call 'ionicReady()' once before use (e.g in app.js)."); } // Options is the sourceType by default @@ -91,7 +80,7 @@ angular.module('cesium.device.services', ['ngResource', 'cesium.utils.services', function scan(n) { if (!exports.enable) { - return $q.reject("Barcode scanner not enable. Please call 'Device.ready()' once before use (e.g in app.js)."); + return $q.reject("Barcode scanner not enable. Please call 'ionicReady()' once before use (e.g in app.js)."); } var deferred = $q.defer(); cordova.plugins.barcodeScanner.scan( @@ -150,46 +139,43 @@ angular.module('cesium.device.services', ['ngResource', 'cesium.utils.services', } }; - var started = false; - var startPromise = ionicReady().then(function(){ + exports.ready = function() { + if (started) return $q.when(); + return startPromise || exports.start(); + }; - exports.enable = window.cordova && cordova && cordova.plugins; + exports.start = function() { - if (exports.enable){ - exports.camera.enable = !!navigator.camera; - exports.keyboard.enable = cordova && cordova.plugins && !!cordova.plugins.Keyboard; - exports.barcode.enable = cordova && cordova.plugins && !!cordova.plugins.barcodeScanner; + var startPromise = ionicReady() + .then(function(){ - if (exports.keyboard.enable) { - angular.extend(exports.keyboard, cordova.plugins.Keyboard); - } + exports.enable = window.cordova && cordova && cordova.plugins; - console.debug('[device] Ionic platform ready, with [camera: {0}] [barcode scanner: {1}] [keyboard: {2}]' - .format(exports.camera.enable, exports.barcode.enable, exports.keyboard.enable)); + if (exports.enable){ + exports.camera.enable = !!navigator.camera; + exports.keyboard.enable = cordova && cordova.plugins && !!cordova.plugins.Keyboard; + exports.barcode.enable = cordova && cordova.plugins && !!cordova.plugins.barcodeScanner; - if (cordova.InAppBrowser) { - console.debug('[device] Enabling InAppBrowser'); - } - } - else { - console.debug('[device] Ionic platform ready - no device detected.'); - } + if (exports.keyboard.enable) { + angular.extend(exports.keyboard, cordova.plugins.Keyboard); + } - started = true; - startPromise = null; - }); + console.debug('[device] Ionic platform ready, with [camera: {0}] [barcode scanner: {1}] [keyboard: {2}]' + .format(exports.camera.enable, exports.barcode.enable, exports.keyboard.enable)); + + if (cordova.InAppBrowser) { + console.debug('[device] Enabling InAppBrowser'); + } + } + else { + console.debug('[device] Ionic platform ready - no device detected.'); + } - var readyPromise; + started = true; + startPromise = null; + }); - // backward compat - exports.ready = function () { - if (!readyPromise) { - readyPromise = $q.all([ - ionicReady(), - csSettings.ready() - ]); - } - return readyPromise; + return startPromise; }; return exports; diff --git a/www/js/services/http-services.js b/www/js/services/http-services.js index 6b108af58576f3e4b0415db21cf66d4ff0cae261..b0c720505ecbdaeafe0588417f13d1345d307ae8 100644 --- a/www/js/services/http-services.js +++ b/www/js/services/http-services.js @@ -1,4 +1,4 @@ -angular.module('cesium.http.services', ['ngResource', 'cesium.cache.services']) +angular.module('cesium.http.services', ['cesium.cache.services']) .factory('csHttp', function($http, $q, csSettings, csCache, $timeout) { 'ngInject'; diff --git a/www/js/services/network-services.js b/www/js/services/network-services.js index 7a784f8b400eb53de275b835ba82bc12825d4a72..843db537abd2e4b9b7e75b9ba3a33982bc1c7d20 100644 --- a/www/js/services/network-services.js +++ b/www/js/services/network-services.js @@ -1,5 +1,5 @@ -angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.services', 'cesium.http.services']) +angular.module('cesium.network.services', ['ngApi', 'cesium.bma.services', 'cesium.http.services']) .factory('csNetwork', function($rootScope, $q, $interval, $timeout, $window, BMA, csHttp, Api) { 'ngInject'; diff --git a/www/js/services/settings-services.js b/www/js/services/settings-services.js index aaff0d30160325857533289517cd10b7e39028c0..e4fb89690b454a4137c7b5e9cf4ee910911dada4 100644 --- a/www/js/services/settings-services.js +++ b/www/js/services/settings-services.js @@ -1,5 +1,5 @@ -angular.module('cesium.settings.services', ['ngResource', 'ngApi', 'cesium.config']) +angular.module('cesium.settings.services', ['ngApi', 'cesium.config']) .factory('csSettings', function($rootScope, $q, Api, localStorage, $translate, csConfig) { 'ngInject'; @@ -62,7 +62,6 @@ angular.module('cesium.settings.services', ['ngResource', 'ngApi', 'cesium.confi logoutIdle: 10 * 60, // 10min - override to false if no device showUDHistory: true, showLoginSalt: false, - initPhase: false, // For currency start (when block #0 not written) httpsMode: false, expertMode: false, decimalCount: 4, @@ -142,12 +141,24 @@ angular.module('cesium.settings.services', ['ngResource', 'ngApi', 'cesium.confi store = function() { if (!started) { console.debug('[setting] Waiting start finished...'); - return startPromise.then(store); + return (startPromise || start()).then(store); } var promise; if (data.useLocalStorage) { - promise = localStorage.setObject(constants.STORAGE_KEY, data); + // When node is temporary (fallback node): keep previous node address - issue #476 + if (data.node.temporary === true) { + promise = localStorage.getObject(constants.STORAGE_KEY) + .then(function(previousSettings) { + var savedData = angular.copy(data); + savedData.node = previousSettings && previousSettings.node || {}; + delete savedData.temporary; // never store temporary flag + return localStorage.setObject(constants.STORAGE_KEY, savedData); + }); + } + else { + promise = localStorage.setObject(constants.STORAGE_KEY, data); + } } else { promise = localStorage.setObject(constants.STORAGE_KEY, null); @@ -283,10 +294,11 @@ angular.module('cesium.settings.services', ['ngResource', 'ngApi', 'cesium.confi applyData(defaultSettings); // Default action - start(); + //start(); return { ready: ready, + start: start, data: data, getByPath: getByPath, reset: reset, diff --git a/www/js/services/storage-services.js b/www/js/services/storage-services.js index 4075118f62f023c6a07050f92defa141ea7d4ded..31e5abd5671fc5d2be936a4276e772f47603c1f2 100644 --- a/www/js/services/storage-services.js +++ b/www/js/services/storage-services.js @@ -1,4 +1,4 @@ -angular.module('cesium.storage.services', ['ngResource', 'ngApi', 'cesium.config']) +angular.module('cesium.storage.services', ['ngApi', 'cesium.config']) .factory('localStorage', function($window, $q, $rootScope, $timeout, csConfig, Api) { 'ngInject'; @@ -114,24 +114,27 @@ angular.module('cesium.storage.services', ['ngResource', 'ngApi', 'cesium.config exports[key] = exports.secure[key]; }); + var deferred = $q.defer(); // No secure storage plugin: fall back to standard storage if (!cordova.plugins || !cordova.plugins.SecureStorage) { console.debug('[storage] No cordova plugin. Will use standard....'); - return initStandardStorage(); + initStandardStorage(); + deferred.resolve(); } + else { - var deferred = $q.defer(); - exports.secure.storage = new cordova.plugins.SecureStorage( - function () { - deferred.resolve(); - }, - function (err) { - console.error('[storage] Could not use secure storage. Will use standard.', err); - deferred.promise.then(initStandardStorage); - deferred.resolve(); - }, - appName); + exports.secure.storage = new cordova.plugins.SecureStorage( + function () { + deferred.resolve(); + }, + function (err) { + console.error('[storage] Could not use secure storage. Will use standard.', err); + initStandardStorage(); + deferred.resolve(); + }, + appName); + } return deferred.promise; } @@ -140,7 +143,6 @@ angular.module('cesium.storage.services', ['ngResource', 'ngApi', 'cesium.config }; exports.ready = function() { - console.debug("[storage] Calling ready()"); if (started) return $q.when(); return startPromise || start(); }; @@ -152,7 +154,7 @@ angular.module('cesium.storage.services', ['ngResource', 'ngApi', 'cesium.config // Use Cordova secure storage plugin if (isDevice) { - console.debug("[storage] Staring secure storage..."); + console.debug("[storage] Starting secure storage..."); startPromise = initSecureStorage(); } diff --git a/www/js/services/tx-services.js b/www/js/services/tx-services.js index 590caf27a09589e6bd8c1f830fae7c867419918f..33fb1a6a34f1d641e951f3012681599e9299d3ee 100644 --- a/www/js/services/tx-services.js +++ b/www/js/services/tx-services.js @@ -1,5 +1,5 @@ -angular.module('cesium.tx.services', ['ngResource', 'ngApi', 'cesium.bma.services', +angular.module('cesium.tx.services', ['ngApi', 'cesium.bma.services', 'cesium.settings.services', 'cesium.wot.services' ]) .factory('csTx', function($q, $timeout, BMA, Api, csConfig, csSettings, csWot) { diff --git a/www/js/services/utils-services.js b/www/js/services/utils-services.js index 5d9a4dc7636c1346bd1df3c74cbc608781500971..d8a60d4c9285bf33e017254b4def453ddb8af487 100644 --- a/www/js/services/utils-services.js +++ b/www/js/services/utils-services.js @@ -1,5 +1,20 @@ angular.module('cesium.utils.services', ['ngResource']) +// Replace the '$ionicPlatform.ready()', to enable multiple calls +// See http://stealthcode.co/multiple-calls-to-ionicplatform-ready/ +.factory('ionicReady', function($ionicPlatform) { + 'ngInject'; + + var readyPromise; + + return function () { + if (!readyPromise) { + readyPromise = $ionicPlatform.ready(); + } + return readyPromise; + }; +}) + .factory('UIUtils', function($ionicLoading, $ionicPopup, $ionicConfig, $translate, $q, ionicMaterialInk, ionicMaterialMotion, $window, $timeout, // removeIf(no-device) $cordovaToast, diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index f85e43b8fd266089a4f32db8c29eb86e1914adb9..ff4a3f2c69e8fb47393526a3f5228c5a8851ce12 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -1,5 +1,5 @@ -angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.services', 'cesium.crypto.services', 'cesium.utils.services', +angular.module('cesium.wallet.services', ['ngApi', 'cesium.bma.services', 'cesium.crypto.services', 'cesium.utils.services', 'cesium.settings.services']) @@ -20,7 +20,9 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser REVOKE_VERSION: csConfig.compatProtocol_0_80 ? 2 : BMA.constants.PROTOCOL_VERSION }, data = {}, - + listeners, + started, + startPromise, api = new Api(this, 'csWallet-' + id), resetData = function(init) { @@ -45,6 +47,9 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser resetTxAndSources(); + started = false; + startPromise = undefined; + if (init) { api.data.raise.init(data); } @@ -371,7 +376,7 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser return csCurrency.get() .then(function(currency){ data.currency = currency.name; - data.parameters =currency.parameters; + data.parameters = currency.parameters; data.currentUD = currency.currentUD; }) .catch(function(err) { @@ -1294,16 +1299,6 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser },[]); }, - /** - * Serialize to JSON string - */ - toJson = function() { - return $q(function(resolve, reject) { - var json = JSON.stringify(data); - resolve(json); - }); - }, - /** * De-serialize from JSON string */ @@ -1360,7 +1355,79 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser } ; + function addListeners() { + listeners = [ + // Listen if settings changed + csSettings.api.data.on.changed($rootScope, store, this), + // Listen if node changed + BMA.api.node.on.restart($rootScope, restart, this) + ]; + } + + function removeListeners() { + _.forEach(listeners, function(remove){ + remove(); + }); + listeners = []; + } + + function ready() { + if (started) return $q.when(); + return startPromise || start(); + } + + function stop() { + console.debug('[wallet] Stopping...'); + removeListeners(); + resetData(); + } + + function restart() { + stop(); + return $timeout(start, 200); + } + + function start() { + console.debug('[wallet] Starting...'); + var now = new Date().getTime(); + + startPromise = $q.all([ + csSettings.ready(), + csCurrency.ready(), + BMA.ready() + ]) + + // Restore + .then(restore) + + // Load data (if a wallet restored) + .then(function(data) { + if (data && data.pubkey) { + return loadData({minData: true}); + } + }) + + // Emit ready event + .then(function() { + addListeners(); + + console.debug('[wallet] Started in ' + (new Date().getTime() - now) + 'ms'); + + started = true; + startPromise = null; + + // Emit event (used by plugins) + api.data.raise.ready(data); + }) + .then(function(){ + return data; + }); + + return startPromise; + } + // Register extension points + api.registerEvent('data', 'ready'); api.registerEvent('data', 'init'); api.registerEvent('data', 'login'); api.registerEvent('data', 'load'); @@ -1369,14 +1436,15 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser api.registerEvent('data', 'reset'); api.registerEvent('action', 'certify'); - csSettings.api.data.on.changed($rootScope, store); - // init data resetData(true); return { id: id, data: data, + ready: ready, + start: start, + stop: stop, // auth login: login, logout: logout, @@ -1393,6 +1461,7 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser self: self, revoke: revoke, revokeWithFile: revokeWithFile, + certify: certify, downloadSaveId: downloadSaveId, getCryptedId: getCryptedId, recoverId: recoverId, @@ -1405,12 +1474,6 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser add: addEvent, cleanByContext: cleanEventsByContext }, - certify: certify, - store: store, - restore: restore, - // serialization - toJson: toJson, - fromJson: fromJson, api: api }; } diff --git a/www/js/services/wot-services.js b/www/js/services/wot-services.js index ce2f414a7d54c3ffd5597d6da082d7df9b19320d..6e34e2e9dedba831508734360b2d0b14e583e0fd 100644 --- a/www/js/services/wot-services.js +++ b/www/js/services/wot-services.js @@ -1,8 +1,8 @@ -angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.services', 'cesium.crypto.services', 'cesium.utils.services', +angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.crypto.services', 'cesium.utils.services', 'cesium.settings.services']) -.factory('csWot', function($q, $timeout, BMA, Api, CacheFactory, csConfig, csSettings, csCache) { +.factory('csWot', function($q, $timeout, BMA, Api, CacheFactory, csConfig, csCurrency, csSettings, csCache) { 'ngInject'; function factory(id) { @@ -351,7 +351,7 @@ angular.module('cesium.wot.services', ['ngResource', 'ngApi', 'cesium.bma.servic if (!pendingCertifications.length) return certifications; // No more pending continue // Special case for initPhase - issue # - if (csConfig.initPhase) { + if (csCurrency.data.initPhase) { return pendingCertifications.reduce(function(res, cert) { return res.concat({ pubkey: cert.pubkey, diff --git a/www/js/sync-storage.js b/www/js/sync-storage.js deleted file mode 100644 index 3b93568b2a2b4579866eeb991d9929ee74426978..0000000000000000000000000000000000000000 --- a/www/js/sync-storage.js +++ /dev/null @@ -1,7 +0,0 @@ -window.addEventListener('message', function(event) { - console.log('[HTTPS frame] ', event); - alert('Received ' + event); -}); - - -alert('get ready !'); diff --git a/www/plugins/es/js/controllers/wallet-controllers.js b/www/plugins/es/js/controllers/wallet-controllers.js index 91f8996be0c3872e59082d335bebe2707410b369..276cbe2e784712177097ec84874d22e066245f23 100644 --- a/www/plugins/es/js/controllers/wallet-controllers.js +++ b/www/plugins/es/js/controllers/wallet-controllers.js @@ -18,17 +18,5 @@ angular.module('cesium.es.wallet.controllers', ['cesium.es.services']) }) - .controller('ESWalletCtrl', ESWalletViewController) - ; -function ESWalletViewController($scope, esSettings) { - 'ngInject'; - - $scope.enable = esSettings.isEnable(); - - esSettings.api.state.on.changed($scope, function(enable) { - $scope.enable = enable; - }); - -} diff --git a/www/plugins/es/js/services/group-services.js b/www/plugins/es/js/services/group-services.js index ebcf4df2c0ed5795ce5442832741d1a9960aebf9..2a796181c65f37ebe728972c16396f637ac96481 100644 --- a/www/plugins/es/js/services/group-services.js +++ b/www/plugins/es/js/services/group-services.js @@ -1,4 +1,4 @@ -angular.module('cesium.es.group.services', ['ngResource', 'cesium.services', 'cesium.es.http.services', +angular.module('cesium.es.group.services', ['ngResource', 'cesium.platform', 'cesium.es.http.services', 'cesium.es.user.services', 'cesium.es.notification.services', 'cesium.es.comment.services']) .config(function(PluginServiceProvider, csConfig) { 'ngInject'; @@ -11,7 +11,7 @@ angular.module('cesium.es.group.services', ['ngResource', 'cesium.services', 'ce }) -.factory('esGroup', function($q, $rootScope, Device, csSettings, esHttp, CryptoUtils, esUser, csWallet, esNotification, esComment) { +.factory('esGroup', function($q, $rootScope, csPlatform, csSettings, esHttp, CryptoUtils, esUser, csWallet, esNotification, esComment) { 'ngInject'; function EsGroup() { @@ -204,7 +204,7 @@ angular.module('cesium.es.group.services', ['ngResource', 'cesium.services', 'ce } // Default actions - Device.ready().then(function() { + csPlatform.ready().then(function() { esHttp.api.node.on.start($rootScope, refreshState, this); esHttp.api.node.on.stop($rootScope, refreshState, this); return refreshState(); diff --git a/www/plugins/es/js/services/http-services.js b/www/plugins/es/js/services/http-services.js index 1effb79c4119e064617e2e729ed4b8a30d93f895..3cfb9aaa5274e6b00ff2f0b5f3b8d58f2d7ddccf 100644 --- a/www/plugins/es/js/services/http-services.js +++ b/www/plugins/es/js/services/http-services.js @@ -3,7 +3,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic /** * Elastic Search Http */ -.factory('esHttp', function($q, $timeout, $rootScope, $state, $sce, CryptoUtils, csHttp, csConfig, csSettings, BMA, csWallet, Api) { +.factory('esHttp', function($q, $timeout, $rootScope, $state, $sce, CryptoUtils, csHttp, csConfig, csSettings, BMA, csWallet, csPlatform, Api) { 'ngInject'; function Factory(host, port, wsPort, useSsl) { @@ -119,8 +119,8 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic that.start = function() { - return csSettings.ready() - .then(service.init) + return csPlatform.ready() + .then(that.init) .then(function() { console.debug('[ES] [http] Starting on [{0}]...'.format(that.server)); var now = new Date().getTime(); @@ -148,9 +148,7 @@ angular.module('cesium.es.http.services', ['ngResource', 'ngApi', 'cesium.servic that.restart = function() { that.stop(); - return $timeout(function() { - that.start(); - }, 200); + return $timeout(that.start, 200); }; function parseTagsFromText(value, prefix) { diff --git a/www/plugins/es/js/services/invitation-services.js b/www/plugins/es/js/services/invitation-services.js index 4278909e73319bd8f961fe154dee901055b769f8..99ec0291499e5e6d9813c7dd6f56efb2d3f300e4 100644 --- a/www/plugins/es/js/services/invitation-services.js +++ b/www/plugins/es/js/services/invitation-services.js @@ -1,4 +1,4 @@ -angular.module('cesium.es.invitation.services', ['cesium.crypto.services', 'cesium.device.services', 'cesium.wallet.services', 'cesium.wot.services', +angular.module('cesium.es.invitation.services', ['cesium.platform', 'cesium.es.http.services', 'cesium.es.wallet.services', 'cesium.es.notification.services']) .config(function(PluginServiceProvider, csConfig) { @@ -12,7 +12,7 @@ angular.module('cesium.es.invitation.services', ['cesium.crypto.services', 'cesi }) -.factory('esInvitation', function($rootScope, $q, CryptoUtils, Device, Api, esHttp, csWallet, esWallet, csWot, esNotification) { +.factory('esInvitation', function($rootScope, $q, CryptoUtils, csPlatform, Api, esHttp, csWallet, esWallet, csWot, esNotification) { 'ngInject'; var @@ -363,7 +363,7 @@ angular.module('cesium.es.invitation.services', ['cesium.crypto.services', 'cesi api.registerEvent('data', 'new'); // Default action - Device.ready().then(function() { + csPlatform.ready().then(function() { esHttp.api.node.on.start($rootScope, refreshState, this); esHttp.api.node.on.stop($rootScope, refreshState, this); return refreshState(); diff --git a/www/plugins/es/js/services/message-services.js b/www/plugins/es/js/services/message-services.js index eb9fb301d271c8410a6ee622fc149829c6bb5aed..51a35cbec4a862d7e125c7919cff978873a17e04 100644 --- a/www/plugins/es/js/services/message-services.js +++ b/www/plugins/es/js/services/message-services.js @@ -1,4 +1,4 @@ -angular.module('cesium.es.message.services', ['ngResource', 'cesium.services', 'cesium.crypto.services', 'cesium.wot.services', +angular.module('cesium.es.message.services', ['ngResource', 'cesium.platform', 'cesium.es.http.services', 'cesium.es.wallet.services', 'cesium.es.notification.services']) .config(function(PluginServiceProvider, csConfig) { 'ngInject'; @@ -11,7 +11,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.services', ' }) -.factory('esMessage', function($q, $rootScope, Api, CryptoUtils, Device, csSettings, esHttp, csWallet, esWallet, csWot, esNotification) { +.factory('esMessage', function($q, $rootScope, Api, CryptoUtils, csPlatform, csSettings, esHttp, csWallet, esWallet, csWot, esNotification) { 'ngInject'; var @@ -469,7 +469,7 @@ angular.module('cesium.es.message.services', ['ngResource', 'cesium.services', ' api.registerEvent('data', 'new'); // Default action - Device.ready().then(function() { + csPlatform.ready().then(function() { esHttp.api.node.on.start($rootScope, refreshState, this); esHttp.api.node.on.stop($rootScope, refreshState, this); return refreshState(); diff --git a/www/plugins/es/js/services/notification-services.js b/www/plugins/es/js/services/notification-services.js index b49c94980ce9f2c82cda98af093c670b69f326fe..54e6a7e4e0d63ae950fdaadca1ed7f4c29fb8e60 100644 --- a/www/plugins/es/js/services/notification-services.js +++ b/www/plugins/es/js/services/notification-services.js @@ -1,4 +1,4 @@ -angular.module('cesium.es.notification.services', ['cesium.services', 'cesium.es.http.services']) +angular.module('cesium.es.notification.services', ['cesium.platform', 'cesium.es.http.services']) .config(function(PluginServiceProvider, csConfig) { 'ngInject'; @@ -10,7 +10,7 @@ angular.module('cesium.es.notification.services', ['cesium.services', 'cesium.es }) -.factory('esNotification', function($rootScope, $q, $timeout, esHttp, csConfig, csSettings, csWallet, csWot, UIUtils, BMA, CryptoUtils, Device, Api, esUser) { +.factory('esNotification', function($rootScope, $q, $timeout, esHttp, csConfig, csSettings, csWallet, csWot, UIUtils, BMA, CryptoUtils, csPlatform, Api, esUser) { 'ngInject'; var @@ -278,7 +278,7 @@ angular.module('cesium.es.notification.services', ['cesium.services', 'cesium.es api.registerEvent('event', 'newMessage'); // Default actions - Device.ready().then(function() { + csPlatform.ready().then(function() { esHttp.api.node.on.start($rootScope, refreshState, this); esHttp.api.node.on.stop($rootScope, refreshState, this); return refreshState(); diff --git a/www/plugins/es/js/services/settings-services.js b/www/plugins/es/js/services/settings-services.js index 8694ea926781ca401e33aa17e70dc4fc061e81fc..1743fb02b06a4bab283bcd909c71f747bea8ac33 100644 --- a/www/plugins/es/js/services/settings-services.js +++ b/www/plugins/es/js/services/settings-services.js @@ -123,7 +123,7 @@ angular.module('cesium.es.settings.services', ['cesium.services', 'cesium.es.htt var settings = JSON.parse(json || '{}'); settings.time = record.time; console.debug('[ES] [settings] Loaded user settings in '+ (new Date().getTime()-now) +'ms'); - console.log(settings); + console.debug(settings); return settings; }) // if error: skip stored content @@ -299,7 +299,6 @@ angular.module('cesium.es.settings.services', ['cesium.services', 'cesium.es.htt console.debug("[ES] [settings] Disable"); removeListeners(); - // Force ES node to stop return esHttp.stop() .then(function() { diff --git a/www/plugins/es/js/services/subscription-services.js b/www/plugins/es/js/services/subscription-services.js index 98bcc1fa819dbfd7bfc7c0e5101e33b512753f28..078bf87f79ad332eb7c459757ddc192f43f939fe 100644 --- a/www/plugins/es/js/services/subscription-services.js +++ b/www/plugins/es/js/services/subscription-services.js @@ -1,4 +1,4 @@ -angular.module('cesium.es.subscription.services', ['cesium.services', 'cesium.es.http.services']) +angular.module('cesium.es.subscription.services', ['cesium.platform', 'cesium.es.http.services']) .config(function(PluginServiceProvider, csConfig) { 'ngInject'; @@ -11,7 +11,7 @@ angular.module('cesium.es.subscription.services', ['cesium.services', 'cesium.es }) .factory('esSubscription', function($rootScope, $q, $timeout, esHttp, $state, $sce, $sanitize, - esSettings, CryptoUtils, UIUtils, csWallet, csWot, BMA, Device, esWallet) { + esSettings, CryptoUtils, UIUtils, csWallet, csWot, BMA, csPlatform, esWallet) { 'ngInject'; var constants = { @@ -213,7 +213,7 @@ angular.module('cesium.es.subscription.services', ['cesium.services', 'cesium.es } // Default actions - Device.ready().then(function() { + csPlatform.ready().then(function() { esHttp.api.node.on.start($rootScope, refreshState, this); esHttp.api.node.on.stop($rootScope, refreshState, this); return refreshState(); diff --git a/www/plugins/es/js/services/user-services.js b/www/plugins/es/js/services/user-services.js index 841068e60011b1a950ffacc4f2996f0e06de93cc..39b32e3d96e8f48294cd8fc3eb36773c5dbd7906 100644 --- a/www/plugins/es/js/services/user-services.js +++ b/www/plugins/es/js/services/user-services.js @@ -1,4 +1,4 @@ -angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.services']) +angular.module('cesium.es.user.services', ['cesium.platform', 'cesium.es.http.services']) .config(function(PluginServiceProvider, csConfig) { 'ngInject'; @@ -11,7 +11,7 @@ angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.se }) .factory('esUser', function($rootScope, $q, $timeout, esHttp, $state, $sce, $sanitize, - esSettings, CryptoUtils, UIUtils, csWallet, csWot, BMA, Device) { + esSettings, CryptoUtils, UIUtils, csWallet, csWot, csPlatform) { 'ngInject'; var constants = { @@ -407,7 +407,7 @@ angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.se } // Default actions - Device.ready().then(function() { + csPlatform.ready().then(function() { esHttp.api.node.on.start($rootScope, refreshState, this); esHttp.api.node.on.stop($rootScope, refreshState, this); return refreshState(); diff --git a/www/plugins/es/js/services/wallet-services.js b/www/plugins/es/js/services/wallet-services.js index 9237f528e85e46345b02afcf8f6c77f8167f009a..40465f364de8e28c777b949046c519ee7c6aba24 100644 --- a/www/plugins/es/js/services/wallet-services.js +++ b/www/plugins/es/js/services/wallet-services.js @@ -1,7 +1,6 @@ -angular.module('cesium.es.wallet.services', ['ngResource', 'cesium.wallet.services', 'cesium.device.services', 'cesium.crypto.services', - 'cesium.es.http.services']) +angular.module('cesium.es.wallet.services', ['ngResource', 'cesium.platform', 'cesium.es.http.services']) -.factory('esWallet', function($q, $rootScope, CryptoUtils, Device, csWallet, esHttp) { +.factory('esWallet', function($q, $rootScope, CryptoUtils, csPlatform, csWallet, esHttp) { 'ngInject'; var @@ -177,7 +176,7 @@ angular.module('cesium.es.wallet.services', ['ngResource', 'cesium.wallet.servic } // Default action - Device.ready().then(function() { + csPlatform.ready().then(function() { esHttp.api.node.on.start($rootScope, refreshState, this); esHttp.api.node.on.stop($rootScope, refreshState, this); return refreshState(); diff --git a/www/plugins/es/templates/user/items_profile.html b/www/plugins/es/templates/user/items_profile.html index 156ab2d26929287b41d858ded1a0895aeb10d441..59911da7c26461b35ae0bdf1fe70323c7a8ac34e 100644 --- a/www/plugins/es/templates/user/items_profile.html +++ b/www/plugins/es/templates/user/items_profile.html @@ -1,4 +1,4 @@ -<div ng-if="!formData.profile" +<div ng-if="!formData.profile && !formData.name" class="item gray" translate>PROFILE.NO_PROFILE_DEFINED</div> <!-- name --> diff --git a/www/plugins/es/templates/wallet/view_wallet_extend.html b/www/plugins/es/templates/wallet/view_wallet_extend.html index ea8e02f0c1007789bcadcf6b18f9d740a31192e6..00926f0e1e611c60979fdcf3fdc89f87444f2d1d 100644 --- a/www/plugins/es/templates/wallet/view_wallet_extend.html +++ b/www/plugins/es/templates/wallet/view_wallet_extend.html @@ -1,37 +1,39 @@ -<!-- profile --> -<div class="item item-divider item-divider-top-border"> - {{'PROFILE.PROFILE_DIVIDER' | translate}} - <a class="badge button button-text button-small button-small-padding " - ui-sref="app.user_edit_profile"> - <i class="icon ion-edit"></i> - <span ng-if="!formData.profile" translate>PROFILE.BTN_ADD</span> - <span ng-if="formData.profile" translate>PROFILE.BTN_EDIT</span> - </a> -</div> +<ng-if ng-if="enable"> + <!-- profile --> + <div class="item item-divider item-divider-top-border"> + {{'PROFILE.PROFILE_DIVIDER' | translate}} + <a class="badge button button-text button-small button-small-padding " + ui-sref="app.user_edit_profile"> + <i class="icon ion-edit"></i> + <span ng-if="!formData.profile" translate>PROFILE.BTN_ADD</span> + <span ng-if="formData.profile" translate>PROFILE.BTN_EDIT</span> + </a> + </div> -<div class="double-padding-x padding-bottom"> - <ng-include src="'plugins/es/templates/user/items_profile.html'" ng-init="showName=true;"></ng-include> -</div> + <div class="double-padding-x padding-bottom"> + <ng-include src="'plugins/es/templates/user/items_profile.html'" ng-init="showName=true;"></ng-include> + </div> -<!-- subscriptions --> -<div class="item item-divider item-divider-top-border"> - {{'SUBSCRIPTION.SUBSCRIPTION_DIVIDER' | translate}} - <a class="badge button button-text button-small button-small-padding " - ng-if="!formData.subscriptions.count" - ui-sref="app.edit_subscriptions"> - <i class="icon ion-edit"></i> - <span translate>SUBSCRIPTION.BTN_ADD</span> - </a> -</div> -<div ng-if="!formData.subscriptions.count" - class="item gray" translate>SUBSCRIPTION.NO_SUBSCRIPTION</div> + <!-- subscriptions --> + <div class="item item-divider item-divider-top-border"> + {{'SUBSCRIPTION.SUBSCRIPTION_DIVIDER' | translate}} + <a class="badge button button-text button-small button-small-padding " + ng-if="!formData.subscriptions.count" + ui-sref="app.edit_subscriptions"> + <i class="icon ion-edit"></i> + <span translate>SUBSCRIPTION.BTN_ADD</span> + </a> + </div> + <div ng-if="!formData.subscriptions.count" + class="item gray" translate>SUBSCRIPTION.NO_SUBSCRIPTION</div> -<a class="item item-icon-left item-text-wrap item-icon-right ink" - ng-if="formData.subscriptions.count" - ui-sref="app.edit_subscriptions"> - <i class="icon ion-gear-a"></i> - <span translate>SUBSCRIPTION.SUBSCRIPTION_COUNT</span> - <span class="badge badge-positive">{{formData.subscriptions.count}}</span> + <a class="item item-icon-left item-text-wrap item-icon-right ink" + ng-if="formData.subscriptions.count" + ui-sref="app.edit_subscriptions"> + <i class="icon ion-gear-a"></i> + <span translate>SUBSCRIPTION.SUBSCRIPTION_COUNT</span> + <span class="badge badge-positive">{{formData.subscriptions.count}}</span> - <i class="gray icon ion-ios-arrow-right"></i> -</a> + <i class="gray icon ion-ios-arrow-right"></i> + </a> +</ng-if> diff --git a/www/templates/currency/view_currency_lg.html b/www/templates/currency/view_currency_lg.html index 227d8a3b9ec19ca19c4166d5e14110f1e8d45383..a22a266202b65781fde6d91efb7d214ffecc61ed 100644 --- a/www/templates/currency/view_currency_lg.html +++ b/www/templates/currency/view_currency_lg.html @@ -38,11 +38,14 @@ </div> - <div class="item item-text-wrap no-border no-padding pull-left" - ng-if="!loading"> + <div class="item item-text-wrap no-border no-padding pull-left"> <div class="item-icon-left card padding stable-900-bg"> - <i class="icon ion-help-circled calm"></i> - <div class="item-icon-left-padding" trust-as-html=":rebind:'CURRENCY.VIEW.CURRENCY_SHORT_DESCRIPTION'|translate:formData"> + <ion-spinner class="icon" icon="android" ng-if="loading"></ion-spinner> + <i class="icon ion-help-circled calm" ng-if="!loading"></i> + <div class="item-icon-left-padding" style="min-height: 26px;"> + <span ng-if="!loading" + trust-as-html="'CURRENCY.VIEW.CURRENCY_SHORT_DESCRIPTION'|translate:formData"> + </span> </div> </div> </div> diff --git a/www/templates/home/home.html b/www/templates/home/home.html index a9795e2d3ae271bd3f7e81923f01cf6e3e735cb5..7ebe1b9a7d7625c7359119a3ad7106c4af8525ff 100644 --- a/www/templates/home/home.html +++ b/www/templates/home/home.html @@ -9,9 +9,13 @@ <h4 class="hidden-xs" translate>HOME.MESSAGE</h4> <h4 class="visible-xs" translate>HOME.MESSAGE_SHORT</h4> - <!-- Help tour (NOT ready yet for small device) --> - <div class="center"> + <div class="center padding" ng-if="loading"> + <ion-spinner icon="android"></ion-spinner> + </div> + + <div class="center animate-fade-in animate-show-hide ng-hide" ng-show="!loading"> + <!-- Help tour (NOT ready yet for small device) --> <button type="button" class="button button-block button-stable button-raised icon-left icon ion-easel ink-dark hidden-xs" ng-click="startHelpTour()" > diff --git a/www/templates/menu.html b/www/templates/menu.html index 4c4451521927c2f5adef5c625f46da5cae28b15b..8dc3c4e89247cfa51e267a5f53b135c01eb49726 100644 --- a/www/templates/menu.html +++ b/www/templates/menu.html @@ -38,8 +38,8 @@ enable-menu-with-back-views="false" width="225"> <ion-header-bar> - <h1 class="title dark hidden-sm hidden-xs" translate> - MENU.TITLE + <h1 class="title dark hidden-sm hidden-xs" > + {{'MENU.TITLE'|translate}} <ng-if ng-if="$root.currency">{{$root.currency.name|currencySymbol:false }}</ng-if> </h1> <div class="visible-sm visible-xs hero"> diff --git a/www/templates/settings/settings.html b/www/templates/settings/settings.html index 70e2805c93d9c46b4f967e716a3d920801078ee7..fc9ef4b9b8225e3b0013494a3ee12614173e966b 100644 --- a/www/templates/settings/settings.html +++ b/www/templates/settings/settings.html @@ -150,8 +150,13 @@ <div class="input-label"> {{'SETTINGS.PEER' | translate}} </div> - <span class="item-note dark">{{bma.server}}</ng-if></span> + <h4 class="gray text-wrap assertive" ng-if="formData.node.temporary"> + <i class="icon ion-alert-circled"></i> + <span ng-bind-html="'SETTINGS.PEER_CHANGED_TEMPORARY' | translate "></span> + </h4> + <div class="item-note " ng-class="{'assertive text-italic': formData.node.temporary, 'dark': !formData.node.temporary}">{{bma.server}}</div> </div> + <div class="item item-text-wrap item-toggle dark hidden-xs hidden-sm"> <div class="input-label" ng-bind-html="'SETTINGS.EXPERT_MODE' | translate"></div> <h4 class="gray" ng-bind-html="'SETTINGS.EXPERT_MODE_HELP' | translate"></h4> diff --git a/www/templates/wallet/popover_unit.html b/www/templates/wallet/popover_unit.html index 31dfb400c2c25a8caf587317a2ebffb5c3d43b7c..8edcea2b65ec9fffa5409bd971c5a525d94f9b2a 100644 --- a/www/templates/wallet/popover_unit.html +++ b/www/templates/wallet/popover_unit.html @@ -5,13 +5,13 @@ ng-class="{ 'selected': !formData.useRelative}" ng-click="closePopover(false)"> <i class="icon" ng-class="{ 'ion-ios-checkmark-empty': !formData.useRelative}"></i> - <i ng-bind-html="$root.walletData.currency | currencySymbol:false"></i> + <i ng-bind-html="$root.currency.name | currencySymbol:false"></i> </a> <a class="item item-icon-left" ng-class="{ 'selected': formData.useRelative}" ng-click="closePopover(true)"> <i class="icon" ng-class="{ 'ion-ios-checkmark-empty': formData.useRelative}"></i> - <i ng-bind-html="$root.walletData.currency | currencySymbol:true"></i> + <i ng-bind-html="$root.currency.name | currencySymbol:true"></i> </a> </div> </ion-content> diff --git a/www/templates/wallet/transfer_form.html b/www/templates/wallet/transfer_form.html index 8d000c25c3d45e4614b1d0a4ee83ae5e060f7bb8..dad906ee9f80eb85b8ac025328f9eb2d00ebbdd6 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" + <span class="badge animate-fade-in animate-show-hide ng-hide" ng-show="!$root.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="!$root.walletData.pubkey"></ion-spinner> <span ng-if="$root.walletData.pubkey && !$root.walletData.isMember"> diff --git a/www/templates/wallet/view_wallet_tx.html b/www/templates/wallet/view_wallet_tx.html index a2be1f21f9dc2069635edfc3f5f7b35bb99587d9..7e7d0fe39dc0016bd98dc090f00a60f330837c38 100644 --- a/www/templates/wallet/view_wallet_tx.html +++ b/www/templates/wallet/view_wallet_tx.html @@ -19,7 +19,7 @@ <span ng-bind-html=":rebind:unit"></span> </h1> - <h4 ng-if="$root.settings.expertMode" + <h4 ng-if="!loading && $root.settings.expertMode" style="font-style: italic;"> (<span ng-bind-html=":balance:rebind:formData.balance | formatAmount:{useRelative:!$root.settings.useRelative}"></span> <span ng-bind-html=":rebind:secondaryUnit"></span>) diff --git a/www/templates/wallet/view_wallet_tx_error.html b/www/templates/wallet/view_wallet_tx_error.html index 3e749350b41213ae704ab50bdd291e5d7d35403a..cc678199af08a3e571f3b7422b59f5409cd650de 100644 --- a/www/templates/wallet/view_wallet_tx_error.html +++ b/www/templates/wallet/view_wallet_tx_error.html @@ -34,8 +34,8 @@ <span class="item item-divider"> <span translate>ACCOUNT.ERROR_TX_SENT</span> <div class="badge item-note"> - <span ng-if="!$root.settings.useRelative">({{$root.walletData.currency | abbreviate}})</span> - <span ng-if="$root.settings.useRelative">({{'COMMON.UD' | translate}}<sub>{{$root.walletData.currency | abbreviate}}</sub>)</span> + <span ng-if="!$root.settings.useRelative">({{$root.currency.name | abbreviate}})</span> + <span ng-if="$root.settings.useRelative">({{'COMMON.UD' | translate}}<sub>{{$root.currency.name | abbreviate}}</sub>)</span> </div> </span> @@ -75,8 +75,8 @@ <span class="item item-divider"> <span translate>ACCOUNT.ERROR_TX_RECEIVED</span> <div class="badge item-note"> - <span ng-if="!$root.settings.useRelative">({{$root.walletData.currency | abbreviate}})</span> - <span ng-if="$root.settings.useRelative">({{'COMMON.UD' | translate}}<sub>{{$root.walletData.currency | abbreviate}}</sub>)</span> + <span ng-if="!$root.settings.useRelative">({{$root.currency.name | abbreviate}})</span> + <span ng-if="$root.settings.useRelative">({{'COMMON.UD' | translate}}<sub>{{$root.currency.name | abbreviate}}</sub>)</span> </div> </span> diff --git a/www/templates/wot/lookup_form.html b/www/templates/wot/lookup_form.html index ac22429b5ac5295dbdd96e339dec203351fbac52..2ba711744d4df50fedec3a37b1997ff8e19c4c71 100644 --- a/www/templates/wot/lookup_form.html +++ b/www/templates/wot/lookup_form.html @@ -86,7 +86,7 @@ </div> <div class="text-center" ng-if="search.loading"> - <p class="gray" ng-if="::initPhase" translate>WOT.SEARCH_INIT_PHASE_WARNING</p> + <p class="gray" ng-if="::$root.currency.initPhase" translate>WOT.SEARCH_INIT_PHASE_WARNING</p> <ion-spinner icon="android"></ion-spinner> </div>