1 import Api from './api.js';
2 import React from 'react';
3 import {PFBalance, Assets} from './balance.js';
4 import Panel from './panel.js';
6 class PoloniexController extends React.Component {
9 this.state = {'flag': 'loading', 'periodStart': null, 'variationP': null, 'balance': null, 'balances': null};
12 testCredentials = () => {
13 Api.Call('MARKET_TEST_CREDENTIALS', {'name': 'poloniex'}, function(err, status, data) {
15 console.error(err, data);
16 if (err.code === 'invalid_market_credentials') {
17 this.setState({'flag': 'invalidCredentials', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null});
18 } else if (err.code === 'ip_restricted_api_key') {
19 this.setState({'flag': 'ipRestricted', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null});
20 } else if (err.code === 'market_credentials_not_configured') {
21 this.setState({'flag': 'emptyCredentials'});
30 loadPortfolio = () => {
31 Api.Call('MARKET_GET_PORTFOLIO', {'name': 'poloniex'}, function(err, status, data) {
33 console.error(err, data);
34 if (err.code === 'not_found') {
35 this.setState({'flag': 'noReport', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null});
40 this.setState({'flag': 'ok', 'variationP': data.performance.variationP, 'balance': data.value, 'balances': data.balances, 'periodStart': data.periodStart});
44 componentDidMount = () => {
45 this.testCredentials();
49 var displayText = null;
50 switch (this.state.flag) {
52 displayText = 'Loading data from poloniex...';
55 displayText = 'Your account is setup ! Reporting will start next Monday !';
57 case 'invalidCredentials':
59 case 'emptyCredentials':
60 displayText = <div>Please provide poloniex credentials in <a href="/account"><u>Account</u></a> page.</div>;
67 <PoloniexBalance balanceCurrency={this.state.valueCurrency}
68 variationP={this.state.variationP}
69 periodStart={this.state.periodStart}
70 balance={this.state.balance}
71 balances={this.state.balances}
72 displayText={displayText}/>
78 class PoloniexBalance extends React.Component {
81 var balancePanel = null;
82 var assetsPanel = null;
83 var messagePanel = null;
85 if (this.props.variationP !== null) {
88 <div className="col-12 offset-md-1 col-md-10 align-self-center h-100 balances">
89 <PFBalance variationP={this.props.variationP} balance={this.props.balance} periodStart={this.props.periodStart}/>
94 <Assets balances={this.props.balances} />;
99 <div className="col-12 text-center">
100 <span>{this.props.displayText}</span>
107 <Panel title="Balance" component={balancePanel}/>
108 <Panel title="Assets" component={assetsPanel}/>
109 <Panel title="Balance" component={messagePanel}/>
115 export default PoloniexController;