X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=cmd%2Fweb%2Fjs%2Fpoloniex.jsx;h=813a506a60d9af3e7a03426b4a1cd3577c32c08f;hb=908ee2dd22c85d5d850f62b1a9d0066b43b80a69;hp=8b577b4a256e2e4c365fe1ebfcebc8c423dcdbcb;hpb=2f91f20a8645339385ada602684f4957f20f4da4;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/cmd/web/js/poloniex.jsx b/cmd/web/js/poloniex.jsx index 8b577b4..813a506 100644 --- a/cmd/web/js/poloniex.jsx +++ b/cmd/web/js/poloniex.jsx @@ -1,14 +1,17 @@ -var Api = require('./api.js').Api; -var classNames = require('classnames'); - -module.exports.PoloniexController = React.createClass({ - getInitialState: function() { - return {'apiKey': '', 'apiSecret': '', 'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}; - }, - handleCredentialsChange: function(key, secret) { +import Api from './api.js'; +import React from 'react'; + +class PoloniexController extends React.Component { + constructor(props) { + super(props); + this.state = {'apiKey': '', 'apiSecret': '', 'apiRequested': false, 'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}; + } + + handleCredentialsChange = (key, secret) => { this.setState({'apiKey': key, 'apiSecret': secret}); - }, - handleCredentialsSubmit: function() { + } + + handleCredentialsSubmit = () => { if (!this.state.apiKey || !this.state.apiSecret) { return; } @@ -21,22 +24,27 @@ module.exports.PoloniexController = React.createClass({ this.setState({'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); this.loadBalance(); }.bind(this)); - }, - loadBalance: function() { + } + + 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: function() { + } + + componentDidMount = () => { Api.Call('MARKET', {'name': 'poloniex'}, function(err, status, data) { + this.setState({'apiRequested': true}); if (err) { console.error(err, data); return; @@ -51,8 +59,9 @@ module.exports.PoloniexController = React.createClass({ this.setState({'apiKey': data.key, 'apiSecret': data.secret, 'flag': flag}); }.bind(this)); - }, - render: function() { + } + + render = () => { var displayText = null; switch (this.state.flag) { case 'loading': @@ -61,12 +70,18 @@ module.exports.PoloniexController = React.createClass({ case 'invalidCredentials': displayText = 'Invalid poloniex credentials'; break; + case 'ipRestricted': + displayText = 'Your API key is IP restricted. Please whitelist us.'; + break; case 'emptyCredentials': displayText = 'Please provide poloniex credentials'; break; default: displayText = null; } + if (this.state.apiRequested === false) { + return
; + } return (
); } -}); +} + +class CurrencyLogo extends React.Component { + render = () => { + return {this.props.currency}; + } +} -var PoloniexBalance = React.createClass({ - getInitialState: function() { - return {'hideMsg': true, 'msg': '', 'msgOk': false}; - }, - render: function() { +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]}
; + return
+ {this.props.balance[currency]} +
; }.bind(this)); - dashboard = ( -
-
-
+ dashboard = +
+
{balance} -
-
-
- Balance ({this.props.balanceCurrency}): {this.props.balanceValue} +
+
+ Balance ({this.props.balanceCurrency}): {this.props.balanceValue}
-
- ); - } else { - dashboard = ( -
-
+
; +} else { + dashboard = +
+
{this.props.displayText}
-
- - ); - } +
; +} return ( -
-
-
-
Portfolio
+
+
+
+
Portfolio

{dashboard} @@ -133,53 +156,57 @@ var PoloniexBalance = React.createClass({
); } -}); +} -module.exports.PoloniexBalance = PoloniexBalance; +class PoloniexCredentialsForm extends React.Component { + constructor(props) { + super(props); + this.state = {'hideMsg': true, 'msg': '', 'editMode': false, 'msgOk': false}; + } -var PoloniexCredentialsForm = React.createClass({ - getInitialState: function() { - return {'hideMsg': true, 'msg': '', 'editMode': false, 'msgOk': false}; - }, - handleSubmit: function(e) { + handleSubmit = (e) => { this.props.onCredentialsSubmit(); this.setState({'editMode': false}); e.preventDefault(); - }, - handleApiKeyChange: function(event) { + } + + handleApiKeyChange = (event) => { this.props.onCredentialsChange(event.target.value, this.props.apiSecret); - }, - handleApiSecretChange: function(event) { + } + + handleApiSecretChange = (event) => { this.props.onCredentialsChange(this.props.apiKey, event.target.value); - }, - onEditClick: function() { + } + + onEditClick = () => { this.setState({'editMode': true}); - }, - render: function() { - 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'; + } + + 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 +
+
+ Poloniex credentials
-
-
); } -}); +} -module.exports.PoloniexCredentialsForm = PoloniexCredentialsForm; +export default PoloniexController;