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

-Currency: Fix amounts (after unit base rotation) - fix #73

parent 20c93a07
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
"BTN_PICTURE_DELETE": "Delete", "BTN_PICTURE_DELETE": "Delete",
"BTN_PICTURE_FAVORISE": "Default", "BTN_PICTURE_FAVORISE": "Default",
"UNIVERSAL_DIVIDEND": "Universal dividend", "UNIVERSAL_DIVIDEND": "Universal dividend",
"UD": "UD" "UD": "UD",
"DATE_PATTERN": "YYYY-MM-DD HH:mm"
}, },
"SYSTEM": { "SYSTEM": {
"PICTURE_CHOOSE_TYPE": "Choose picture source :", "PICTURE_CHOOSE_TYPE": "Choose picture source :",
......
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
"BTN_PICTURE_DELETE": "Supprimer", "BTN_PICTURE_DELETE": "Supprimer",
"BTN_PICTURE_FAVORISE": "Principale", "BTN_PICTURE_FAVORISE": "Principale",
"UNIVERSAL_DIVIDEND": "Dividende universel", "UNIVERSAL_DIVIDEND": "Dividende universel",
"UD": "DU" "UD": "DU",
"DATE_PATTERN": "DD/MM/YYYY HH:mm"
}, },
"SYSTEM": { "SYSTEM": {
"PICTURE_CHOOSE_TYPE": "Choisir la source :", "PICTURE_CHOOSE_TYPE": "Choisir la source :",
......
...@@ -13,7 +13,7 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'ngAnimate', ...@@ -13,7 +13,7 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'ngAnimate',
.filter('formatInteger', function() { .filter('formatInteger', function() {
return function(input) { return function(input) {
return input ? numeral(input).format('0,0').replace(',', ' ') : '0'; return !input ? '0' : numeral(input).format('0,0').replace(',', ' ');
}; };
}) })
...@@ -25,6 +25,14 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'ngAnimate', ...@@ -25,6 +25,14 @@ angular.module('cesium', ['ionic', 'ionic-material', 'ngMessages', 'ngAnimate',
}; };
}) })
.filter('formatNumeral', function() {
return function(input, pattern) {
if (!input) return '0';
if (Math.abs(input) < 0.0001) return '~ 0';
return numeral(input).format(pattern).replace(',', ' ');
};
})
.filter('formatDate', function() { .filter('formatDate', function() {
return function(input) { return function(input) {
// TODO: use local format // TODO: use local format
......
...@@ -242,7 +242,7 @@ function LoginModalController($scope, $rootScope, $ionicModal, Wallet, CryptoUti ...@@ -242,7 +242,7 @@ function LoginModalController($scope, $rootScope, $ionicModal, Wallet, CryptoUti
function AppController($scope, $rootScope, $ionicModal, $state, $ionicSideMenuDelegate, UIUtils, $q, $timeout, function AppController($scope, $rootScope, $ionicModal, $state, $ionicSideMenuDelegate, UIUtils, $q, $timeout,
CryptoUtils, BMA, Wallet, APP_CONFIG, $ionicHistory, Device, $translate, $ionicPopover CryptoUtils, BMA, Wallet, APP_CONFIG, $ionicHistory, Device, $ionicPopover
) { ) {
'ngInject'; 'ngInject';
......
...@@ -91,7 +91,7 @@ function CurrencyLookupController($scope, $state, $q, $timeout, UIUtils, APP_CON ...@@ -91,7 +91,7 @@ function CurrencyLookupController($scope, $state, $q, $timeout, UIUtils, APP_CON
}; };
} }
function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $interval, $timeout, Wallet) { function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $interval, $timeout, Wallet, $translate) {
PeersController.call(this, $scope, $rootScope, BMA, UIUtils, $q, $interval, $timeout); PeersController.call(this, $scope, $rootScope, BMA, UIUtils, $q, $interval, $timeout);
...@@ -110,10 +110,11 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i ...@@ -110,10 +110,11 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i
$scope.loading = true; $scope.loading = true;
$scope.$on('$ionicView.enter', function(e, $state) { $scope.$on('$ionicView.enter', function(e, $state) {
if (!!$scope.node) { $scope.closeNode();
$scope.node.websocket.block().close();
$scope.node = null; $translate(['COMMON.DATE_PATTERN'])
} .then(function($translations) {
$scope.datePattern = $translations['COMMON.DATE_PATTERN'];
if ($state.stateParams && $state.stateParams.name) { // Load by name if ($state.stateParams && $state.stateParams.name) { // Load by name
$scope.load($scope.name); $scope.load($scope.name);
} }
...@@ -127,6 +128,7 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i ...@@ -127,6 +128,7 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i
.catch(UIUtils.onError('ERROR.GET_CURRENCY_FAILED')); .catch(UIUtils.onError('ERROR.GET_CURRENCY_FAILED'));
} }
}); });
});
$scope.$on('$ionicView.beforeLeave', function(){ $scope.$on('$ionicView.beforeLeave', function(){
$scope.closeNode(); $scope.closeNode();
...@@ -174,20 +176,15 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i ...@@ -174,20 +176,15 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i
}; };
$scope.onUseRelativeChanged = function() { $scope.onUseRelativeChanged = function() {
if (!$scope.loading) { if ($scope.loading) return;
if ($scope.formData.useRelative) { if ($scope.formData.useRelative) {
$scope.M = $scope.M / $scope.currentUD; $scope.M = $scope.M / $scope.currentUD;
$scope.MoverN = $scope.MoverN / $scope.currentUD; $scope.MoverN = $scope.MoverN / $scope.currentUD;
$scope.UD = $scope.UD / $scope.currentUD; $scope.UD = $scope.UD / $scope.currentUD;
$scope.unit = 'universal_dividend';
$scope.udUnit = $scope.baseUnit;
} else { } else {
$scope.M = $scope.M * $scope.currentUD; $scope.M = $scope.M * $scope.currentUD;
$scope.MoverN = $scope.MoverN * $scope.currentUD; $scope.MoverN = $scope.MoverN * $scope.currentUD;
$scope.UD = $scope.UD * $scope.currentUD; $scope.UD = $scope.UD * $scope.currentUD;
$scope.unit = $scope.baseUnit;
$scope.udUnit = '';
}
} }
}; };
$scope.$watch('formData.useRelative', $scope.onUseRelativeChanged, true); $scope.$watch('formData.useRelative', $scope.onUseRelativeChanged, true);
...@@ -199,6 +196,8 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i ...@@ -199,6 +196,8 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i
UIUtils.loading.show(); UIUtils.loading.show();
var M;
$q.all([ $q.all([
// Get the currency parameters // Get the currency parameters
...@@ -206,8 +205,6 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i ...@@ -206,8 +205,6 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i
.then(function(json){ .then(function(json){
$scope.currency = json.currency; $scope.currency = json.currency;
$scope.c = json.c; $scope.c = json.c;
$scope.baseUnit = json.currency;
$scope.unit = json.currency;
$scope.dt = json.dt; $scope.dt = json.dt;
$scope.sigQty = json.sigQty; $scope.sigQty = json.sigQty;
}), }),
...@@ -215,9 +212,9 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i ...@@ -215,9 +212,9 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i
// Get the current block informations // Get the current block informations
$scope.node.blockchain.current() $scope.node.blockchain.current()
.then(function(block){ .then(function(block){
$scope.M = block.monetaryMass; M = block.monetaryMass;
$scope.N = block.membersCount; $scope.N = block.membersCount;
$scope.time = moment(block.medianTime*1000).format('YYYY-MM-DD HH:mm'); $scope.time = moment(block.medianTime*1000).format($scope.datePattern);
$scope.difficulty = block.powMin; $scope.difficulty = block.powMin;
}), }),
...@@ -228,8 +225,7 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i ...@@ -228,8 +225,7 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i
var lastBlockWithUD = res.result.blocks[res.result.blocks.length - 1]; var lastBlockWithUD = res.result.blocks[res.result.blocks.length - 1];
return $scope.node.blockchain.block({ block: lastBlockWithUD }) return $scope.node.blockchain.block({ block: lastBlockWithUD })
.then(function(block){ .then(function(block){
$scope.currentUD = block.dividend; $scope.currentUD = (block.unitbase > 0) ? block.dividend * Math.pow(10, block.unitbase) : block.dividend;
$scope.UD = block.dividend;
$scope.Nprev = block.membersCount; $scope.Nprev = block.membersCount;
}); });
} }
...@@ -238,20 +234,24 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i ...@@ -238,20 +234,24 @@ function CurrencyViewController($scope, $rootScope, $state, BMA, $q, UIUtils, $i
// Done // Done
.then(function(){ .then(function(){
$scope.M = $scope.M - $scope.UD*$scope.Nprev; var Mprev = M - $scope.currentUD * $scope.Nprev; // remove fresh money
$scope.MoverN = $scope.M / $scope.Nprev; var MoverN = Mprev / $scope.Nprev;
$scope.cactual = 100 * $scope.UD / $scope.MoverN; $scope.cactual = 100 * $scope.currentUD / MoverN;
//$scope.formData.useRelative = USE_RELATIVE_DEFAULT;
if ($scope.formData.useRelative) {
$scope.M = Mprev / $scope.currentUD;
$scope.MoverN = MoverN / $scope.currentUD;
$scope.UD = 1;
} else {
$scope.M = Mprev;
$scope.MoverN = MoverN;
$scope.UD = $scope.currentUD;
}
// Set Ink // Set Ink
UIUtils.ink({selector: '.peer-item'}); UIUtils.ink({selector: '.peer-item'});
$scope.loading = false; $scope.loading = false;
if ($scope.formData.useRelative) {
$scope.onUseRelativeChanged(); // convert to UD
}
UIUtils.loading.hide(); UIUtils.loading.hide();
}) })
.catch(function(err) { .catch(function(err) {
......
...@@ -112,7 +112,6 @@ angular.module('cesium.device.services', ['ngResource', 'cesium.utils.services'] ...@@ -112,7 +112,6 @@ angular.module('cesium.device.services', ['ngResource', 'cesium.utils.services']
} }
else { else {
UIUtils.toast.show('INFO.COPY_TO_CLIPBOARD_DONE'); UIUtils.toast.show('INFO.COPY_TO_CLIPBOARD_DONE');
console.log("Copy text to clipboard: " + text);
} }
}, function () { }, function () {
// error // error
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
<a href="#" class="item item-icon-left"> <a href="#" class="item item-icon-left">
<i class="icon ion-android-bookmark"></i> <i class="icon ion-android-bookmark"></i>
<span translate>CURRENCY.VIEW.CURRENCY_NAME</span> <span translate>CURRENCY.VIEW.CURRENCY_NAME</span>
<span class="item-note">{{currency}} ({{unit | abbreviate}}<sub>{{udUnit | abbreviate}}</sub>)</span> <span class="item-note" ng-if="!formData.useRelative">{{currency}} ({{currency | abbreviate}})</span>
<span class="item-note" ng-if="formData.useRelative">{{currency}} ({{'COMMON.UD' | translate}}<sub>{{currency | abbreviate}})</sub></span>
</a> </a>
<a class="item item-icon-left" href="#"> <a class="item item-icon-left" href="#">
...@@ -28,25 +29,28 @@ ...@@ -28,25 +29,28 @@
<a class="item item-icon-left" href="#"> <a class="item item-icon-left" href="#">
<i class="icon ion-record"></i> <i class="icon ion-record"></i>
<span translate>CURRENCY.VIEW.MASS</span> <span translate>CURRENCY.VIEW.MASS</span>
<span class="badge badge-stable">{{M | formatInteger}} {{unit | abbreviate}}<sub>{{udUnit | abbreviate}}</sub></span> <span class="badge badge-stable" ng-if="!formData.useRelative">{{M | formatInteger}} {{currency | abbreviate}}</span>
<span class="badge badge-stable" ng-if="formData.useRelative">{{M | formatNumeral: '0,0.00'}} {{'COMMON.UD'|translate}}<sub>{{currency | abbreviate}}</sub></span>
</a> </a>
<a class="item item-icon-left" href="#"> <a class="item item-icon-left" href="#">
<i class="icon ion-pie-graph"></i> <i class="icon ion-pie-graph"></i>
{{'CURRENCY.VIEW.SHARE'|translate}} {{'CURRENCY.VIEW.SHARE'|translate}}
<span class="badge badge-energized">{{MoverN | formatInteger}} {{unit | abbreviate}}<sub>{{udUnit | abbreviate}}</span> <span class="badge badge-energized" ng-if="!formData.useRelative">{{MoverN | formatInteger}} {{currency | abbreviate}}</span>
<span class="badge badge-energized" ng-if="formData.useRelative">{{MoverN | formatNumeral: '0,0.00'}} {{'COMMON.UD'|translate}}<sub>{{currency | abbreviate}}</sub></span>
</a> </a>
<a class="item item-icon-left" ui-sref="app.currency_ud"> <a class="item item-icon-left" ui-sref="app.currency_ud">
<i class="icon ion-load-c"></i> <i class="icon ion-load-c"></i>
<span translate>CURRENCY.VIEW.UD</span> <span translate>CURRENCY.VIEW.UD</span>
<span class="badge badge-royal">{{UD | formatInteger}} {{unit | abbreviate}}<sub>{{udUnit | abbreviate}}</sub>&nbsp;/&nbsp;{{dt | formatPeriod}}</span> <span class="badge badge-royal" ng-if="!formData.useRelative">{{currentUD | formatInteger}} {{currency | abbreviate}}&nbsp;/&nbsp;{{dt | formatPeriod}}</span>
<span class="badge badge-royal" ng-if="formData.useRelative">1 {{'COMMON.UD'|translate}}<sub>{{currency | abbreviate}}</sub>%&nbsp;/&nbsp;{{dt | formatPeriod}}</span>
</a> </a>
<a class="item item-icon-left" href="#"> <a class="item item-icon-left" href="#">
<i class="icon ion-arrow-graph-up-right"></i> <i class="icon ion-arrow-graph-up-right"></i>
<span translate>CURRENCY.VIEW.C_ACTUAL</span> <span translate>CURRENCY.VIEW.C_ACTUAL</span>
<span class="badge badge-stable">{{cactual | formatInteger}}%&nbsp;/&nbsp;{{dt | formatPeriod}}</span> <span class="badge badge-stable">{{cactual | formatNumeral: '0,0.00'}} %&nbsp;/&nbsp;{{dt | formatPeriod}}</span>
</a> </a>
<div class="item item-toggle dark"> <div class="item item-toggle dark">
...@@ -82,13 +86,13 @@ ...@@ -82,13 +86,13 @@
<ion-item class="item item-icon-left"> <ion-item class="item item-icon-left">
<i class="icon ion-arrow-graph-up-right"></i> <i class="icon ion-arrow-graph-up-right"></i>
<span translate>CURRENCY.VIEW.C_RULE</span> <span translate>CURRENCY.VIEW.C_RULE</span>
<span class="badge badge-stable">{{c*100 | formatInteger}}%&nbsp;/&nbsp;{{dt | formatPeriod}}</span> <span class="badge badge-stable">{{c*100 | formatNumeral: '0,0.00'}} %&nbsp;/&nbsp;{{dt | formatPeriod}}</span>
</ion-item> </ion-item>
<ion-item class="item item-icon-left"> <ion-item class="item item-icon-left">
<i class="icon ion-load-c"></i> <i class="icon ion-load-c"></i>
<span translate>CURRENCY.VIEW.UD_RULE</span> <span translate>CURRENCY.VIEW.UD_RULE</span>
<span class="item-note">MAX(UD<sub>t-1</sub>, c*M/N)</span> <span class="item-note">MAX({{'COMMON.UD'|translate}}<sub>t-1</sub>, c*M/N)</span>
</ion-item> </ion-item>
<ion-item class="item-icon-left"> <ion-item class="item-icon-left">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment