import Api from './api.js'; import React from 'react'; class PoloniexController extends React.Component { constructor(props) { super(props); this.state = {'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}; } loadBalance = () => { Api.Call('MARKET_BALANCE', {'name': 'poloniex', 'currency': 'BTC'}, function(err, status, data) { if (err) { console.error(err, data); if (err.code === 'invalid_market_credentials') { this.setState({'flag': 'invalidCredentials', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); } else if (err.code === 'ip_restricted_api_key') { this.setState({'flag': 'ipRestricted', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); } return; } this.setState({'flag': 'ok', 'valueCurrency': data.valueCurrency, 'balanceValue': data.value, 'balance': data.balance}); }.bind(this)); } componentDidMount = () => { this.loadBalance(); } render = () => { var displayText = null; switch (this.state.flag) { case 'loading': displayText = 'Loading data from poloniex...'; break; case 'invalidCredentials': case 'ipRestricted': case 'emptyCredentials': displayText =
Please provide poloniex credentials in Account page.
; break; default: displayText = null; } return (
); } } class CurrencyLogo extends React.Component { render = () => { return {this.props.currency}; } } class PoloniexBalance extends React.Component { constructor(props) { super(props); this.state = {'hideMsg': true, 'msg': '', 'msgOk': false}; } computeCurrencyRatio = (currency) => { return (parseFloat(this.props.balance[currency].btcValue) / parseFloat(this.props.balanceValue) * 100.0).toFixed(1); } render = () => { var dashboard = null; if (this.props.balanceValue !== null) { var balance = Object.keys(this.props.balance).map(function(currency) { return
{this.props.balance[currency].amount} {currency} ({this.computeCurrencyRatio(currency)}%)
; }.bind(this)); dashboard =
{balance}
Balance ({this.props.balanceCurrency}): {this.props.balanceValue}
; } else { dashboard =
{this.props.displayText}
; } return (
Portfolio

{dashboard}
); } } export default PoloniexController;