diff --git a/www/index.html b/www/index.html index b6ca609bb9fa2b6f982156a5f8f26d9b46988218..fdead4fa018e49d67cfc2db4c422d27af17776c1 100644 --- a/www/index.html +++ b/www/index.html @@ -157,6 +157,7 @@ <script src="dist/dist_js/app/controllers/login-controllers.js"></script> <script src="dist/dist_js/app/controllers/help-controllers.js"></script> <script src="dist/dist_js/app/controllers/wallet-controllers.js"></script> + <script src="dist/dist_js/app/controllers/wallets-controllers.js"></script> <script src="dist/dist_js/app/controllers/wot-controllers.js"></script> <script src="dist/dist_js/app/controllers/network-controllers.js"></script> <script src="dist/dist_js/app/controllers/currency-controllers.js"></script> diff --git a/www/js/controllers.js b/www/js/controllers.js index a612166287398398363b2d659baf4dfc0c8f2367..5ed49c51576e0032ddf87bf2b62cfbc130b8b201 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -5,6 +5,7 @@ angular.module('cesium.controllers', [ 'cesium.login.controllers', 'cesium.help.controllers', 'cesium.wallet.controllers', + 'cesium.wallets.controllers', 'cesium.currency.controllers', 'cesium.wot.controllers', 'cesium.transfer.controllers', diff --git a/www/js/controllers/transfer-controllers.js b/www/js/controllers/transfer-controllers.js index ef8cdb9570c4a7a0dcce051c0c9f7411ad12d954..7c7e41f5cb271e18135bde6c4d9184eb9d53d1e6 100644 --- a/www/js/controllers/transfer-controllers.js +++ b/www/js/controllers/transfer-controllers.js @@ -164,7 +164,7 @@ function TransferModalController($scope, $q, $translate, $timeout, $filter, $foc wallet = $scope.enableSelectWallet && ($scope.formData.walletId ? csWallet.children.get($scope.formData.walletId) : csWallet) || csWallet; if (!wallet.isDefault()) { - console.debug("[transfer] Using {" + wallet.id + "} wallet"); + console.debug("[transfer] Using wallet {" + wallet.id + "}"); } // Make to sure to load full wallet data (balance) return wallet.login({sources: true, silent: true}) @@ -413,7 +413,7 @@ function TransferModalController($scope, $q, $translate, $timeout, $filter, $foc if (!newWallet || (wallet && wallet.id === newWallet.id)) return; wallet = newWallet; $scope.walletData = wallet.data; - console.debug("[transfer] Using {" + wallet.id + "} wallet"); + console.debug("[transfer] Using wallet {" + wallet.id + "}"); $scope.onAmountChanged(); }); }; diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js index dba0f095db6e5da39e8a86c1faa7ecc7194fee76..c415480d5bc7b0a3313d3fad9dfb07b59ab5bdf9 100644 --- a/www/js/controllers/wallet-controllers.js +++ b/www/js/controllers/wallet-controllers.js @@ -45,64 +45,9 @@ angular.module('cesium.wallet.controllers', ['cesium.services', 'cesium.currency login: true } }) - - .state('app.view_wallets', { - url: "/wallets", - views: { - 'menuContent': { - templateUrl: "templates/wallet/list/view_wallets.html", - controller: 'WalletListCtrl' - } - }, - data: { - login: true - } - }) - - .state('app.view_wallet_by_id', { - url: "/wallets/:id?refresh", - views: { - 'menuContent': { - templateUrl: "templates/wallet/view_wallet.html", - controller: 'WalletCtrl' - } - }, - data: { - login: true, - silentLocationChange: true - } - }) - - .state('app.view_wallet_tx_by_id', { - url: "/history/wallets/:id?refresh", - views: { - 'menuContent': { - templateUrl: "templates/wallet/view_wallet_tx.html", - controller: 'WalletTxCtrl' - } - }, - data: { - login: true, - silentLocationChange: true - } - }) - - .state('app.view_wallet_tx_errors_by_id', { - url: "/history/wallets/:id/errors", - views: { - 'menuContent': { - templateUrl: "templates/wallet/view_wallet_tx_error.html", - controller: 'WalletTxErrorCtrl' - } - }, - data: { - login: true - } - }) ; }) - .controller('WalletCtrl', WalletController) .controller('WalletTxCtrl', WalletTxController) @@ -110,12 +55,6 @@ angular.module('cesium.wallet.controllers', ['cesium.services', 'cesium.currency .controller('WalletTxErrorCtrl', WalletTxErrorController) .controller('WalletSecurityModalCtrl', WalletSecurityModalController) - - .controller('WalletListCtrl', WalletListController) - - .controller('WalletSelectModalCtrl', WalletSelectModalController) - - .controller('PopoverWalletSelectModalCtrl', PopoverWalletSelectModalController) ; function WalletController($scope, $rootScope, $q, $ionicPopup, $timeout, $state, $translate, $ionicPopover, $location, @@ -927,7 +866,7 @@ function WalletTxController($scope, $ionicPopover, $state, $timeout, $location, $scope.removeListeners(); $scope.loading = true; wallet = newWallet; - console.debug("[transfer] Using {" + wallet.id + "} wallet"); + console.debug("[transfer] Using wallet {" + wallet.id + "}"); $scope.formData = {}; return $scope.load(); }); @@ -1514,444 +1453,3 @@ function WalletSecurityModalController($scope, UIUtils, csWallet, $translate, pa ; }; } - -function WalletListController($scope, $controller, $state, $timeout, $q, $translate, $ionicPopover, $ionicPopup, - UIUtils, Modals, csCurrency, csSettings, csWallet){ - 'ngInject'; - - $scope.settings = csSettings.data; - $scope.listeners = []; - - - // Initialize the super class and extend it. - angular.extend(this, $controller('WalletSelectModalCtrl', {$scope: $scope, parameters: {}})); - - // Override defaults - $scope.formData.name = undefined; - $scope.motion = UIUtils.motion.default; - - $scope.enter = function(e, state) { - // First enter - if ($scope.loading) { - $scope.setParameters({ - showDefault: false, - showBalance: true - }); - - return $scope.load() - .then(function() { - UIUtils.loading.hide(); - if (!$scope.wallets) return; // user cancel - $scope.addListeners(); - $scope.showFab('fab-add-wallet'); - }); - } - else { - $scope.addListeners(); - } - }; - $scope.$on('$ionicView.enter', $scope.enter); - - $scope.leave = function() { - $scope.removeListeners(); - }; - $scope.$on('$ionicView.leave', $scope.leave); - - $scope.cancel = function() { - $scope.showHome(); - }; - - $scope.select = function(event, wallet) { - if (event.isDefaultPrevented()) return; - - $state.go('app.view_wallet_by_id', {id: wallet.id}); - }; - - - $scope.editWallet = function(event, wallet) { - - event.preventDefault(); - - return $scope.showEditPopup(wallet) - .then(function(newName) { - if (!newName) return; - - // Save changes - return csWallet.auth({minData: true}) - .then(function() { - wallet.data.localName = newName; - csWallet.storeData(); - UIUtils.loading.hide(); - $scope.updateView(); - }) - .catch(function(err) { - if (err === 'CANCELLED') { - return UIUtils.loading.hide(); - } - UIUtils.onError('ERROR.SAVE_WALLET_LIST_FAILED')(err); - }); - }); - }; - - /* -- modals -- */ - - $scope.showNewWalletModal = function() { - - var walletId = csWallet.children.count() + 1; - var wallet = csWallet.instance(walletId); - return wallet.login({ - showNewAccountLink: false, - title: 'ACCOUNT.WALLET_LIST.BTN_NEW', - okText: 'COMMON.BTN_ADD', - // Load data options : - minData: true, - sources: true, - api: false, - success: UIUtils.loading.show - }) - .then(function(walletData) { - if (!walletData) return; - - // Avoid to add main wallet again - if (walletData.pubkey === csWallet.data.pubkey) { - UIUtils.loading.hide(); - UIUtils.alert.error('ERROR.COULD_NOT_ADD_MAIN_WALLET'); - return; - } - - // Make sure to auth on the main wallet - return csWallet.auth({minData: true}) - .then(function() { - return csWallet.api.data.raisePromise.load(wallet.data) - // continue, when plugins extension failed (just log in console) - .catch(console.error) - .then(function() { - $scope.listeners.push(wallet.api.data.on.unauth($scope, $scope.updateView)); - $scope.listeners.push(wallet.api.data.on.auth($scope, $scope.updateView)); - csWallet.children.add(wallet); - UIUtils.loading.hide(); - $scope.updateView(); - }); - }) - .catch(function(err) { - if (err === 'CANCELLED') { - return UIUtils.loading.hide(); - } - UIUtils.onError('ERROR.ADD_SECONDARY_WALLET_FAILED')(err); - }); - }); - }; - - $scope.selectAndRemoveWallet = function() { - $scope.hideActionsPopover(); - return Modals.showSelectWallet({ - wallets: $scope.wallets, - showDefault: false - }) - .then(function(wallet) { - if (!wallet || !wallet.id) return; - - // Make sure to auth on the main wallet - return csWallet.auth({minData: true}) - .then(function() { - csWallet.children.remove(wallet.id); - UIUtils.loading.hide(); - $scope.updateView(); - }) - .catch(function(err) { - if (err === 'CANCELLED') { - return UIUtils.loading.hide(); - } - UIUtils.onError('ERROR.ADD_SECONDARY_WALLET_FAILED')(err); - }); - }); - }; - - /* -- popups -- */ - - $scope.setEditForm = function(editForm) { - $scope.editForm = editForm; - }; - - $scope.showEditPopup = function(wallet) { - return $q(function(resolve, reject) { - $translate(['ACCOUNT.WALLET_LIST.EDIT_POPOVER.TITLE', 'ACCOUNT.WALLET_LIST.EDIT_POPOVER.HELP', 'COMMON.BTN_OK', 'COMMON.BTN_CANCEL']) - .then(function (translations) { - $scope.formData.name = wallet.data.name || wallet.data.uid || wallet.data.pubkey.substring(0, 8); - - // Choose UID popup - $ionicPopup.show({ - templateUrl: 'templates/wallet/list/popup_edit_name.html', - title: translations['ACCOUNT.WALLET_LIST.EDIT_POPOVER.TITLE'], - subTitle: translations['ACCOUNT.WALLET_LIST.EDIT_POPOVER.HELP'], - scope: $scope, - buttons: [ - { text: translations['COMMON.BTN_CANCEL'] }, - { - text: translations['COMMON.BTN_OK'], - type: 'button-positive', - onTap: function(e) { - $scope.editForm.$submitted=true; - if(!$scope.editForm.$valid || !$scope.formData.name) { - //don't allow the user to close unless he enters a name - e.preventDefault(); - } else { - return $scope.formData.name; - } - } - } - ] - }) - .then(function(name) { - if (!name) { // user cancel - delete $scope.formData.name; - UIUtils.loading.hide(); - return; - } - resolve(name); - }); - }); - }); - }; - - /* -- popovers -- */ - - $scope.showActionsPopover = function(event) { - if (!$scope.actionsPopover) { - $ionicPopover.fromTemplateUrl('templates/wallet/list/popover_actions.html', { - scope: $scope - }).then(function(popover) { - $scope.actionsPopover = popover; - //Cleanup the popover when we're done with it! - $scope.$on('$destroy', function() { - $scope.actionsPopover.remove(); - }); - $scope.actionsPopover.show(event); - }); - } - else { - $scope.actionsPopover.show(event); - } - }; - - $scope.hideActionsPopover = function() { - if ($scope.actionsPopover) { - $scope.actionsPopover.hide(); - } - }; - - /* -- listeners -- */ - - $scope.addListeners = function() { - if (csSettings.data.walletHistoryAutoRefresh && $scope.wallets) { - - var listeners = [ - // Update on new block - csCurrency.api.data.on.newBlock($scope, function(block) { - if ($scope.loading) return; - console.debug("[wallet-list] Received new block. Will reload list."); - $timeout(function() { - $scope.doUpdate(true); - }, 300/*waiting for node cache propagation*/); - }) - ]; - - // Listen wallets changed - $scope.listeners = $scope.wallets.reduce(function(res, wallet) { - return res.concat([ - wallet.api.data.on.unauth($scope, $scope.updateView), - wallet.api.data.on.auth($scope, $scope.updateView) - ]); - }, listeners); - } - else { - $scope.listeners = []; - } - }; - - $scope.removeListeners = function() { - _.forEach($scope.listeners, function(remove){ - remove(); - }); - $scope.listeners = []; - }; - - var inheritedUpdateView = $scope.updateView; - $scope.updateView = function() { - inheritedUpdateView(); - $scope.$broadcast('$$rebind::' + 'rebind'); // force rebind - }; -} - -function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTranslations, csSettings, csCurrency, csWallet, parameters){ - 'ngInject'; - - var loadWalletWaitTime = 500; - $scope.loading = true; - $scope.formData = { - useRelative: csSettings.data.useRelative, - showDefault: true, - showBalance: false - }; - $scope.motion = null; // no animation - - $scope.setParameters = function(parameters) { - parameters = parameters || {}; - - $scope.formData.useRelative = angular.isDefined(parameters.useRelative) ? parameters.useRelative : $scope.formData.useRelative; - - $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.load = function() { - $scope.loading = true; - - // Load currency, and filter translations (need by 'formatAmount' filter) - var jobs = [ - csCurrency.name() - .then(function(name) { - $scope.currency = name; - return filterTranslations.ready(); - }) - ]; - - // Get children wallets - if (!$scope.wallets) { - jobs.push( - csWallet.children.all() - .then(function(children) { - $scope.wallets = $scope.formData.showDefault ? [csWallet].concat(children) : children; - }) - ); - } - - // Prepare load options - var options = { - silent: true, - minData: true, - sources: $scope.formData.showBalance, - tx: { - enable: false - }, - api: true - }; - return $q.all(jobs) - // Load wallet data (apply a timeout between each wallet) - .then(function() { - var counter = 0; - return $q.all( - $scope.wallets.reduce(function(res, wallet){ - return wallet.isDataLoaded(options) ? - res : res.concat( - $timeout(function(){ - return wallet.loadData(options); - }, loadWalletWaitTime * counter++)); - }, []) - ); - }) - .then(function() { - $scope.loading = false; - UIUtils.loading.hide(); - $scope.updateView(); - }) - .catch(function(err) { - if (err && err === 'CANCELLED') { - $scope.loading = true; - $scope.cancel(); - throw err; - } - $scope.loading = false; - UIUtils.onError('ERROR.LOAD_WALLET_LIST_FAILED')(err); - }); - }; - $scope.$on('modal.shown', $scope.load); - - $scope.cancel = function() { - $scope.closeModal(); - }; - - $scope.select = function($event, wallet) { - $scope.closeModal(wallet); - }; - - $scope.updateView = function() { - if (!$scope.wallets.length) return; - - if ($scope.motion) { - $scope.motion.show({selector: '.list .item.item-wallet', ink: true}); - } - else { - UIUtils.ink({selector: '.list .item.item-wallet'}); - } - }; - - $scope.doUpdate = function(silent) { - if ($scope.loading || !$scope.wallets || !$scope.wallets.length) return $q.when(); - - $scope.loading = !silent; - - var options = { - silent: true, - sources: $scope.formData.showBalance, - tx: { - enable: false - }, - api: true - }; - return $q.all($scope.wallets.reduce(function(res, wallet, counter) { - return res.concat( - $timeout(function(){ - return wallet.refreshData(angular.merge({ - requirements: wallet.requirements && (wallet.requirements.isMember || wallet.requirements.wasMember || wallet.requirements.pendingMembership) - }, options)); - }, counter * loadWalletWaitTime)); - }, [])) - .then(function() { - $scope.loading = false; - if (silent) { - $scope.$broadcast('$$rebind::' + 'rebind'); // force rebind - } - $scope.updateView(); - }) - .catch(function(err) { - $scope.loading = false; - UIUtils.onError('ERROR.UPDATE_WALLET_LIST_FAILED')(err); - }); - }; - - // Default actions - $scope.setParameters(parameters); - -} - -function PopoverWalletSelectModalController($scope, $controller, UIUtils) { - 'ngInject'; - - // Initialize the super class and extend it. - angular.extend(this, $controller('WalletSelectModalCtrl', {$scope: $scope, parameters: { - showDefault: true, - showBalance: false - }})); - - // Disable list motion - $scope.motion = null; - - $scope.$on('popover.shown', function() { - if ($scope.loading) { - $scope.load(); - } - }); - - $scope.updateView = function() { - if (!$scope.wallets.length) return; - - UIUtils.ink({selector: '.popover-wallets .list .item'}); - }; - - $scope.select = function($event, wallet) { - if ($event.preventDefault() || !wallet) return; // no selection - $scope.closePopover(wallet); - }; -} diff --git a/www/js/controllers/wallets-controllers.js b/www/js/controllers/wallets-controllers.js new file mode 100644 index 0000000000000000000000000000000000000000..64ec8fe3ec8f7c2b69555547176d70208601dfca --- /dev/null +++ b/www/js/controllers/wallets-controllers.js @@ -0,0 +1,515 @@ +angular.module('cesium.wallets.controllers', ['cesium.services', 'cesium.currency.controllers']) + + .config(function($stateProvider) { + 'ngInject'; + $stateProvider + + .state('app.view_wallets', { + url: "/wallets", + views: { + 'menuContent': { + templateUrl: "templates/wallet/list/view_wallets.html", + controller: 'WalletListCtrl' + } + }, + data: { + login: true + } + }) + + .state('app.view_wallet_by_id', { + url: "/wallets/:id?refresh", + views: { + 'menuContent': { + templateUrl: "templates/wallet/view_wallet.html", + controller: 'WalletCtrl' + } + }, + data: { + login: true, + silentLocationChange: true + } + }) + + .state('app.view_wallet_tx_by_id', { + url: "/history/wallets/:id?refresh", + views: { + 'menuContent': { + templateUrl: "templates/wallet/view_wallet_tx.html", + controller: 'WalletTxCtrl' + } + }, + data: { + login: true, + silentLocationChange: true + } + }) + + .state('app.view_wallet_tx_errors_by_id', { + url: "/history/wallets/:id/errors", + views: { + 'menuContent': { + templateUrl: "templates/wallet/view_wallet_tx_error.html", + controller: 'WalletTxErrorCtrl' + } + }, + data: { + login: true + } + }) + ; + }) + + + .controller('WalletListCtrl', WalletListController) + + .controller('WalletSelectModalCtrl', WalletSelectModalController) + + .controller('PopoverWalletSelectModalCtrl', PopoverWalletSelectModalController) +; + +function WalletListController($scope, $controller, $state, $timeout, $q, $translate, $ionicPopover, $ionicPopup, + UIUtils, Modals, csCurrency, csSettings, csWallet){ + 'ngInject'; + + $scope.settings = csSettings.data; + $scope.listeners = []; + + + // Initialize the super class and extend it. + angular.extend(this, $controller('WalletSelectModalCtrl', {$scope: $scope, parameters: {}})); + + // Override defaults + $scope.formData.name = undefined; + $scope.motion = UIUtils.motion.default; + + $scope.enter = function(e, state) { + // First enter + if ($scope.loading) { + $scope.setParameters({ + showDefault: false, + showBalance: true + }); + + return $scope.load() + .then(function() { + UIUtils.loading.hide(); + if (!$scope.wallets) return; // user cancel + $scope.addListeners(); + $scope.showFab('fab-add-wallet'); + }); + } + else { + //$scope.addListeners(); + } + }; + $scope.$on('$ionicView.enter', $scope.enter); + + $scope.leave = function() { + //$scope.removeListeners(); + }; + $scope.$on('$ionicView.leave', $scope.leave); + + $scope.cancel = function() { + $scope.showHome(); + }; + + $scope.select = function(event, wallet) { + if (event.isDefaultPrevented()) return; + + $state.go('app.view_wallet_by_id', {id: wallet.id}); + }; + + + $scope.editWallet = function(event, wallet) { + + event.preventDefault(); + + return $scope.showEditPopup(wallet) + .then(function(newName) { + if (!newName) return; + + // Save changes + return csWallet.auth({minData: true}) + .then(function() { + wallet.data.localName = newName; + csWallet.storeData(); + UIUtils.loading.hide(); + $scope.updateView(); + }) + .catch(function(err) { + if (err === 'CANCELLED') { + return UIUtils.loading.hide(); + } + UIUtils.onError('ERROR.SAVE_WALLET_LIST_FAILED')(err); + }); + }); + }; + + /* -- modals -- */ + + $scope.showNewWalletModal = function() { + + var walletId = csWallet.children.count() + 1; + var wallet = csWallet.instance(walletId); + return wallet.login({ + showNewAccountLink: false, + title: 'ACCOUNT.WALLET_LIST.BTN_NEW', + okText: 'COMMON.BTN_ADD', + // Load data options : + minData: true, + sources: true, + api: false, + success: UIUtils.loading.show + }) + .then(function(walletData) { + if (!walletData) return; + + // Avoid to add main wallet again + if (walletData.pubkey === csWallet.data.pubkey) { + UIUtils.loading.hide(); + UIUtils.alert.error('ERROR.COULD_NOT_ADD_MAIN_WALLET'); + return; + } + + // Make sure to auth on the main wallet + return csWallet.auth({minData: true}) + .then(function() { + return csWallet.api.data.raisePromise.load(wallet.data) + // continue, when plugins extension failed (just log in console) + .catch(console.error) + .then(function() { + $scope.listeners.push(wallet.api.data.on.unauth($scope, $scope.updateView)); + $scope.listeners.push(wallet.api.data.on.auth($scope, $scope.updateView)); + csWallet.children.add(wallet); + UIUtils.loading.hide(); + $scope.updateView(); + }); + }) + .catch(function(err) { + if (err === 'CANCELLED') { + return UIUtils.loading.hide(); + } + UIUtils.onError('ERROR.ADD_SECONDARY_WALLET_FAILED')(err); + }); + }); + }; + + $scope.selectAndRemoveWallet = function() { + $scope.hideActionsPopover(); + return Modals.showSelectWallet({ + wallets: $scope.wallets, + showDefault: false + }) + .then(function(wallet) { + if (!wallet || !wallet.id) return; + + // Make sure to auth on the main wallet + return csWallet.auth({minData: true}) + .then(function() { + csWallet.children.remove(wallet.id); + UIUtils.loading.hide(); + $scope.updateView(); + }) + .catch(function(err) { + if (err === 'CANCELLED') { + return UIUtils.loading.hide(); + } + UIUtils.onError('ERROR.ADD_SECONDARY_WALLET_FAILED')(err); + }); + }); + }; + + /* -- popups -- */ + + $scope.setEditForm = function(editForm) { + $scope.editForm = editForm; + }; + + $scope.showEditPopup = function(wallet) { + return $q(function(resolve, reject) { + $translate(['ACCOUNT.WALLET_LIST.EDIT_POPOVER.TITLE', 'ACCOUNT.WALLET_LIST.EDIT_POPOVER.HELP', 'COMMON.BTN_OK', 'COMMON.BTN_CANCEL']) + .then(function (translations) { + $scope.formData.name = wallet.data.name || wallet.data.uid || wallet.data.pubkey.substring(0, 8); + + // Choose UID popup + $ionicPopup.show({ + templateUrl: 'templates/wallet/list/popup_edit_name.html', + title: translations['ACCOUNT.WALLET_LIST.EDIT_POPOVER.TITLE'], + subTitle: translations['ACCOUNT.WALLET_LIST.EDIT_POPOVER.HELP'], + scope: $scope, + buttons: [ + { text: translations['COMMON.BTN_CANCEL'] }, + { + text: translations['COMMON.BTN_OK'], + type: 'button-positive', + onTap: function(e) { + $scope.editForm.$submitted=true; + if(!$scope.editForm.$valid || !$scope.formData.name) { + //don't allow the user to close unless he enters a name + e.preventDefault(); + } else { + return $scope.formData.name; + } + } + } + ] + }) + .then(function(name) { + if (!name) { // user cancel + delete $scope.formData.name; + UIUtils.loading.hide(); + return; + } + resolve(name); + }); + }); + }); + }; + + /* -- popovers -- */ + + $scope.showActionsPopover = function(event) { + if (!$scope.actionsPopover) { + $ionicPopover.fromTemplateUrl('templates/wallet/list/popover_actions.html', { + scope: $scope + }).then(function(popover) { + $scope.actionsPopover = popover; + //Cleanup the popover when we're done with it! + $scope.$on('$destroy', function() { + $scope.actionsPopover.remove(); + }); + $scope.actionsPopover.show(event); + }); + } + else { + $scope.actionsPopover.show(event); + } + }; + + $scope.hideActionsPopover = function() { + if ($scope.actionsPopover) { + $scope.actionsPopover.hide(); + } + }; + + /* -- listeners -- */ + + $scope.addListeners = function() { + + var listeners = []; + + // Auto-update on new block + if (csSettings.data.walletHistoryAutoRefresh) { + listeners.push( + csCurrency.api.data.on.newBlock($scope, function (block) { + if ($scope.loading) return; + console.debug("[wallet-list] Received new block. Will reload list."); + $timeout(function () { + $scope.doUpdate(true); + }, 300/*waiting for node cache propagation*/); + })); + } + + // Listen auth events on each wallet + $scope.listeners = ($scope.wallets||[]).reduce(function(res, wallet) { + return res.concat([ + wallet.api.data.on.unauth($scope, $scope.updateView), + wallet.api.data.on.auth($scope, $scope.updateView), + ]); + }, listeners); + }; + + $scope.removeListeners = function() { + _.forEach($scope.listeners, function(remove){ + remove(); + }); + $scope.listeners = []; + }; + + var inheritedUpdateView = $scope.updateView; + $scope.updateView = function() { + inheritedUpdateView(); + $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; + $scope.formData.useRelative = $scope.settings.useRelative; + $scope.updateView(); + }, true); +} + +function WalletSelectModalController($scope, $q, $timeout, UIUtils, filterTranslations, csSettings, csCurrency, csWallet, parameters){ + 'ngInject'; + + var loadWalletWaitTime = 500; + $scope.loading = true; + $scope.formData = { + useRelative: csSettings.data.useRelative, + showDefault: true, + showBalance: false + }; + $scope.motion = null; // no animation + + $scope.setParameters = function(parameters) { + parameters = parameters || {}; + + $scope.formData.useRelative = angular.isDefined(parameters.useRelative) ? parameters.useRelative : $scope.formData.useRelative; + + $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.load = function() { + $scope.loading = true; + + // Load currency, and filter translations (need by 'formatAmount' filter) + var jobs = [ + csCurrency.name() + .then(function(name) { + $scope.currency = name; + return filterTranslations.ready(); + }) + ]; + + // Get children wallets + if (!$scope.wallets) { + jobs.push( + csWallet.children.all() + .then(function(children) { + $scope.wallets = $scope.formData.showDefault ? [csWallet].concat(children) : children; + }) + ); + } + + // Prepare load options + var options = { + silent: true, + minData: true, + sources: $scope.formData.showBalance, + tx: { + enable: false + }, + api: true + }; + return $q.all(jobs) + // Load wallet data (apply a timeout between each wallet) + .then(function() { + var counter = 0; + return $q.all( + $scope.wallets.reduce(function(res, wallet){ + return wallet.isDataLoaded(options) ? + res : res.concat( + $timeout(function(){ + return wallet.loadData(options); + }, loadWalletWaitTime * counter++)); + }, []) + ); + }) + .then(function() { + $scope.loading = false; + UIUtils.loading.hide(); + $scope.updateView(); + }) + .catch(function(err) { + if (err && err === 'CANCELLED') { + $scope.loading = true; + $scope.cancel(); + throw err; + } + $scope.loading = false; + UIUtils.onError('ERROR.LOAD_WALLET_LIST_FAILED')(err); + }); + }; + $scope.$on('modal.shown', $scope.load); + + $scope.cancel = function() { + $scope.closeModal(); + }; + + $scope.select = function($event, wallet) { + $scope.closeModal(wallet); + }; + + $scope.updateView = function() { + if (!$scope.wallets.length) return; + + if ($scope.motion) { + $scope.motion.show({selector: '.list .item.item-wallet', ink: true}); + } + else { + UIUtils.ink({selector: '.list .item.item-wallet'}); + } + }; + + $scope.doUpdate = function(silent) { + if ($scope.loading || !$scope.wallets || !$scope.wallets.length) return $q.when(); + + $scope.loading = !silent; + + var options = { + silent: true, + sources: $scope.formData.showBalance, + tx: { + enable: false + }, + api: true + }; + return $q.all($scope.wallets.reduce(function(res, wallet, counter) { + return res.concat( + $timeout(function(){ + return wallet.refreshData(angular.merge({ + requirements: wallet.requirements && (wallet.requirements.isMember || wallet.requirements.wasMember || wallet.requirements.pendingMembership) + }, options)); + }, counter * loadWalletWaitTime)); + }, [])) + .then(function() { + $scope.loading = false; + if (silent) { + $scope.$broadcast('$$rebind::' + 'rebind'); // force rebind + } + $scope.updateView(); + }) + .catch(function(err) { + $scope.loading = false; + UIUtils.onError('ERROR.UPDATE_WALLET_LIST_FAILED')(err); + }); + }; + + // Default actions + $scope.setParameters(parameters); + +} + +function PopoverWalletSelectModalController($scope, $controller, UIUtils) { + 'ngInject'; + + // Initialize the super class and extend it. + angular.extend(this, $controller('WalletSelectModalCtrl', {$scope: $scope, parameters: { + showDefault: true, + showBalance: false + }})); + + // Disable list motion + $scope.motion = null; + + $scope.$on('popover.shown', function() { + if ($scope.loading) { + $scope.load(); + } + }); + + $scope.updateView = function() { + if (!$scope.wallets.length) return; + + UIUtils.ink({selector: '.popover-wallets .list .item'}); + }; + + $scope.select = function($event, wallet) { + if ($event.preventDefault() || !wallet) return; // no selection + $scope.closePopover(wallet); + }; +} diff --git a/www/plugins/es/js/controllers/profile-controllers.js b/www/plugins/es/js/controllers/profile-controllers.js index cd2e2a8af18e843b07cfcf931ebc987ce4a1d3b7..f2e87fbf23b1983a947efbba688ff21c6ded47bf 100644 --- a/www/plugins/es/js/controllers/profile-controllers.js +++ b/www/plugins/es/js/controllers/profile-controllers.js @@ -72,11 +72,9 @@ function ESViewEditProfileController($scope, $q, $timeout, $state, $focus, $tran return $scope.showHome(); } - $scope.loadWallet({ - wallet: wallet, - auth: true, - minData: true - }) + return wallet.auth({ + minData: true + }) .then($scope.load) .catch(function(err){ if (err == 'CANCELLED') { @@ -152,34 +150,32 @@ function ESViewEditProfileController($scope, $q, $timeout, $state, $focus, $tran $scope.updateView(walletData, {}); } + UIUtils.loading.hide(); + + // Update loading - done with a delay, to avoid trigger onFormDataChanged() + return $timeout(function() { + $scope.loading = false; + }, 1000); + }) + .then(function() { // removeIf(device) $focus('profile-name'); // endRemoveIf(device) }) - .catch(function(err){ - UIUtils.loading.hide(10); - UIUtils.onError('PROFILE.ERROR.LOAD_PROFILE_FAILED')(err); - }); + .catch(UIUtils.onError('PROFILE.ERROR.LOAD_PROFILE_FAILED')); }; $scope.setForm = function(form) { $scope.form = form; }; - $scope.updateView = function(wallet, profile) { - $scope.walletData = wallet; + $scope.updateView = function(walletData, profile) { + $scope.walletData = walletData; $scope.formData = profile; if (profile.avatar) { $scope.avatarStyle={'background-image':'url("'+$scope.avatar.src+'")'}; } - $scope.motion.show(); - UIUtils.loading.hide(); - - // Update loading - done with a delay, to avoid trigger onFormDataChanged() - $timeout(function() { - $scope.loading = false; - }, 1000); }; $scope.onFormDataChanged = function() { diff --git a/www/plugins/es/js/controllers/registry-controllers.js b/www/plugins/es/js/controllers/registry-controllers.js index 1c2f782ea3688ecdacfb2bcf2b79818b6d29d2ef..218a4adba30c8b2035d72852bd554056a505eac4 100644 --- a/www/plugins/es/js/controllers/registry-controllers.js +++ b/www/plugins/es/js/controllers/registry-controllers.js @@ -1026,7 +1026,6 @@ function ESRegistryRecordEditController($scope, $timeout, $state, $q, $ionicHis if ($scope.loading) { wallet = (state.stateParams && state.stateParams.wallet && state.stateParams.wallet != 'default') ? csWallet.children.get(state.stateParams.wallet) : csWallet; - console.log(wallet); if (!wallet) { UIUtils.alert.error('ERROR.UNKNOWN_WALLET_ID'); return $scope.showHome(); diff --git a/www/plugins/es/js/services/settings-services.js b/www/plugins/es/js/services/settings-services.js index d05402be681c30bd9fa069e5550bc2c5fccb80da..21724f6cde3f1848a8befe05a5356e1012ff97a9 100644 --- a/www/plugins/es/js/services/settings-services.js +++ b/www/plugins/es/js/services/settings-services.js @@ -217,7 +217,6 @@ angular.module('cesium.es.settings.services', ['cesium.services', 'cesium.es.htt var isEnable = that.isEnable(); if (isEnable && csWallet.isAuth()) { - console.log(data); if (!wasEnable) { onWalletAuth(csWallet.data); } diff --git a/www/plugins/map/js/controllers/wot-controllers.js b/www/plugins/map/js/controllers/wot-controllers.js index 892abd3fe245f41d279b7257d4259f655783d4e3..99de21daa3a68523669506f8272d0f06c1d527ca 100644 --- a/www/plugins/map/js/controllers/wot-controllers.js +++ b/www/plugins/map/js/controllers/wot-controllers.js @@ -379,8 +379,6 @@ function MapWotViewController($scope, $filter, $templateCache, $interpolate, $ti return $timeout(function(){ $scope.loading = false; - console.log("dataload"); - // hide loading indicator map.fire('dataload'); diff --git a/www/templates/wallet/list/item_wallet.html b/www/templates/wallet/list/item_wallet.html index df687f0b27f6bed48ad4b823659f518f33de14f8..1fdc2484d9baa95fb636a8965342e31b572b2e02 100644 --- a/www/templates/wallet/list/item_wallet.html +++ b/www/templates/wallet/list/item_wallet.html @@ -5,7 +5,7 @@ <i ng-if="::!walletData.avatar" class="item-image icon" ng-class=":rebind:{'ion-card': !walletData.isMember, 'ion-persion': walletData.isMember}"></i> <i ng-if="::walletData.avatar" class="item-image avatar" style="background-image: url({{::walletData.avatar.src}})"></i> - <!--<i ng-hide=":rebind:wallet.isAuth()" class="icon-secondary assertive ion-locked" style="top: -16px; left: 66px; font-size: 20px;"></i>--> + <i ng-hide=":rebind:wallet.isAuth()" class="icon-secondary assertive ion-locked" style="top: -16px; left: 66px; font-size: 20px;"></i> <h2> <span class="text-editable" ng-click="editWallet($event, wallet)" title="{{'ACCOUNT.WALLET_LIST.BTN_RENAME'|translate}}"> <ng-if ng-if=":rebind:walletData.localName||walletData.name||walletData.uid" ng-bind-html="::walletData.localName||walletData.name||walletData.uid"></ng-if> @@ -39,7 +39,7 @@ <span class="badge" ng-if="formData.showBalance" ng-class=":rebind:{'badge-assertive': (walletData.balance <= 0), 'badge-balanced': (walletData.balance > 0) }"> - <span ng-bind-html=":rebind:walletData.balance|formatAmount:{useRelative: true, currency: currency}"></span> + <span ng-bind-html=":rebind:walletData.balance|formatAmount:{useRelative: formData.useRelative, currency: currency}"></span> </span> <i class="icon ion-ios-arrow-right "></i>