From 1fcb77583201f9979a839fcae2dd642edc25af96 Mon Sep 17 00:00:00 2001 From: jloup Date: Thu, 19 Jul 2018 18:00:20 +0200 Subject: Display total balance/performance. --- cmd/web/js/admin.jsx | 21 ++++++++++++++++++--- cmd/web/js/balance.jsx | 19 ++++++++++++------- 2 files changed, 30 insertions(+), 10 deletions(-) (limited to 'cmd/web') diff --git a/cmd/web/js/admin.jsx b/cmd/web/js/admin.jsx index 81ce15d..19eb3ef 100644 --- a/cmd/web/js/admin.jsx +++ b/cmd/web/js/admin.jsx @@ -6,7 +6,7 @@ import Panel from './panel.js'; class AdminDashboard extends React.Component { constructor(state) { super(state); - this.state = {'portfolios': null}; + this.state = {'portfolios': null, 'globalPerformance': null}; } load = () => { @@ -16,7 +16,13 @@ class AdminDashboard extends React.Component { return; } - this.setState({'portfolios': data}); + this.setState({ + 'portfolios': data.portfolios, + 'globalPerformance': { + 'totalBtcValue': data.totalBtcValue, + 'totalBtcVariation': data.totalBtcVariation + } + }); }.bind(this)); } @@ -28,15 +34,24 @@ class AdminDashboard extends React.Component { if (this.state.portfolios === null) { return
; } + + var globalPerformance =
+
Total:
+
+ +
+
; var portfolios = Object.keys(this.state.portfolios).map(function(email) { return
{email}:
- +
; }.bind(this)); + portfolios.push(
, globalPerformance); + return {portfolios}} title="Portfolios Overview"/>; } diff --git a/cmd/web/js/balance.jsx b/cmd/web/js/balance.jsx index 1915511..429538d 100644 --- a/cmd/web/js/balance.jsx +++ b/cmd/web/js/balance.jsx @@ -11,14 +11,19 @@ class CurrencyLogo extends React.Component { } } - var formatVariation = (variation) => { + var formatVariation = (variation, isPercent) => { var variationAbs = Math.abs(variation); + var suffix = ''; + if (isPercent === true) { + suffix = '%'; + } + if (variation === 0.0) { - return {variationAbs}%; + return {variationAbs}{suffix}; } else if (variation > 0) { - return +{variationAbs}%; + return +{variationAbs}{suffix}; } - return -{variationAbs}%; + return -{variationAbs}{suffix}; }; @@ -46,7 +51,7 @@ class CurrencyRate extends React.Component {
{this.props.quantity}
{this.props.BTCValue}
{this.props.weight}%
-
{formatVariation(this.props.positionPerformanceP)}
+
{formatVariation(this.props.positionPerformanceP, true)}
; } @@ -87,7 +92,7 @@ class PFBalance extends React.Component { since {date}
- {formatVariation(this.props.variationP)} + {formatVariation(this.props.variationP, true)}
@@ -100,7 +105,7 @@ class PFBalanceMinimal extends React.Component { return
- {this.props.balance} {formatVariation(this.props.variationP)} + {this.props.balance} {formatVariation(this.props.variationP, this.props.isPercent)}
; -- cgit v1.2.3