From: jloup Date: Thu, 19 Jul 2018 16:00:20 +0000 (+0200) Subject: Display total balance/performance. X-Git-Tag: v0.0.24 X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=1fcb77583201f9979a839fcae2dd642edc25af96;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git Display total balance/performance. --- diff --git a/api/admin.go b/api/admin.go index 3b16d87..e4bfda5 100644 --- a/api/admin.go +++ b/api/admin.go @@ -4,13 +4,18 @@ import ( "fmt" "git.immae.eu/Cryptoportfolio/Front.git/db" + "github.com/shopspring/decimal" ) type GetAllPortfoliosQuery struct { In struct { Market string } - Out map[string]Portfolio + Out struct { + Portfolios map[string]Portfolio `json:"portfolios"` + TotalBTCValue decimal.Decimal `json:"totalBtcValue"` + TotalBTCVariation decimal.Decimal `json:"totalBtcVariation"` + } } func (q GetAllPortfoliosQuery) ValidateParams() *Error { @@ -27,7 +32,7 @@ func (q GetAllPortfoliosQuery) Run() (interface{}, *Error) { return nil, NewInternalError(err) } - q.Out = make(map[string]Portfolio) + q.Out.Portfolios = make(map[string]Portfolio) for _, marketConfig := range u { report, err := GetWeekPortfolio(marketConfig) @@ -39,8 +44,13 @@ func (q GetAllPortfoliosQuery) Run() (interface{}, *Error) { return nil, NewInternalError(err) } - q.Out[marketConfig.User.Email] = report.Round() + q.Out.Portfolios[marketConfig.User.Email] = report.Round() + q.Out.TotalBTCValue = q.Out.TotalBTCValue.Add(report.Performance.Value) + q.Out.TotalBTCVariation = q.Out.TotalBTCVariation.Add(report.Performance.Variation) } + q.Out.TotalBTCValue = q.Out.TotalBTCValue.Round(3) + q.Out.TotalBTCVariation = q.Out.TotalBTCVariation.Round(3) + return q.Out, nil } 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)}
;