X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=cmd%2Fweb%2Fjs%2Fpoloniex.jsx;h=482dbb6c9b437ca2f0bf2af7e93ed2378810ff55;hb=6b3f0ad04550060fd25b87b68c3f9bc1602f3226;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..482dbb6 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,8 +24,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 +38,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 +57,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 +74,9 @@ module.exports.PoloniexController = React.createClass({
default:
displayText = null;
}
+ if (this.state.apiRequested === false) {
+ return
;
+ }
return (
);
}
-});
+}
+
+class CurrencyLogo extends React.Component {
+ render = () => {
+ return ;
+ }
+}
+
+class PoloniexBalance extends React.Component {
+ constructor(props) {
+ super(props);
+ this.state = {'hideMsg': true, 'msg': '', 'msgOk': false};
+ }
-var PoloniexBalance = React.createClass({
- getInitialState: function() {
- return {'hideMsg': true, 'msg': '', 'msgOk': false};
- },
- render: function() {
+ 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 ({this.props.balanceCurrency}):
{this.props.balanceValue}
+
+
+ Balance ({this.props.balanceCurrency}): {this.props.balanceValue}
-
- );
- } else {
- dashboard = (
-
-
+
;
+} else {
+ dashboard =
+
+
{this.props.displayText}
-
-
- );
- }
+
;
+}
return (
-
-
-
-
Portfolio
+
+
+
{dashboard}
@@ -133,53 +151,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;