X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=cmd%2Fweb%2Fjs%2Fpoloniex.jsx;h=5c374c3b3efbf2675cb642d208a3ef8ad9527973;hb=d5b8f0ffbbde5fb8d41c3abb4b0969b962746b52;hp=482dbb6c9b437ca2f0bf2af7e93ed2378810ff55;hpb=6b3f0ad04550060fd25b87b68c3f9bc1602f3226;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/cmd/web/js/poloniex.jsx b/cmd/web/js/poloniex.jsx index 482dbb6..5c374c3 100644 --- a/cmd/web/js/poloniex.jsx +++ b/cmd/web/js/poloniex.jsx @@ -1,62 +1,48 @@ import Api from './api.js'; import React from 'react'; +import {PFBalance, Assets} from './balance.js'; +import Panel from './panel.js'; class PoloniexController extends React.Component { constructor(props) { super(props); - this.state = {'apiKey': '', 'apiSecret': '', 'apiRequested': false, 'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}; + this.state = {'flag': 'loading', 'periodStart': null, 'variationP': null, 'balance': null, 'balances': null}; } - handleCredentialsChange = (key, secret) => { - this.setState({'apiKey': key, 'apiSecret': secret}); - } - - handleCredentialsSubmit = () => { - if (!this.state.apiKey || !this.state.apiSecret) { - return; - } - Api.Call('UPDATE_MARKET', {'key': this.state.apiKey, 'secret': this.state.apiSecret, 'name': 'poloniex'}, 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', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null}); + } else if (err.code === 'ip_restricted_api_key') { + this.setState({'flag': 'ipRestricted', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null}); + } else if (err.code === 'market_credentials_not_configured') { + this.setState({'flag': 'emptyCredentials'}); + } return; } - this.setState({'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); - this.loadBalance(); + this.loadPortfolio(); }.bind(this)); } - loadBalance = () => { - Api.Call('MARKET_BALANCE', {'name': 'poloniex', 'currency': 'BTC'}, function(err, status, data) { + loadPortfolio = () => { + Api.Call('MARKET_GET_PORTFOLIO', {'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}); + if (err.code === 'not_found') { + this.setState({'flag': 'noReport', 'variationP': null, 'balance': null, 'balances': null, 'periodStart': null}); } return; } - this.setState({'flag': 'ok', 'valueCurrency': data.valueCurrency, 'balanceValue': data.value, 'balance': data.balance}); + this.setState({'flag': 'ok', 'variationP': data.performance.variationP, 'balance': data.value, 'balances': data.balances, 'periodStart': data.periodStart}); }.bind(this)); } componentDidMount = () => { - Api.Call('MARKET', {'name': 'poloniex'}, function(err, status, data) { - this.setState({'apiRequested': true}); - if (err) { - console.error(err, data); - return; - } - - var flag = this.state.flag; - if (!data.key || !data.secret) { - flag = 'emptyCredentials'; - } else { - this.loadBalance(); - } - - this.setState({'apiKey': data.key, 'apiSecret': data.secret, 'flag': flag}); - }.bind(this)); + this.testCredentials(); } render = () => { @@ -65,143 +51,65 @@ class PoloniexController extends React.Component { case 'loading': displayText = 'Loading data from poloniex...'; break; - case 'invalidCredentials': - displayText = 'Invalid poloniex credentials'; + case 'noReport': + displayText = 'Your account is setup ! Reporting will start next Monday !'; break; + case 'invalidCredentials': + case 'ipRestricted': case 'emptyCredentials': - displayText = 'Please provide poloniex credentials'; + displayText =
Please provide poloniex credentials in Account page.
; break; default: displayText = null; } - if (this.state.apiRequested === false) { - return
; - } 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}; - } render = () => { - var dashboard = null; - - if (this.props.balanceValue !== null) { - - var balance = Object.keys(this.props.balance).map(function(currency) { - return
- {this.props.balance[currency]} -
; - }.bind(this)); + var balancePanel = null; + var assetsPanel = null; + var messagePanel = null; - dashboard = + if (this.props.variationP !== null) { + balancePanel =
-
- {balance} -
-
-
- Balance ({this.props.balanceCurrency}): {this.props.balanceValue} -
+
+
; -} else { - dashboard = + + assetsPanel = + ; + + } else { + messagePanel =
{this.props.displayText}
; -} + } return ( -
-
-
-
Portfolio
-
-
- {dashboard} -
-
+ + + + + ); } } -class PoloniexCredentialsForm extends React.Component { - constructor(props) { - super(props); - this.state = {'hideMsg': true, 'msg': '', 'editMode': false, 'msgOk': false}; - } - - handleSubmit = (e) => { - this.props.onCredentialsSubmit(); - this.setState({'editMode': false}); - e.preventDefault(); - } - - handleApiKeyChange = (event) => { - this.props.onCredentialsChange(event.target.value, this.props.apiSecret); - } - - handleApiSecretChange = (event) => { - this.props.onCredentialsChange(this.props.apiKey, event.target.value); - } - - onEditClick = () => { - this.setState({'editMode': true}); - } - - render = () => { - var submitType = this.state.editMode === true ? 'submit' : 'hidden'; - var buttonDisplay = this.state.editMode === true ? 'none' : 'inline'; - var secretDisplayed = this.state.editMode === true ? this.props.apiSecret : 'XXXXXXX'; - var keyDisplayed = this.state.editMode === true ? this.props.apiKey : 'XXXXXXX'; - - return ( -
-
- Poloniex credentials -
-
- - - - -
-
-
- ); - } -} - export default PoloniexController;