diff --git a/www/i18n/locale-fr-FR.json b/www/i18n/locale-fr-FR.json index aac23b1f133895afa691fdaea5d98c03545f6289..32c9eef8c845511b59819aebe2dd56fd33193ca8 100644 --- a/www/i18n/locale-fr-FR.json +++ b/www/i18n/locale-fr-FR.json @@ -579,7 +579,7 @@ "NEED_MEMBER_ACCOUNT_TO_CERTIFY_HAS_SELF": "Vous ne pouvez pas effectuer de certification, car votre compte n'est pas encore membre.<br/><br/>Il vous manque encore des certifications, ou bien celles-ci n'ont pas encore été validées.", "NOT_MEMBER_FOR_CERTIFICATION": "Votre compte n'est pas encore membre.", "IDENTITY_TO_CERTIFY_HAS_NO_SELF": "Compte non certifiable. Aucune demande d'adhésion n'a été faite, ou bien elle n'a pas été renouvellée.", - "LOGIN_FAILED": "Erreur lors de l'authentification.", + "LOGIN_FAILED": "Erreur lors de la connexion.", "LOAD_IDENTITY_FAILED": "Erreur de chargement de l'identité.", "LOAD_REQUIREMENTS_FAILED": "Erreur de chargement des prérequis de l'identité.", "SEND_MEMBERSHIP_IN_FAILED": "Echec de la tentative d'entrée dans la communauté.", diff --git a/www/js/controllers/app-controllers.js b/www/js/controllers/app-controllers.js index f922c2337065df8c5006672e2206eb8ee1c11d48..8604bd2c042a0fe2dd2e14709b4db8799eb1f8b7 100644 --- a/www/js/controllers/app-controllers.js +++ b/www/js/controllers/app-controllers.js @@ -256,8 +256,8 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ }); } - // Laready login ro auth - else if (!csWallet.data.loaded) { + // Already login or auth + else if (!csWallet.isDataLoaded(options)) { return $scope.loadWalletData(options); } else { @@ -365,20 +365,7 @@ function AppController($scope, $rootScope, $state, $ionicSideMenuDelegate, $q, $ // Open transfer modal $scope.showTransferModal = function(parameters) { - return $scope.loadWallet() - .then(function(walletData){ - UIUtils.loading.hide(); - if (walletData) { - return Modals.showTransfer(parameters); - } - }) - .then(function(result){ - if (result){ - return $timeout(function(){ - return UIUtils.toast.show('INFO.TRANSFER_SENT'); - }, 10); - } - }); + return Modals.showTransfer(parameters); }; $scope.showAboutModal = function() { diff --git a/www/js/controllers/blockchain-controllers.js b/www/js/controllers/blockchain-controllers.js index 1296714c12fba4966ef0e75e503231b8477831f9..dba9f40fef5388b71effb27b0042a80c6d7ccfbf 100644 --- a/www/js/controllers/blockchain-controllers.js +++ b/www/js/controllers/blockchain-controllers.js @@ -166,7 +166,7 @@ function BlockLookupController($scope, $timeout, $focus, $filter, $state, $ancho UIUtils.alert.error('ERROR.GET_CURRENCY_FAILED'); return; } - $scope.enter(); // back to enter() + $scope.enter(); // back to enter(), with no stateParams }) .catch(UIUtils.onError('ERROR.GET_CURRENCY_FAILED')); } @@ -444,9 +444,12 @@ function BlockLookupController($scope, $timeout, $focus, $filter, $state, $ancho $anchorScroll('block-' + block.number); }, 900); } - else { + else if (BMA.node.same($scope.node.host, $scope.node.port)) { $state.go('app.view_block_hash', {number: block.number, hash: block.hash}); } + else { + $state.go('app.view_server_block_hash', {server: $scope.node.server, ssl: $scope.node.useSsl, number: block.number, hash: block.hash}); + } }; $scope.toggleCompactMode = function() { @@ -495,43 +498,44 @@ function BlockViewController($scope, $ionicPopover, $state, UIUtils, BMA, csCurr $scope.enter = function(e, state) { if (!$scope.loading) return; // call once - $scope.number = state && state.stateParams && angular.isDefined(state.stateParams.number) ? state.stateParams.number : 'current'; - $scope.hash = state && state.stateParams && state.stateParams.hash ? state.stateParams.hash : undefined; - - // Load from server if need - if (state && state.stateParams && state.stateParams.server) { - var useSsl = state.stateParams.ssl == "true"; - var useTor = state.stateParams.tor == "true"; - - var node = { - server: state.stateParams.server, - host: state.stateParams.server, - useSsl: useSsl, - useTor: useTor - }; - var serverParts = state.stateParams.server.split(':'); - if (serverParts.length == 2) { - node.host = serverParts[0]; - node.port = serverParts[1]; - } + if (state) { + $scope.number = state.stateParams && angular.isDefined(state.stateParams.number) ? state.stateParams.number : 'current'; + $scope.hash = state.stateParams && state.stateParams.hash ? state.stateParams.hash : undefined; - if (BMA.node.same(node.host, node.port)) { - $scope.node = BMA; - } - else { - $scope.node = useTor ? - // For TOR, use a web2tor to access the endpoint - BMA.instance(node.host + ".to", 443, true/*ssl*/, 600000 /*long timeout*/) : - BMA.instance(node.host, node.port, node.useSsl); - return $scope.node.blockchain.parameters() - .then(function(json) { - $scope.currency = json.currency; - $scope.enter(); // back to enter() - }); + // Load from server if need + if (state.stateParams && state.stateParams.server) { + var useSsl = state.stateParams.ssl == "true"; + var useTor = state.stateParams.tor == "true"; + + var node = { + server: state.stateParams.server, + host: state.stateParams.server, + useSsl: useSsl, + useTor: useTor + }; + var serverParts = state.stateParams.server.split(':'); + if (serverParts.length == 2) { + node.host = serverParts[0]; + node.port = serverParts[1]; + } + + if (BMA.node.same(node.host, node.port)) { + $scope.node = BMA; + } + else { + $scope.node = useTor ? + // For TOR, use a web2tor to access the endpoint + BMA.instance(node.host + ".to", 443, true/*ssl*/, 600000 /*long timeout*/) : + BMA.instance(node.host, node.port, node.useSsl); + return $scope.node.blockchain.parameters() + .then(function (json) { + $scope.currency = json.currency; + $scope.enter(); // back to enter(), with no stateParams + }); + } } } - if (!$scope.currency || !$scope.node) { csCurrency.get() .then(function (currency) { diff --git a/www/js/controllers/transfer-controllers.js b/www/js/controllers/transfer-controllers.js index 6333a3e4e8a27afc81d9805139ed5bdd28e1d5c2..fbeb2261dc11a1d63904f60b107d95a71f61d811 100644 --- a/www/js/controllers/transfer-controllers.js +++ b/www/js/controllers/transfer-controllers.js @@ -70,12 +70,14 @@ function TransferController($scope, $controller, UIUtils, csWot) { parameters.comment = state.stateParams.comment; } } + $scope.setParameters(parameters); // Make sure wallet is loaded - $scope.loadWallet() + $scope.login({sources: true}) - // If pubkey, get the uid (+ name, avatar) - .then(function() { + // If pubkey, get the uid (+ name, avatar) + .then(function(data) { + $scope.walletData = data; if (parameters.pubkey) { return csWot.extend({pubkey: parameters.pubkey}) .then(function(dest) { @@ -88,9 +90,10 @@ function TransferController($scope, $controller, UIUtils, csWot) { // Apply parameters, then recompute relative amount .then(function() { - $scope.setParameters(parameters); + $scope.onUseRelativeChanged(); UIUtils.loading.hide(); + $scope.loading = false; UIUtils.ink({selector: '.modal-transfer .ink'}); }); }; @@ -106,7 +109,7 @@ function TransferController($scope, $controller, UIUtils, csWot) { }; } -function TransferModalController($scope, $translate, $filter, BMA, csWallet, UIUtils, Modals, +function TransferModalController($scope, $q, $translate, $filter, BMA, csWallet, UIUtils, Modals, csCurrency, csSettings, parameters) { 'ngInject'; @@ -121,6 +124,7 @@ function TransferModalController($scope, $translate, $filter, BMA, csWallet, UIU $scope.udAmount = null; $scope.commentPattern = BMA.regexp.COMMENT; $scope.currency = csCurrency.data.name; + $scope.loading = true; $scope.setParameters = function(parameters) { if (!parameters) return; @@ -153,6 +157,17 @@ function TransferModalController($scope, $translate, $filter, BMA, csWallet, UIU $scope.enter = function() { UIUtils.ink({selector: '.modal-transfer .ink'}); + + // Make to sure to load full wallet data (balance) + return csWallet.login({sources: true}) + .then(function(data) { + $scope.walletData = data; + $scope.loading = false; + }) + .catch(function(err){ + if (err == 'CANCELLED') return $scope.cancel(); // close the modal + UIUtils.onError('ERROR.LOGIN_FAILED')(err); + }); }; $scope.$on('modal.shown', $scope.enter); @@ -197,8 +212,17 @@ function TransferModalController($scope, $translate, $filter, BMA, csWallet, UIU return; } - return csWallet.auth() - .then(UIUtils.loading.hide) + var currentUD; + return $q.all([ + // Make sure user is auth + csWallet.auth({silent: true}), + + // Get current UD + csCurrency.currentUD() + .then(function(res) { + currentUD = res; + }) + ]) .then($scope.askTransferConfirm) .then(function(confirm){ if (!confirm) return; @@ -210,10 +234,10 @@ function TransferModalController($scope, $translate, $filter, BMA, csWallet, UIU amount = parseFloat(amount.replace(new RegExp('[.,]'), '.')); } if ($scope.formData.useRelative) { - amount = csWallet.data.currentUD * amount; + amount = currentUD * amount; } else { - amount = amount * 100; // remove 2 decimals of quantitative mode + amount = amount.toFixed(2) * 100; // remove 2 decimals on quantitative mode } return csWallet.transfer($scope.formData.destPub, amount, $scope.formData.comment, $scope.formData.useRelative); @@ -222,6 +246,9 @@ function TransferModalController($scope, $translate, $filter, BMA, csWallet, UIU return $scope.closeModal(true); }) .then(UIUtils.loading.hide) + .then(function() { + UIUtils.toast.show('INFO.TRANSFER_SENT'); + }) .catch(UIUtils.onError('ERROR.SEND_TX_FAILED')); }); }; diff --git a/www/js/controllers/wallet-controllers.js b/www/js/controllers/wallet-controllers.js index f5bb85277f9b006ca2330d18270cfb57a0b5140b..3af2dc7ce58a132fc23dd3c3d27fcf02f2519d0c 100644 --- a/www/js/controllers/wallet-controllers.js +++ b/www/js/controllers/wallet-controllers.js @@ -573,6 +573,7 @@ function WalletTxController($scope, $filter, $ionicPopover, $state, $timeout, UI $scope.updateUnit(); $scope.motion.show({ink: false}); }; + csWallet.api.data.on.balanceChanged($scope, $scope.updateView); $scope.downloadHistoryFile = function(options) { options = options || {}; @@ -585,15 +586,9 @@ function WalletTxController($scope, $filter, $ionicPopover, $state, $timeout, UI $scope.doUpdate = function() { console.debug('[wallet] TX history reloading...'); return UIUtils.loading.show() - .then(function() { - return csWallet.refreshData(); - }) - .then(function() { - return UIUtils.loading.hide(); - }) - .then(function() { - $scope.updateView(); - }) + .then(csWallet.refreshData) + .then(UIUtils.loading.hide) + .then($scope.updateView) .catch(UIUtils.onError('ERROR.REFRESH_WALLET_DATA')); }; @@ -610,8 +605,6 @@ function WalletTxController($scope, $filter, $ionicPopover, $state, $timeout, UI .then(function(done){ if (done) { UIUtils.toast.show('INFO.TRANSFER_SENT'); - $scope.$broadcast('$$rebind::' + 'balance'); // force rebind balance - $scope.motion.show({selector: '.item-pending'}); } }); }; diff --git a/www/js/services/wallet-services.js b/www/js/services/wallet-services.js index bce5d17f632203f59f9dcfcf2aecd9efcfc14f16..de44cd1966b6a96f295f5a1017a3c71b97cb1d4c 100644 --- a/www/js/services/wallet-services.js +++ b/www/js/services/wallet-services.js @@ -110,6 +110,11 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se // user already login if (!needLogin && !needAuth) { + // Load data + if (!data.loaded) { + var loadOptions = options && angular.isDefined(options.minData) ? {minData: true} : undefined; + return loadData(loadOptions); + } return $q.when(data); } var keepAuth = csSettings.data.keepAuthIdle > 0; @@ -887,6 +892,10 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se return csWot.extendAll([pendingTx], 'pubkey') .then(function() { data.tx.pendings.unshift(pendingTx); + + // API extension + api.data.raise.balanceChanged(data); + api.data.raise.newTx(data); }); }); }); @@ -1600,6 +1609,11 @@ angular.module('cesium.wallet.services', ['ngApi', 'ngFileSaver', 'cesium.bma.se api.registerEvent('data', 'load'); api.registerEvent('data', 'logout'); api.registerEvent('data', 'reset'); + + // Data changed : balance changed, new TX + api.registerEvent('data', 'balanceChanged'); + api.registerEvent('data', 'newTx'); + api.registerEvent('action', 'certify'); // init data diff --git a/www/plugins/map/js/controllers/network-controllers.js b/www/plugins/map/js/controllers/network-controllers.js index a0df7e4d104177222a67b423ed7ce4e1a30ca60a..eaaeba27d356bade8f19a3ff1f034d480885636f 100644 --- a/www/plugins/map/js/controllers/network-controllers.js +++ b/www/plugins/map/js/controllers/network-controllers.js @@ -228,12 +228,7 @@ angular.module('cesium.map.network.controllers', ['cesium.services', 'cesium.map iconSize: L.point(0, 0) }), title: searchText, - uid: peer.uid, - name: peer.name, - pubkey: peer.pubkey, - ipv4: searchIp, - port: bma.port, - server: (peer.dns || peer.server) + peer: angular.extend({ipv4: searchIp}, peer) })); }) .catch(function(err) { diff --git a/www/plugins/map/templates/network/item_search_tooltip.html b/www/plugins/map/templates/network/item_search_tooltip.html index 32937b25ecf85384c8d1321119688039648ebbfa..596d3db687e75fd57b87e1701b0256d9b0a8311b 100644 --- a/www/plugins/map/templates/network/item_search_tooltip.html +++ b/www/plugins/map/templates/network/item_search_tooltip.html @@ -1,8 +1,9 @@ <a href="#"> - {{server}} - <span class="{{uid ? 'positive' : 'gray'}}"> - <i class="icon {{uid ? 'ion-person' : 'ion-key'}}"></i> - {{uid ? (name||uid) : (pubkey|formatPubkey) }} + {{peer.dns || peer.server}} + <span class="{{peer.uid ? 'positive' : 'gray'}}"> + <i class="icon {{peer.uid ? 'ion-person' : 'ion-key'}}"></i> + {{peer.uid ? (peer.name||peer.uid) : (peer.pubkey|formatPubkey) }} </span> - <span class="gray">{{ipv4 ? (ipv4 + ':' + port) : ''}}</span> + <span class="gray">{{peer.ipv4 ? (peer.ipv4 + ':' + peer.port) : ''}}</span> + <span class="{{peer.bma.useSsl ? '' : 'ng-hide'}}"><i class="ion-locked"></i> <small>SSL</small></span> </a> diff --git a/www/templates/wallet/transfer_form.html b/www/templates/wallet/transfer_form.html index 36de11dac9a188fa9d86155ef7ee29cd99093dd5..509d7d6340c58fbd939cf5c4fce8123a6025afda 100644 --- a/www/templates/wallet/transfer_form.html +++ b/www/templates/wallet/transfer_form.html @@ -24,16 +24,16 @@ <span class="item item-text-wrap"> <span class="gray" translate>TRANSFER.FROM</span> - <span class="badge animate-fade-in animate-show-hide ng-hide" ng-show="!$root.loading" + <span class="badge animate-fade-in animate-show-hide ng-hide" ng-show="!$root.loading && !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"> - <i class="ion-key"></i> {{$root.walletData.pubkey| formatPubkey}} + <ion-spinner icon="android" ng-if="!walletData.pubkey"></ion-spinner> + <span ng-if="walletData.pubkey && !walletData.isMember"> + <i class="ion-key"></i> {{walletData.pubkey| formatPubkey}} </span> - <span ng-if="$root.walletData.isMember"> - <i class="ion-person"></i> {{$root.walletData.name||$root.walletData.uid}} + <span ng-if="walletData.isMember"> + <i class="ion-person"></i> {{walletData.name||walletData.uid}} </span> - <span ng-bind-html="$root.walletData.balance|formatAmount:{useRelative: formData.useRelative, currency:currency}"></span> + <span ng-bind-html="walletData.balance|formatAmount:{useRelative: formData.useRelative, currency:currency}"></span> </span> </span>