]>
Commit | Line | Data |
---|---|---|
2e4885d9 | 1 | import Api from './api.js'; |
2 | import React from 'react'; | |
3 | import {PFBalanceMinimal} from './balance.js'; | |
4 | import Panel from './panel.js'; | |
5 | ||
6 | class AdminDashboard extends React.Component { | |
7 | constructor(state) { | |
8 | super(state); | |
1fcb7758 | 9 | this.state = {'portfolios': null, 'globalPerformance': null}; |
2e4885d9 | 10 | } |
11 | ||
12 | load = () => { | |
13 | Api.Call('ADMIN_PORTFOLIOS', {}, function(err, status, data) { | |
14 | if (err) { | |
15 | console.error(err, data); | |
16 | return; | |
17 | } | |
18 | ||
1fcb7758 | 19 | this.setState({ |
20 | 'portfolios': data.portfolios, | |
21 | 'globalPerformance': { | |
22 | 'totalBtcValue': data.totalBtcValue, | |
23 | 'totalBtcVariation': data.totalBtcVariation | |
24 | } | |
25 | }); | |
2e4885d9 | 26 | }.bind(this)); |
27 | } | |
28 | ||
29 | componentDidMount = () => { | |
30 | this.load(); | |
31 | } | |
32 | ||
33 | render = () => { | |
34 | if (this.state.portfolios === null) { | |
35 | return <div></div>; | |
36 | } | |
1fcb7758 | 37 | |
38 | var globalPerformance = <div className="row" key="global"> | |
39 | <div className="col-6"><span>Total:</span></div> | |
40 | <div className="col-6 text-center"> | |
41 | <PFBalanceMinimal variationP={this.state.globalPerformance.totalBtcVariation} balance={this.state.globalPerformance.totalBtcValue} isPercent={false}/> | |
42 | </div> | |
43 | </div>; | |
2e4885d9 | 44 | var portfolios = Object.keys(this.state.portfolios).map(function(email) { |
45 | return <div className="row" key={email}> | |
46 | <div className="col-6"><span>{email}:</span></div> | |
47 | <div className="col-6 text-center"> | |
1fcb7758 | 48 | <PFBalanceMinimal variationP={this.state.portfolios[email].performance.variationP} balance={this.state.portfolios[email].value} isPercent={true}/> |
2e4885d9 | 49 | </div> |
50 | </div>; | |
51 | }.bind(this)); | |
52 | ||
1fcb7758 | 53 | portfolios.push(<hr key="hr"/>, globalPerformance); |
54 | ||
2e4885d9 | 55 | return <Panel component={<div>{portfolios}</div>} title="Portfolios Overview"/>; |
56 | } | |
57 | ||
58 | } | |
59 | ||
60 | export default AdminDashboard; |