1 import Api from './api.js';
2 import React from 'react';
3 import {PFBalance, Assets} from './balance.js';
5 class PoloniexController extends React.Component {
8 this.state = {'flag': 'loading', 'periodStart': null, 'variationP': null, 'balance': null, 'balances': null};
11 testCredentials = () => {
12 Api.Call('MARKET_TEST_CREDENTIALS', {'name': 'poloniex'}, function(err, status, data) {
14 console.error(err, data);
15 if (err.code === 'invalid_market_credentials') {
16 this.setState({'flag': 'invalidCredentials', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null});
17 } else if (err.code === 'ip_restricted_api_key') {
18 this.setState({'flag': 'ipRestricted', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null});
19 } else if (err.code === 'market_credentials_not_configured') {
20 this.setState({'flag': 'emptyCredentials'});
29 loadPortfolio = () => {
30 Api.Call('MARKET_GET_PORTFOLIO', {'name': 'poloniex'}, function(err, status, data) {
32 console.error(err, data);
33 if (err.code === 'not_found') {
34 this.setState({'flag': 'noReport', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null});
39 this.setState({'flag': 'ok', 'variationP': data.performance.variationP, 'balance': data.value, 'balances': data.balances, 'periodStart': data.periodStart});
43 componentDidMount = () => {
44 this.testCredentials();
48 var displayText = null;
49 switch (this.state.flag) {
51 displayText = 'Loading data from poloniex...';
54 displayText = 'Your account is setup ! Reporting will start next Monday !';
56 case 'invalidCredentials':
58 case 'emptyCredentials':
59 displayText = <div>Please provide poloniex credentials in <a href="/account"><u>Account</u></a> page.</div>;
66 <PoloniexBalance balanceCurrency={this.state.valueCurrency}
67 variationP={this.state.variationP}
68 periodStart={this.state.periodStart}
69 balance={this.state.balance}
70 balances={this.state.balances}
71 displayText={displayText}/>
77 class Panel extends React.Component {
79 if (this.props.component === null) {
85 <div className="box col-12">
87 <div className="col-4">{this.props.title}</div>
90 {this.props.component}
96 class PoloniexBalance extends React.Component {
99 var balancePanel = null;
100 var assetsPanel = null;
101 var messagePanel = null;
103 if (this.props.variationP !== null) {
105 <div className="row">
106 <div className="col-12 offset-md-1 col-md-10 align-self-center h-100 balances">
107 <PFBalance variationP={this.props.variationP} balance={this.props.balance} periodStart={this.props.periodStart}/>
112 <Assets balances={this.props.balances} />;
116 <div className="row">
117 <div className="col-12 text-center">
118 <span>{this.props.displayText}</span>
125 <Panel title="Balance" component={balancePanel}/>
126 <Panel title="Assets" component={assetsPanel}/>
127 <Panel title="Balance" component={messagePanel}/>
133 export default PoloniexController;