diff --git a/www/js/controllers/wallets-controllers.js b/www/js/controllers/wallets-controllers.js index f6306fc47be7af1ce8035f5612e37f804ecdee3d..3db90e5b797ce090d6b480fbd88367795dd50a04 100644 --- a/www/js/controllers/wallets-controllers.js +++ b/www/js/controllers/wallets-controllers.js @@ -92,7 +92,7 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl $scope.setParameters({ showDefault: true, showBalance: true, - minData: true + minData: false }); return $scope.load() @@ -130,13 +130,14 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl }; $scope.select = function(event, wallet) { - if (event.isDefaultPrevented()) return; + if (event.isDefaultPrevented() || !wallet || $scope.selectPrevented) return; if (wallet.isDefault()) { $state.go('app.view_wallet'); } else { $state.go('app.view_wallet_by_id', {id: wallet.id}); } + event.preventDefault(); }; $scope.editWallet = function(event, wallet) { @@ -564,19 +565,27 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl if ($scope.formData.stopped) return; // skip if stopped // Loading next wallet, after waiting some time $scope.formData.updatingWalletId = wallet.id; - return (options.refresh || (walletLoadOptions.sources && !wallet.balance) ? - wallet.refreshData(angular.merge({ - requirements: wallet.requirements && (wallet.requirements.isMember || wallet.requirements.wasMember || wallet.requirements.pendingMembership) - }, walletLoadOptions)) : - wallet.loadData(walletLoadOptions) - ).then(function(walletData) { + var loadPromise; + if (options.refresh && wallet.data.loaded) { + var refreshOptions = angular.merge({ + // Refresh requirements if member account + requirements: (!wallet.data.requirements.loaded || wallet.data.requirements.isMember || wallet.data.requirements.wasMember || wallet.data.requirements.pendingMembership) + }, walletLoadOptions); + loadPromise = wallet.refreshData(refreshOptions); + } + else { + loadPromise = wallet.loadData(walletLoadOptions); + } + + loadPromise.then(function(walletData) { balance += walletData.balance; $scope.updateWalletView(wallet.id); }) - .catch(function(err) { - console.error("[wallets] Error while loading data of wallet #{0}".format(wallet.id), err); - hasLoadError = true; - }); + .catch(function(err) { + console.error("[wallets] Error while loading data of wallet #{0}".format(wallet.id), err); + hasLoadError = true; + }); + return loadPromise; }); }, $q.when()); }) @@ -608,13 +617,17 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl return UIUtils.onError('ERROR.LOAD_WALLET_LIST_FAILED')(err); }); }; - $scope.$on('modal.shown', $scope.load); + + $scope.$on('modal.shown', function() { + $scope.load(); + }); $scope.cancel = function() { $scope.closeModal(); }; - $scope.select = function($event, wallet) { + $scope.select = function(event, wallet) { + if (event.isDefaultPrevented() || !wallet || $scope.selectPrevented) return; $scope.closeModal(wallet); }; @@ -653,9 +666,15 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl $scope.doUpdate = function(silent, event) { if ($scope.loading || !$scope.wallets || !$scope.wallets.length || $scope.formData.updatingWalletId) return $q.when(); + $scope.selectPrevented = true; + $timeout(function() { + $scope.selectPrevented = false; + }, 1000); + return $scope.load({silent: silent, refresh: true}) .then(function() { $scope.loading = false; + $scope.selectPrevented = false; if (silent) { $scope.$broadcast('$$rebind::' + 'rebind'); // force rebind } @@ -692,8 +711,8 @@ function PopoverWalletSelectModalController($scope, $controller, UIUtils) { UIUtils.ink({selector: '.popover-wallets .list .item'}); }; - $scope.select = function($event, wallet) { - if ($event.preventDefault() || !wallet) return; // no selection + $scope.select = function(event, wallet) { + if (event.isDefaultPrevented() || !wallet || $scope.selectPrevented) return; // no selection $scope.closePopover(wallet); }; } diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index fdc2ad14969be6deafa954ac63decc34b889b351..7efa749908ae8e16bb793798da417cdbbedf85e9 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -342,7 +342,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se isDataLoaded = function(options) { if (options) { if (options.minData && !options.sources) return data.loaded && true; - if (options.requirements && !data.requirements) return false; + if (options.requirements && !data.requirements.loaded) return false; if (options.tx && options.tx.enable && (!data.tx.fromTime || data.tx.fromTime == 'pending')) return false; if (options.sigStock && !data.sigStock) return false; } @@ -936,7 +936,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se loadMinData = function(options) { options = options || {}; options.requirements = angular.isDefined(options.requirements) ? options.requirements : - (!data.requirements || angular.isUndefined(data.requirements.needSelf)); + (!data.requirements.loaded || angular.isUndefined(data.requirements.needSelf)); if (!options.requirements) { return $q.when(data); } @@ -960,7 +960,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se }; // Force some load (requirements) if not already loaded - options.requirements = angular.isDefined(options.requirements) ? options.requirements : angular.isDefined(data.requirements.needSelf); + options.requirements = angular.isDefined(options.requirements) ? options.requirements : !data.requirements.loaded; // Force sources when TX enable if (angular.isUndefined(options.sources) && options.tx && options.tx.enable) { @@ -1003,6 +1003,12 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // API extension (after all other jobs) return api.data.raisePromise.load(data) .then(function(){ + + // Compute if full loaded + if (!data.loaded) { + data.loaded = data.requirements.loaded && data.sources; + } + return data; }); }); @@ -1475,7 +1481,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se if (!uid || !blockUid) { throw {message: 'ERROR.WALLET_HAS_NO_SELF'}; } - if (data.requirements && data.requirements.expired) { + if (data.requirements.expired) { throw {message: 'ERROR.WALLET_IDENTITY_EXPIRED'}; } diff --git a/www/js/services/wot-services.js b/www/js/services/wot-services.js index 1821362ad489b4aad0b05d9acdac124810d11fbf..54aa54b57a6b78ca943434ff1d0bfc3945a172c9 100644 --- a/www/js/services/wot-services.js +++ b/www/js/services/wot-services.js @@ -58,6 +58,7 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c _resetRequirements = function(data) { data.requirements = { + loaded: false, meta: {}, needSelf: true, needMembership: true, @@ -119,6 +120,9 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c (requirements.certificationCount - requirements.willExpireCertificationCount) < currencyParameters.sigQty) ? (currencyParameters.sigQty - requirements.certificationCount + requirements.willExpireCertificationCount) : 0; + // Mark as loaded - need by csWallet.isDataLoaded() + requirements.loaded = true; + return requirements; }, @@ -247,6 +251,7 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c if (!!err && (err.ucode == BMA.errorCodes.NO_MATCHING_MEMBER || err.ucode == BMA.errorCodes.NO_IDTY_MATCHING_PUB_OR_UID)) { + data.requirements.loaded = true; return data; } throw err; @@ -336,11 +341,11 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c data.lookup = {}; // Store received certifications (can be usefull later) - var certPubkeys = []; - data.lookup.certifications = !res.results ? {} : res.results.reduce(function(certsMap, res) { + var certPubkeys = {}; + data.lookup.certifications = (res.results || []).reduce(function(certsMap, res) { return res.uids.reduce(function(certsMap, idty) { var idtyFullKey = idty.uid + '-' + (idty.meta ? idty.meta.timestamp : ''); - certsMap[idtyFullKey] = idty.others.reduce(function(certs, cert) { + certsMap[idtyFullKey] = (idty.others||[]).reduce(function(certs, cert) { var certFullKey = idtyFullKey + '-' + cert.pubkey; var result = { pubkey: cert.pubkey, @@ -372,9 +377,9 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c }, {}); // Store given certifications - certPubkeys = []; - data.lookup.givenCertifications = !res.results ? [] : res.results.reduce(function(certs, res) { - return res.signed.reduce(function(certs, cert) { + certPubkeys = {}; + data.lookup.givenCertifications = (res.results || []).reduce(function(certs, res) { + return (res.signed || []).reduce(function(certs, cert) { var result = { pubkey: cert.pubkey, uid: cert.uid, @@ -388,14 +393,18 @@ angular.module('cesium.wot.services', ['ngApi', 'cesium.bma.services', 'cesium.c }; if (!certPubkeys[cert.pubkey]) { certPubkeys[cert.pubkey] = result; - // TODO : to not add, but replace the old one } else { // if duplicated cert: keep the most recent if (result.block > certPubkeys[cert.pubkey].block) { certPubkeys[cert.pubkey] = result; + // TODO: Replace the existing one ? May be not, to be able to see renewal + // (see issue #806) + // If yes (need to replace), check this code works: + //certs.splice(_.findIndex(certs, {pubkey: cert.pubkey}), 1, result); + //return certs; } else { - return certs; // skip this result + return certs; // skip this cert } } return certs.concat(result); diff --git a/www/plugins/graph/js/controllers/account-controllers.js b/www/plugins/graph/js/controllers/account-controllers.js index fabbf9c4669f126107fec303387623d7a344fbc8..7fcb2c61ca39a109ebe40912e44e4d2ab4ab7960 100644 --- a/www/plugins/graph/js/controllers/account-controllers.js +++ b/www/plugins/graph/js/controllers/account-controllers.js @@ -354,14 +354,14 @@ function GpAccountSumTxController($scope, $controller, $filter, $state, csTx, gp sumByPubkeys[tx.pubkey].sum += Math.abs(tx.amount); }); - // Divide amount by 100 - _.each(_.keys(sumByPubkeys), function(pubkey) { - sumByPubkeys[pubkey].sum = sumByPubkeys[pubkey].sum / 100; - }); - // Get values (from the map), then sort (desc) on sum var sumItems = _.sortBy(_.values(sumByPubkeys), 'sum').reverse(); + // Divide total amount by 100 + _.each(sumItems, function(item) { + item.sum = item.sum / 100; + }); + // Return arrays expected by angular-chart return { data: _.pluck(sumItems, 'sum'), diff --git a/www/plugins/graph/templates/account/graph_sum_tx.html b/www/plugins/graph/templates/account/graph_sum_tx.html index bfecae086b242b90244f0cbe253262a15f1f4180..ca11e96571bbd5ffae4125efa736f29734dffa11 100644 --- a/www/plugins/graph/templates/account/graph_sum_tx.html +++ b/www/plugins/graph/templates/account/graph_sum_tx.html @@ -4,7 +4,7 @@ <div class="col text-center"> - <!-- [NEW] TX input chart --> + <!-- TX input chart --> <p class="gray padding text-wrap" ng-if="inputChart.data.length" translate>GRAPH.ACCOUNT.INPUT_CHART_TITLE</p> @@ -21,7 +21,7 @@ <div class="col text-center"> - <!-- [NEW] TX input chart --> + <!-- TX output chart --> <p class="gray padding text-wrap" ng-if="outputChart.data.length" translate>GRAPH.ACCOUNT.OUTPUT_CHART_TITLE</p> diff --git a/www/templates/wallet/list/item_wallet.html b/www/templates/wallet/list/item_wallet.html index 8e1072ea3724f7a7290c11454e46800280e31f0b..17d903d72c8ae82afe8a6d0626b62ede5751a838 100644 --- a/www/templates/wallet/list/item_wallet.html +++ b/www/templates/wallet/list/item_wallet.html @@ -27,7 +27,7 @@ <cs-extension-point name="item-wallet"></cs-extension-point> - <span class="badge" ng-if=":rebind:formData.showBalance && walletData.loaded" + <span class="badge" ng-if=":rebind:formData.showBalance && walletData.sources" ng-class=":rebind:{'badge-assertive': (walletData.balance <= 0), 'badge-balanced': (walletData.balance > 0) }"> <ion-spinner class="ion-spinner-small" ng-if="formData.updatingWalletId==wallet.id" icon="android"></ion-spinner> <span ng-bind-html=":rebind:walletData.balance|formatAmount:{useRelative: formData.useRelative, currency: currency}"></span> diff --git a/www/templates/wallet/list/view_wallets.html b/www/templates/wallet/list/view_wallets.html index 3542c2aeea870ebd49ea4a5c92f49981531acbb6..840ee659d670fe7a414a8de4ac5ed2fc0844dae8 100644 --- a/www/templates/wallet/list/view_wallets.html +++ b/www/templates/wallet/list/view_wallets.html @@ -17,14 +17,14 @@ bind-notifier="{ rebind:formData.useRelative, locale:settings.locale.id}"> <ion-refresher pulling-text="{{:locale:'COMMON.BTN_REFRESH' | translate}}" - on-refresh="doUpdate(true)"> + on-refresh="doUpdate(true, $event)"> </ion-refresher> <!-- Buttons bar--> <div class="hidden-xs hidden-sm padding text-center"> <button class="button button-stable button-small-padding icon ion-loop ink" - ng-click="doUpdate(true)" + ng-click="doUpdate(true, $event)" title="{{:locale:'COMMON.BTN_REFRESH' | translate}}"> </button>