aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/js/admin.jsx
blob: 19eb3ef02727f47a4a3a345376edcdf8294a8686 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import Api from './api.js';
import React from 'react';
import {PFBalanceMinimal} from './balance.js';
import Panel from './panel.js';

class AdminDashboard extends React.Component {
  constructor(state) {
    super(state);
    this.state = {'portfolios': null, 'globalPerformance': null};
  }

  load = () => {
    Api.Call('ADMIN_PORTFOLIOS', {}, function(err, status, data) {
      if (err) {
        console.error(err, data);
        return;
      }

      this.setState({
        'portfolios': data.portfolios,
        'globalPerformance': {
          'totalBtcValue':     data.totalBtcValue,
          'totalBtcVariation': data.totalBtcVariation
        }
      });
    }.bind(this));
  }

  componentDidMount = () => {
    this.load();
  }

  render = () => {
    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} isPercent={true}/>
               </div>
             </div>;
    }.bind(this));

    portfolios.push(<hr key="hr"/>, globalPerformance);

    return <Panel component={<div>{portfolios}</div>} title="Portfolios Overview"/>;
  }

}

export default AdminDashboard;