diff --git a/www/js/controllers/wallets-controllers.js b/www/js/controllers/wallets-controllers.js index c2afb865cdbe8217dd0666973d4d8636cd2ae4c7..0c4649196f4d7c989ecdbb36f7a969b5b2dc314b 100644 --- a/www/js/controllers/wallets-controllers.js +++ b/www/js/controllers/wallets-controllers.js @@ -92,7 +92,8 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl $scope.entered = true; $scope.setParameters({ showDefault: true, - showBalance: true + showBalance: true, + minData: true }); return $scope.load() @@ -454,6 +455,12 @@ function WalletListController($scope, $controller, $state, $timeout, $q, $transl $scope.$broadcast('$$rebind::' + 'rebind'); // force rebind }; + var inheritedUpdateWalletView = $scope.updateWalletView; + $scope.updateWalletView = function(walletId) { + inheritedUpdateWalletView(walletId); + $scope.$broadcast('$$rebind::' + 'rebind'); // force rebind + }; + // Detect changes in settings useRelative $scope.$watch('settings.useRelative', function(newVal, oldVal) { if (!$scope.formData || $scope.loading || (newVal === oldVal)) return; @@ -473,7 +480,8 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl showBalance: false, balance: undefined, updatingWalletId: undefined, - stopped: false + stopped: false, + minData: true }; $scope.motion = null; // no animation @@ -485,6 +493,8 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl $scope.formData.showDefault = angular.isDefined(parameters.showDefault) ? parameters.showDefault : $scope.formData.showDefault; $scope.formData.showBalance = angular.isDefined(parameters.showBalance) ? parameters.showBalance : $scope.formData.showBalance; + + $scope.formData.minData = angular.isDefined(parameters.minData) ? parameters.minData : $scope.formData.minData; }; $scope.load = function(options) { @@ -505,15 +515,13 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl })); // Get children wallets - var tempWallets; + $scope.defaultWallet = $scope.formData.showDefault ? csWallet : undefined; if (!$scope.wallets) { jobs.push( csWallet.children.all() .then(function(children) { - $scope.wallets = []; - tempWallets = $scope.formData.showDefault ? [csWallet].concat(children) : children; + $scope.wallets=children; UIUtils.loading.hide(); - $scope.updateView(); }) ); } @@ -521,7 +529,7 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl // Prepare load options var walletLoadOptions = { silent: true, - minData: !$scope.formData.showBalance, + minData: $scope.formData.minData, sources: $scope.formData.showBalance, tx: { enable: false @@ -535,17 +543,16 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl return (jobs.length ? $q.all(jobs) : $q.when()) // Load wallet data (apply a timeout between each wallet) .then(function() { - console.debug("[wallets] Loading {0} wallets...".format($scope.wallets.length)); - return (tempWallets || $scope.wallets).reduce(function(res, wallet) { + var wallets = $scope.formData.showDefault ? [csWallet].concat($scope.wallets) : $scope.wallets; + if (!wallets.length) return; + console.debug("[wallets] Loading {0} wallets...".format(wallets.length)); + return wallets.reduce(function(res, wallet) { var skip= !options.refresh && wallet.isDataLoaded(walletLoadOptions); if (skip) { console.debug("[wallets] Wallet #{0} already loaded. Skipping".format(wallet.id), walletLoadOptions); return res.then(function(){ balance += wallet.data.balance; - if (tempWallets) { - $scope.wallets.push(wallet); - $scope.updateView(); - } + $scope.updateWalletView(wallet.id); }); } loadCounter++; @@ -553,17 +560,14 @@ 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 ? - wallet.loadData(walletLoadOptions) : + return (options.refresh || (walletLoadOptions.sources && !wallet.balance) ? wallet.refreshData(angular.merge({ requirements: wallet.requirements && (wallet.requirements.isMember || wallet.requirements.wasMember || wallet.requirements.pendingMembership) - }, walletLoadOptions)) + }, walletLoadOptions)) : + wallet.loadData(walletLoadOptions) ).then(function(walletData) { - if (tempWallets) { - $scope.wallets.push(wallet); - $scope.updateView(); - } balance += walletData.balance; + $scope.updateWalletView(wallet.id); }) .catch(function(err) { console.error("[wallets] Error while loading data of wallet #{0}".format(wallet.id), err); @@ -580,11 +584,8 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl $scope.cancel(); }); } - if ($scope.formData.stopped) { - // Make sure to keep all wallets - if (tempWallets) $scope.wallets = tempWallets; - return; - } + // Stop + if ($scope.formData.stopped) return; if (loadCounter) { console.debug("[wallets] Loaded data of {0} wallet(s) in {1}ms".format(loadCounter, (Date.now() - now))); } @@ -621,14 +622,25 @@ function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTransl $scope.formData.updatingWalletId = undefined; }; - $scope.updateView = function() { + $scope.updateView = function(walletId) { if (!$scope.wallets || !$scope.wallets.length) return; + var selectorSuffix = walletId && (' #wallet-' + walletId) || ''; + + if ($scope.motion) { + $scope.motion.show({selector: '.list .item.item-wallet' + selectorSuffix, ink: true}); + } + else { + UIUtils.ink({selector: '.list .item.item-wallet' + selectorSuffix}); + } + }; + + $scope.updateWalletView = function(walletId) { if ($scope.motion) { - $scope.motion.show({selector: '.list .item.item-wallet', ink: true}); + $scope.motion.show({selector: '.list #wallet-' + walletId, ink: true}); } else { - UIUtils.ink({selector: '.list .item.item-wallet'}); + UIUtils.ink({selector: '.list #wallet-' + walletId}); } }; diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index 01885a9bd9dc6f9bbc7fd6ae0c27b3ca0ff7770b..31f5d3b5d2ad2dac2a6b0dc0e712f9df0ac30299 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -341,7 +341,7 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se isDataLoaded = function(options) { if (options) { - if (options.minData && !options.sources) return data.loaded; + if (options.minData && !options.sources) return data.loaded && true; if (options.requirements && !data.requirements) return false; if (options.tx && options.tx.enable && (!data.tx.fromTime || data.tx.fromTime == 'pending')) return false; if (options.sigStock && !data.sigStock) return false; diff --git a/www/templates/wallet/list/item_wallet.html b/www/templates/wallet/list/item_wallet.html index 1317ab65f4d66f4bbeb374525558675ab30dcb47..223151db94ca4be2697b05357af69876448eae59 100644 --- a/www/templates/wallet/list/item_wallet.html +++ b/www/templates/wallet/list/item_wallet.html @@ -1,4 +1,5 @@ <div class="item item-avatar item-icon-right item-border-large item-wallet ink" + id="wallet-{{::wallet.id}}" ng-click="select($event, wallet)" ng-init="walletData=wallet.data;"> diff --git a/www/templates/wallet/list/modal_wallets.html b/www/templates/wallet/list/modal_wallets.html index c309863f9c17a045976d744167541d04bd9513d4..cd2d769a8b6942d91ce6d2d2e525735f5fdb6527 100644 --- a/www/templates/wallet/list/modal_wallets.html +++ b/www/templates/wallet/list/modal_wallets.html @@ -10,11 +10,14 @@ <ion-spinner icon="android"></ion-spinner> </div> - <div class="center padding gray" ng-if="!loading && !wallets.length"> + <div class="center padding gray" ng-if="!loading && !wallets.length && !defaultWallet"> {{:locale:'ACCOUNT.WALLET_LIST.NO_WALLET'|translate}} </div> <ion-list ng-if="!loading" class="{{::motion.ionListClass}}"> + <ng-include ng-if="defaultWallet" ng-init="wallet = defaultWallet" src="'templates/wallet/list/item_wallet.html'"> + </ng-include> + <ng-repeat ng-repeat="wallet in wallets track by wallet.id" ng-include="'templates/wallet/list/item_wallet_light.html'"> </ng-repeat> diff --git a/www/templates/wallet/list/view_wallets.html b/www/templates/wallet/list/view_wallets.html index 94508c90911054f51e68a3e5ed614a7874262f48..3542c2aeea870ebd49ea4a5c92f49981531acbb6 100644 --- a/www/templates/wallet/list/view_wallets.html +++ b/www/templates/wallet/list/view_wallets.html @@ -57,11 +57,14 @@ - <div class="center padding gray" ng-if="!loading && wallets && !wallets.length"> + <div class="center padding gray" ng-if="!loading && wallets && !wallets.length && !defaultWallet"> {{:locale:'ACCOUNT.WALLET_LIST.NO_WALLET'|translate}} </div> - <ion-list ng-if="wallets" class="{{::motion.ionListClass}}"> + <ion-list class="{{::motion.ionListClass}}"> + <ng-include ng-if="defaultWallet" ng-init="wallet = defaultWallet" src="'templates/wallet/list/item_wallet.html'"> + </ng-include> + <ng-include ng-repeat="wallet in wallets track by wallet.id" src="'templates/wallet/list/item_wallet.html'"> </ng-include>