1 import Api from './api.js';
2 import React from 'react';
4 class PoloniexController extends React.Component {
7 this.state = {'apiRequested': false, 'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null};
11 Api.Call('MARKET_BALANCE', {'name': 'poloniex', 'currency': 'BTC'}, function(err, status, data) {
13 console.error(err, data);
14 if (err.code === 'invalid_market_credentials') {
15 this.setState({'flag': 'invalidCredentials', 'apiRequested': true, 'valueCurrency': null, 'balanceValue': null, 'balance': null});
16 } else if (err.code === 'ip_restricted_api_key') {
17 this.setState({'flag': 'ipRestricted', 'apiRequested': true, 'valueCurrency': null, 'balanceValue': null, 'balance': null});
22 this.setState({'flag': 'ok', 'apiRequested': true, 'valueCurrency': data.valueCurrency, 'balanceValue': data.value, 'balance': data.balance});
26 componentDidMount = () => {
31 var displayText = null;
32 switch (this.state.flag) {
34 displayText = 'Loading data from poloniex...';
36 case 'invalidCredentials':
38 case 'emptyCredentials':
39 displayText = <div>Please provide poloniex credentials in <a href="/account">Account</a> page.</div>;
44 if (this.state.apiRequested === false) {
49 <PoloniexBalance balanceCurrency={this.state.valueCurrency}
50 balanceValue={this.state.balanceValue}
51 balance={this.state.balance}
52 displayText={displayText}/>
58 class CurrencyLogo extends React.Component {
60 return <img className="currency-logo"
61 src={'/public/icons/black/' + this.props.currency.toLowerCase() + '.svg' }
62 title={this.props.currency}
63 alt={this.props.currency} />;
67 class PoloniexBalance extends React.Component {
70 this.state = {'hideMsg': true, 'msg': '', 'msgOk': false};
73 computeCurrencyRatio = (currency) => {
74 return (parseFloat(this.props.balance[currency].btcValue) / parseFloat(this.props.balanceValue) * 100.0).toFixed(1);
80 if (this.props.balanceValue !== null) {
82 var balance = Object.keys(this.props.balance).map(function(currency) {
83 return <div key={currency}>
85 <CurrencyLogo currency={currency} /> {this.props.balance[currency].amount} {currency} ({this.computeCurrencyRatio(currency)}%)
92 <div className="col-6 align-self-center h-100 balances">
95 <div className="offset-1 col-5 h-100 align-self-center">
96 <div className="text-center">
97 Balance ({this.props.balanceCurrency}): <span>{this.props.balanceValue}</span><CurrencyLogo currency={this.props.balanceCurrency} />
103 <div className="row">
104 <div className="col-12 text-center">
105 <span>{this.props.displayText}</span>
111 <div className="row">
112 <div className="box offset-2 col-8 portfolio">
113 <div className="row">
114 <div className="col-4">Portfolio</div>
124 export default PoloniexController;