import Api from './api.js'; import React from 'react'; class PoloniexController extends React.Component { constructor(props) { super(props); this.state = {'apiRequested': false, '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', 'apiRequested': true, 'valueCurrency': null, 'balanceValue': null, 'balance': null}); } else if (err.code === 'ip_restricted_api_key') { this.setState({'flag': 'ipRestricted', 'apiRequested': true, 'valueCurrency': null, 'balanceValue': null, 'balance': null}); } return; } this.setState({'flag': 'ok', 'apiRequested': true, '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 =