X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=cmd%2Fweb%2Fjs%2Fpoloniex.jsx;h=6019ef8cb59402ac143e1fdc4cf9d1668360b7fa;hb=24e4797900b3d2edf642fdb547bc22357a5b39ad;hp=edac368e84d07f02d2060d838481d7853cab04a3;hpb=78e3e81ddf01f41102f3f4e32c5a3955cf5fb04f;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/cmd/web/js/poloniex.jsx b/cmd/web/js/poloniex.jsx index edac368..6019ef8 100644 --- a/cmd/web/js/poloniex.jsx +++ b/cmd/web/js/poloniex.jsx @@ -1,30 +1,45 @@ import Api from './api.js'; import React from 'react'; +import {PFBalance, Assets} from './balance.js'; class PoloniexController extends React.Component { constructor(props) { super(props); - this.state = {'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}; + this.state = {'flag': 'loading', 'periodStart': null, 'variationP': null, 'balance': null, 'balances': null}; } - loadBalance = () => { - Api.Call('MARKET_BALANCE', {'name': 'poloniex', 'currency': 'BTC'}, function(err, status, data) { + testCredentials = () => { + Api.Call('MARKET_TEST_CREDENTIALS', {'name': 'poloniex'}, 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}); + this.setState({'flag': 'invalidCredentials', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null}); } else if (err.code === 'ip_restricted_api_key') { - this.setState({'flag': 'ipRestricted', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); + this.setState({'flag': 'ipRestricted', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null}); } return; } - this.setState({'flag': 'ok', 'valueCurrency': data.valueCurrency, 'balanceValue': data.value, 'balance': data.balance}); + this.loadPortfolio(); + }.bind(this)); + } + + loadPortfolio = () => { + Api.Call('MARKET_GET_PORTFOLIO', {'name': 'poloniex'}, function(err, status, data) { + if (err) { + console.error(err, data); + if (err.code === 'not_found') { + this.setState({'flag': 'noReport', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null}); + } + return; + } + + this.setState({'flag': 'ok', 'variationP': data.performance.variationP, 'balance': data.value, 'balances': data.balances, 'periodStart': data.periodStart}); }.bind(this)); } componentDidMount = () => { - this.loadBalance(); + this.testCredentials(); } render = () => { @@ -33,10 +48,13 @@ class PoloniexController extends React.Component { case 'loading': displayText = 'Loading data from poloniex...'; break; + case 'noReport': + displayText = 'Your account is setup ! Reporting will start next Monday !'; + break; case 'invalidCredentials': case 'ipRestricted': case 'emptyCredentials': - displayText =
Please provide poloniex credentials in Account page.
; + displayText =
Please provide poloniex credentials in Account page.
; break; default: displayText = null; @@ -44,59 +62,55 @@ class PoloniexController extends React.Component { return (
); } } -class CurrencyLogo extends React.Component { +class Panel extends React.Component { render = () => { - return {this.props.currency}; + if (this.props.component === null) { + return
; + } + + return ( +
+
+
+
{this.props.title}
+
+
+ {this.props.component} +
+
); } } 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 balancePanel = null; + var assetsPanel = null; + var messagePanel = null; - var balance = Object.keys(this.props.balance).map(function(currency) { - return
-
- {this.props.balance[currency].amount} {currency} ({this.computeCurrencyRatio(currency)}%) -
-
; - }.bind(this)); - - dashboard = + if (this.props.variationP !== null) { + balancePanel =
-
- {balance} -
-
-
- Balance ({this.props.balanceCurrency}): {this.props.balanceValue} -
+
+
; + + assetsPanel = + ; + } else { - dashboard = + messagePanel =
{this.props.displayText} @@ -105,15 +119,11 @@ class PoloniexBalance extends React.Component { } return ( -
-
-
-
Portfolio
-
-
- {dashboard} -
-
+ + + + + ); } }