diff --git a/www/js/app.js b/www/js/app.js index 341540e338459a80d9330f700424f84c6c03dd68..dd02ab231a98411585f1ee43ecebf6f7ce22b34f 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -26,10 +26,10 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'pascalprecht .filter('formatDecimal', function() { return function(input) { if (input === undefined) return '0'; - // for DEBUG only - //if (input === Infinity || input === -Infinity) { - // return '∞'; - //} + if (input === Infinity || input === -Infinity) { + console.warn("formatDecimal: division by zero ? (is currentUD defined ?)"); + return 'error'; + } if (Math.abs(input) < 0.0001) return '~ 0'; return numeral(input/*-0.00005*/).format('0,0.0000'); }; diff --git a/www/js/controllers/app-controllers.js b/www/js/controllers/app-controllers.js index 4d27afc13c008a8a024f6022d5b24432b5f62280..17f167b46caabfc28bb6eab45bbb15ae153d7f4b 100644 --- a/www/js/controllers/app-controllers.js +++ b/www/js/controllers/app-controllers.js @@ -212,6 +212,8 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ return $q(function(resolve, reject){ + Device.ready() + if (!Wallet.isLogin()) { $scope.showLoginModal() .then(function(walletData) { diff --git a/www/js/services/settings-services.js b/www/js/services/settings-services.js index 35a30f5414572f01fbb3ce989c8500e3f1cd22b8..9e5cea9ff14b7c7175c5cd5162f0b66e91bb0517 100644 --- a/www/js/services/settings-services.js +++ b/www/js/services/settings-services.js @@ -145,6 +145,7 @@ angular.module('cesium.settings.services', ['ngResource', 'ngApi', 'cesium.confi api.registerEvent('data', 'changed'); api.registerEvent('data', 'store'); + api.registerEvent('data', 'ready'); return { id: id, @@ -162,7 +163,10 @@ angular.module('cesium.settings.services', ['ngResource', 'ngApi', 'cesium.confi service.instance = CSSettings; - service.restore(); + service.restore() + .then(function() { + service.api.data.raise.ready(); + }); return service; }); diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index 7cee549634cbdceb93905829d42d1d837db37368..a68f5867c096396ca6f33929fd65f9fcf9a77198 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -262,13 +262,16 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser // Load parameters // This prevent timeout error, when loading a market record after a browser refresh (e.g. F5) loadParameters() - ]); + ]) } else { // This prevent timeout error, when loading a market record after a browser refresh (e.g. F5) return loadParameters(); } }) + .then(function(){ + resolve(data); + }) .catch(function(err){reject(err);}); }); }, @@ -1347,9 +1350,11 @@ angular.module('cesium.wallet.services', ['ngResource', 'ngApi', 'cesium.bma.ser var service = Wallet('default'); // try to restore wallet - Device.ready().then(function() { - service.restore(); - $rootScope.walletData = service.data; + csSettings.api.data.on.ready($rootScope, function() { + service.restore() + .then(function(data) { + $rootScope.walletData = data; + }); }); service.instance = Wallet; diff --git a/www/plugins/es/js/controllers/wot-controllers.js b/www/plugins/es/js/controllers/wot-controllers.js index 11479b35fea4362f9e54f78c73c1abc1dba18027..c91c1b57a09b9390d132b6bcf0ddb15769354433 100644 --- a/www/plugins/es/js/controllers/wot-controllers.js +++ b/www/plugins/es/js/controllers/wot-controllers.js @@ -1,22 +1,24 @@ angular.module('cesium.es.wot.controllers', ['cesium.es.services']) - .config(function(PluginServiceProvider) { + .config(function(PluginServiceProvider, csConfig) { 'ngInject'; - PluginServiceProvider - - .extendState('app.wot_view_identity', { - points: { - 'general': { - templateUrl: "plugins/es/templates/wot/view_identity_extend.html", - controller: 'ESWotIdentityViewCtrl' - }, - 'buttons': { - templateUrl: "plugins/es/templates/wot/view_identity_extend.html", - controller: 'ESWotIdentityViewCtrl' - } - } - }) - ; + + var enable = csConfig.plugins && csConfig.plugins.es; + if (enable) { + PluginServiceProvider.extendState('app.wot_view_identity', { + points: { + 'general': { + templateUrl: "plugins/es/templates/wot/view_identity_extend.html", + controller: 'ESWotIdentityViewCtrl' + }, + 'buttons': { + templateUrl: "plugins/es/templates/wot/view_identity_extend.html", + controller: 'ESWotIdentityViewCtrl' + } + } + }) + ; + } }) @@ -24,11 +26,25 @@ angular.module('cesium.es.wot.controllers', ['cesium.es.services']) ; -function ESWotIdentityViewController($scope, PluginService, esModals) { +function ESWotIdentityViewController($scope, csSettings, PluginService, esModals) { 'ngInject'; $scope.extensionPoint = PluginService.extensions.points.current.get(); + $scope.updateView = function() { + $scope.enable = csSettings.data.plugins && csSettings.data.plugins.es ? + csSettings.data.plugins.es.enable : + !!csSettings.data.plugins.host; + }; + + csSettings.api.data.on.changed($scope, function() { + $scope.updateView(); + }); + + $scope.updateView(); + + /* -- modals -- */ + $scope.showNewMessageModal = function() { return $scope.loadWallet() .then(function() { diff --git a/www/plugins/es/js/services/user-services.js b/www/plugins/es/js/services/user-services.js index a498221af6694913ce311732f3e28012ddabab84..887abdd0e7f4ea59afce6f65acae2dd869bfad62 100644 --- a/www/plugins/es/js/services/user-services.js +++ b/www/plugins/es/js/services/user-services.js @@ -10,7 +10,7 @@ angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.se }) -.factory('esUser', function($rootScope, $q, esHttp, csSettings, Wallet, WotService, UIUtils, BMA, CryptoUtils) { +.factory('esUser', function($rootScope, $q, $timeout, esHttp, csSettings, Wallet, WotService, UIUtils, BMA, CryptoUtils) { 'ngInject'; function factory(host, port) { @@ -230,7 +230,6 @@ angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.se } return; } - console.debug('[esUser] Loading user settings from ES node...'); // Waiting to load crypto libs if (!CryptoUtils.isLoaded()) { @@ -241,6 +240,8 @@ angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.se return; } + console.debug('[esUser] Loading user settings from ES node...'); + // Load settings esHttp.get(host, port, '/user/settings/:id')({id: data.pubkey}) .then(function(res) { @@ -284,6 +285,15 @@ angular.module('cesium.es.user.services', ['cesium.services', 'cesium.es.http.se function onSettingsChanged(data) { if (!Wallet.isLogin()) return; + // Waiting to load crypto libs + if (!CryptoUtils.isLoaded()) { + console.debug('[esUser] Waiting crypto lib loading...'); + $timeout(function() { + onSettingsChanged(data); + }, 200); + return; + } + console.debug('[esUser] Saving user settings to ES...'); var boxKeypair = CryptoUtils.box.keypair.fromSignKeypair(Wallet.data.keypair); diff --git a/www/plugins/es/templates/wot/view_identity_extend.html b/www/plugins/es/templates/wot/view_identity_extend.html index 5cb57e5ac9bb5d58b66040b69c480adb2ee6c51e..71ef33d943c667f924e6d0e8465113b1f3732689 100644 --- a/www/plugins/es/templates/wot/view_identity_extend.html +++ b/www/plugins/es/templates/wot/view_identity_extend.html @@ -1,5 +1,5 @@ <!-- Buttons section --> -<ng-if ng-if="extensionPoint === 'buttons'"> +<ng-if ng-if="enable && extensionPoint === 'buttons'"> <button class="button button-stable icon ion-compose" ng-click="showNewMessageModal()"> {{'MESSAGE.BTN_WRITE' | translate}} @@ -7,7 +7,7 @@ </ng-if> <!-- General section --> -<ng-if ng-if="extensionPoint === 'general'"> +<ng-if ng-if="enable && extensionPoint === 'general'"> <!-- About me --> <ng-if ng-if="formData.profile.description"> @@ -52,7 +52,7 @@ </ng-if> <!-- Technical section--> -<ng-if ng-if="formData.profile && extensionPoint == 'technical'"> +<ng-if ng-if="enable && formData.profile && extensionPoint == 'technical'"> </ng-if>