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 (