Skip to content
Snippets Groups Projects
Commit 36b51977 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

- Currency: left data (and BC time) not updated when new block - fix #258

- Network: do not load full BMA node object for network scanning
parent 62010955
No related branches found
No related tags found
No related merge requests found
...@@ -24,4 +24,4 @@ ...@@ -24,4 +24,4 @@
"version": "12.41.296.5" "version": "12.41.296.5"
} }
] ]
} }
\ No newline at end of file
...@@ -100,7 +100,7 @@ function CurrencyLookupController($scope, $state, UIUtils, csCurrency) { ...@@ -100,7 +100,7 @@ function CurrencyLookupController($scope, $state, UIUtils, csCurrency) {
}; };
} }
function CurrencyViewController($scope, $q, BMA, UIUtils, csSettings, csCurrency) { function CurrencyViewController($scope, $q, $timeout, BMA, UIUtils, csSettings, csCurrency, csNetwork) {
$scope.formData = { $scope.formData = {
useRelative: csSettings.data.useRelative, useRelative: csSettings.data.useRelative,
currency: '', currency: '',
...@@ -120,49 +120,59 @@ function CurrencyViewController($scope, $q, BMA, UIUtils, csSettings, csCurrency ...@@ -120,49 +120,59 @@ function CurrencyViewController($scope, $q, BMA, UIUtils, csSettings, csCurrency
stepMax: 0, stepMax: 0,
xpercent: 0, xpercent: 0,
durationFromLastUD: 0, durationFromLastUD: 0,
blockUid: null
}; };
$scope.node = null; $scope.node = null;
$scope.loading = true; $scope.loading = true;
$scope.screen = UIUtils.screen; $scope.screen = UIUtils.screen;
$scope.$on('$ionicView.enter', function(e, state) { $scope.$on('$ionicView.enter', function(e, state) {
if (state.stateParams && state.stateParams.name) { // Load by name if ($scope.loading) { // run only once (first enter)
csCurrency.searchByName(state.stateParams.name) if (state.stateParams && state.stateParams.name) { // Load by name
.then(function(currency){ csCurrency.searchByName(state.stateParams.name)
$scope.load(currency); .then(function(currency){
}); $scope.init(currency);
} });
else { }
csCurrency.all() else {
.then(function (currencies) { csCurrency.default()
if (currencies && currencies.length > 0) { .then(function (currency) {
$scope.load(currencies[0]); $scope.init(currency);
})
.catch(UIUtils.onError('ERROR.GET_CURRENCY_FAILED'));
}
csNetwork.api.data.on.mainBlockChanged($scope, function(data) {
if ($scope.loading) return;
if ($scope.formData.blockUid !== data.mainBuid) {
console.debug("[currency] Updating parameters UI (new main block detected)");
$timeout($scope.load, 1000 /*waiting propagation to requested node*/);
} }
}) });
.catch(UIUtils.onError('ERROR.GET_CURRENCY_FAILED'));
} }
}); });
$scope.load = function(currency) { $scope.init = function(currency) {
$scope.formData.currency = currency.name; $scope.formData.currency = currency.name;
$scope.node = !BMA.node.same(currency.peer.host, currency.peer.port) ? $scope.node = !BMA.node.same(currency.peer.host, currency.peer.port) ?
BMA.instance(currency.peer.host, currency.peer.port) : BMA; BMA.instance(currency.peer.host, currency.peer.port) : BMA;
UIUtils.loading.show(); UIUtils.loading.show();
// Load currency parameters // Load data
$scope.loadParameter(); $scope.load()
// Show help tip // Show help tip
$scope.showHelpTip(); .then($scope.showHelpTip);
}; };
$scope.loadParameter = function() { $scope.load = function() {
if (!$scope.node) { if (!$scope.node) {
return; return;
} }
// Load data from node // Load data from node
var data = {}; var data = {}, M, lastUDTime, now = new Date().getTime();
var M, lastUDTime;
return $q.all([ return $q.all([
// Get the currency parameters // Get the currency parameters
...@@ -186,6 +196,7 @@ function CurrencyViewController($scope, $q, BMA, UIUtils, csSettings, csCurrency ...@@ -186,6 +196,7 @@ function CurrencyViewController($scope, $q, BMA, UIUtils, csSettings, csCurrency
data.N = block.membersCount; data.N = block.membersCount;
data.medianTime = block.medianTime; data.medianTime = block.medianTime;
data.difficulty = block.powMin; data.difficulty = block.powMin;
data.blockUid = [block.number, block.hash].join('-');
}) })
.catch(function(err){ .catch(function(err){
// Special case for currency init (root block not exists): use fixed values // Special case for currency init (root block not exists): use fixed values
...@@ -231,13 +242,15 @@ function CurrencyViewController($scope, $q, BMA, UIUtils, csSettings, csCurrency ...@@ -231,13 +242,15 @@ function CurrencyViewController($scope, $q, BMA, UIUtils, csSettings, csCurrency
data.MoverN = (Mprev ? Mprev : M/*need at currency start only*/) / data.Nprev; data.MoverN = (Mprev ? Mprev : M/*need at currency start only*/) / data.Nprev;
data.UD = data.currentUD; data.UD = data.currentUD;
data.durationFromLastUD = lastUDTime ? data.medianTime - lastUDTime : 0; data.durationFromLastUD = lastUDTime ? data.medianTime - lastUDTime : 0;
data.useRelative = $scope.formData.useRelative;
// Apply to formData // Apply to formData
angular.copy(data, $scope.formData); angular.copy(data, $scope.formData);
console.debug("[currency] Parameters loaded in " + (new Date().getTime() - now) + 'ms' );
$scope.loading = false; $scope.loading = false;
$scope.$broadcast('$$rebind::' + 'rebind'); // force bind of currency name $scope.$broadcast('$$rebind::' + 'rebind'); // force bind of currency name
UIUtils.loading.hide(); return UIUtils.loading.hide();
}) })
.catch(function(err) { .catch(function(err) {
$scope.loading = false; $scope.loading = false;
......
...@@ -76,7 +76,7 @@ function NetworkLookupController($scope, $timeout, $state, $ionicPopover, BMA, U ...@@ -76,7 +76,7 @@ function NetworkLookupController($scope, $timeout, $state, $ionicPopover, BMA, U
if (!refreshing) { if (!refreshing) {
refreshing = true; refreshing = true;
$timeout(function() { // Timeout avoid to quick updates $timeout(function() { // Timeout avoid to quick updates
console.debug("Updating UI Peers"); console.debug("[peers] Updating UI");
$scope.search.results = data.peers; $scope.search.results = data.peers;
$scope.search.memberPeersCount = data.memberPeersCount; $scope.search.memberPeersCount = data.memberPeersCount;
$scope.search.loading = csNetwork.isBusy(); $scope.search.loading = csNetwork.isBusy();
......
This diff is collapsed.
angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.services']) angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.services', 'cesium.http.services'])
.factory('csNetwork', function($rootScope, $q, $interval, $timeout, BMA, Api, csSettings, UIUtils) { .factory('csNetwork', function($rootScope, $q, $interval, $timeout, BMA, csHttp, Api, csSettings, UIUtils) {
'ngInject'; 'ngInject';
factory = function(id) { factory = function(id) {
...@@ -64,6 +64,20 @@ angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.se ...@@ -64,6 +64,20 @@ angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.se
return data.knownBlocks; return data.knownBlocks;
}, },
newLightBMA = function(peer) {
return {
node: {
summary: csHttp.getWithCache(peer.getHost(), peer.getPort(), '/node/summary', csHttp.cache.LONG)
},
blockchain: {
current: csHttp.get(peer.getHost(), peer.getPort(), '/blockchain/current'),
stats: {
hardship: csHttp.get(peer.getHost(), peer.getPort(), '/blockchain/hardship/:pubkey')
}
}
};
},
loadPeers = function() { loadPeers = function() {
data.knownPeers = {}; data.knownPeers = {};
data.peers = []; data.peers = [];
...@@ -157,7 +171,7 @@ angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.se ...@@ -157,7 +171,7 @@ angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.se
// Apply filter // Apply filter
if (!applyPeerFilter(peer)) return $q.when(); if (!applyPeerFilter(peer)) return $q.when();
var node = new BMA.instance(peer.getHost(), peer.getPort(), false); var node = newLightBMA(peer);
// Get current block // Get current block
return node.blockchain.current() return node.blockchain.current()
...@@ -257,8 +271,9 @@ angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.se ...@@ -257,8 +271,9 @@ angular.module('cesium.network.services', ['ngResource', 'ngApi', 'cesium.bma.se
score += (-1 * (peer.uid ? peer.uid.charCodeAt(0) : 999)); // alphabetical order score += (-1 * (peer.uid ? peer.uid.charCodeAt(0) : 999)); // alphabetical order
return -score; return -score;
}); });
if (updateMainBuid) { if (updateMainBuid && mainBlock.buid) {
data.mainBuid = mainBlock.buid; data.mainBuid = mainBlock.buid;
console.log(data.mainBuid);
api.data.raise.mainBlockChanged(data); // raise event api.data.raise.mainBlockChanged(data); // raise event
} }
api.data.raise.changed(data); // raise event api.data.raise.changed(data); // raise event
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
<div class="item item-toggle dark"> <div class="item item-toggle dark">
<span translate>COMMON.BTN_RELATIVE_UNIT</span> <span translate>COMMON.BTN_RELATIVE_UNIT</span>
<label class="toggle toggle-royal" id="helptip-currency-change-unit" ng-if="!loading"> <label class="toggle toggle-royal" id="helptip-currency-change-unit">
<input type="checkbox" ng-model="formData.useRelative"> <input type="checkbox" ng-model="formData.useRelative">
<div class="track"> <div class="track">
<div class="handle"></div> <div class="handle"></div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment