"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 {
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)
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
}
class AdminDashboard extends React.Component {
constructor(state) {
super(state);
- this.state = {'portfolios': null};
+ this.state = {'portfolios': null, 'globalPerformance': null};
}
load = () => {
return;
}
- this.setState({'portfolios': data});
+ this.setState({
+ 'portfolios': data.portfolios,
+ 'globalPerformance': {
+ 'totalBtcValue': data.totalBtcValue,
+ 'totalBtcVariation': data.totalBtcVariation
+ }
+ });
}.bind(this));
}
if (this.state.portfolios === null) {
return <div></div>;
}
+
+ var globalPerformance = <div className="row" key="global">
+ <div className="col-6"><span>Total:</span></div>
+ <div className="col-6 text-center">
+ <PFBalanceMinimal variationP={this.state.globalPerformance.totalBtcVariation} balance={this.state.globalPerformance.totalBtcValue} isPercent={false}/>
+ </div>
+ </div>;
var portfolios = Object.keys(this.state.portfolios).map(function(email) {
return <div className="row" key={email}>
<div className="col-6"><span>{email}:</span></div>
<div className="col-6 text-center">
- <PFBalanceMinimal variationP={this.state.portfolios[email].performance.variationP} balance={this.state.portfolios[email].value} periodStart={this.state.portfolios[email].periodStart}/>
+ <PFBalanceMinimal variationP={this.state.portfolios[email].performance.variationP} balance={this.state.portfolios[email].value} isPercent={true}/>
</div>
</div>;
}.bind(this));
+ portfolios.push(<hr key="hr"/>, globalPerformance);
+
return <Panel component={<div>{portfolios}</div>} title="Portfolios Overview"/>;
}
}
}
- var formatVariation = (variation) => {
+ var formatVariation = (variation, isPercent) => {
var variationAbs = Math.abs(variation);
+ var suffix = '';
+ if (isPercent === true) {
+ suffix = '%';
+ }
+
if (variation === 0.0) {
- return <span>{variationAbs}%</span>;
+ return <span>{variationAbs}{suffix}</span>;
} else if (variation > 0) {
- return <span className="performance-up">+{variationAbs}%</span>;
+ return <span className="performance-up">+{variationAbs}{suffix}</span>;
}
- return <span className="performance-down">-{variationAbs}%</span>;
+ return <span className="performance-down">-{variationAbs}{suffix}</span>;
};
<div className="d-inline col-2">{this.props.quantity}</div>
<div className="d-inline col-2">{this.props.BTCValue}</div>
<div className="d-inline col-2">{this.props.weight}%</div>
- <div className="d-inline col-2">{formatVariation(this.props.positionPerformanceP)}</div>
+ <div className="d-inline col-2">{formatVariation(this.props.positionPerformanceP, true)}</div>
</div>
</React.Fragment>;
}
<em>since {date}</em>
</div>
<div className="col-4 variation text-center">
- <strong>{formatVariation(this.props.variationP)}</strong>
+ <strong>{formatVariation(this.props.variationP, true)}</strong>
</div>
</div>
</div>
return <React.Fragment>
<div className="balance">
<div className="col-12">
- <CurrencyLogo currency="BTC" /> <span><strong>{this.props.balance}</strong> <strong>{formatVariation(this.props.variationP)}</strong></span>
+ <CurrencyLogo currency="BTC" /> <span><strong>{this.props.balance}</strong> <strong>{formatVariation(this.props.variationP, this.props.isPercent)}</strong></span>
</div>
</div>
</React.Fragment>;