X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=cmd%2Fweb%2Fjs%2Fpoloniex.jsx;h=a5fb9a74d49bb3ac45b933c088bb184c18038e75;hb=adf936f66a5c59e6cc2e7a1c644148e0f119e5c8;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..a5fb9a7 100644 --- a/cmd/web/js/poloniex.jsx +++ b/cmd/web/js/poloniex.jsx @@ -1,14 +1,18 @@ -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 classNames from 'classnames'; +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,8 +25,9 @@ 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); @@ -34,9 +39,11 @@ module.exports.PoloniexController = React.createClass({ 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 +58,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': @@ -67,6 +75,9 @@ module.exports.PoloniexController = React.createClass({ default: displayText = null; } + if (this.state.apiRequested === false) { + return
; + } return (