From 989fb5c7dbba174f54f3ae69df788d6685fff46b Mon Sep 17 00:00:00 2001
From: jloup <jeanloup.jamet@gmail.com>
Date: Sat, 24 Feb 2018 17:06:57 +0100
Subject: Upgrade ReactJS. EC6 import modules.

---
 cmd/web/js/poloniex.jsx | 154 ++++++++++++++++++++++++++----------------------
 1 file changed, 82 insertions(+), 72 deletions(-)

(limited to 'cmd/web/js/poloniex.jsx')

diff --git a/cmd/web/js/poloniex.jsx b/cmd/web/js/poloniex.jsx
index 8b577b4..96384fd 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': '', '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,8 +39,9 @@ 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) {
       if (err) {
         console.error(err, data);
@@ -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':
@@ -81,13 +88,15 @@ module.exports.PoloniexController = React.createClass({
       </div>
     );
   }
-});
+}
+
+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) {
@@ -96,36 +105,33 @@ var PoloniexBalance = React.createClass({
         return <div key={currency}><i className={classNames('cc', currency)}></i> {this.props.balance[currency]}</div>;
       }.bind(this));
 
-      dashboard = (
-        <div className='row'>
-          <div className='col-4 align-self-center h-100'>
+      dashboard =
+        <div className="row">
+          <div className="col-4 align-self-center h-100">
             <div>
               {balance}
             </div>
           </div>
-          <div className='offset-1 col-7 h-100 align-self-center'>
-            <div className='text-center'>
+          <div className="offset-1 col-7 h-100 align-self-center">
+            <div className="text-center">
               Balance ({this.props.balanceCurrency}): <span>{this.props.balanceValue} <i className={classNames('cc', this.props.balanceCurrency)}></i></span>
             </div>
           </div>
-        </div>
-      );
-    } else {
-      dashboard = (
-        <div className='row'>
-          <div className='col-12 text-center'>
+        </div>;
+} else {
+      dashboard =
+        <div className="row">
+          <div className="col-12 text-center">
            <span>{this.props.displayText}</span>
           </div>
-        </div>
-
-      );
-    }
+        </div>;
+}
 
     return (
-      <div className='row'>
-        <div className='box offset-2 col-8'>
-          <div className='row'>
-            <div className='col-4'>Portfolio</div>
+      <div className="row">
+        <div className="box offset-2 col-8">
+          <div className="row">
+            <div className="col-4">Portfolio</div>
           </div>
           <hr/>
           {dashboard}
@@ -133,53 +139,57 @@ var PoloniexBalance = React.createClass({
       </div>
     );
   }
-});
+}
 
-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 (
-        <div className='row api-credentials-form'>
-          <div className='offset-3 col-6 box'>
-            <span className='text-center'>Poloniex credentials</span>
+        <div className="row api-credentials-form">
+          <div className="offset-3 col-6 box">
+            <span className="text-center">Poloniex credentials</span>
             <hr/>
-            <form role='form' onSubmit={this.handleSubmit}>
-              <label className='w-100'>Key:
-                <input className='form-control' type='text' placeholder='key' value={keyDisplayed} onChange={this.handleApiKeyChange} disabled={!this.state.editMode}/>
+            <form role="form" onSubmit={this.handleSubmit}>
+              <label className="w-100">Key:
+                <input className="form-control" type="text" placeholder="key" value={keyDisplayed} onChange={this.handleApiKeyChange} disabled={!this.state.editMode}/>
               </label>
-              <label className='w-100'>Secret:
-                <input className='form-control' type='text' placeholder='secret' value={secretDisplayed} onChange={this.handleApiSecretChange} disabled={!this.state.editMode}/>
+              <label className="w-100">Secret:
+                <input className="form-control" type="text" placeholder="secret" value={secretDisplayed} onChange={this.handleApiSecretChange} disabled={!this.state.editMode}/>
               </label>
-              <input className='form-control submit' type={submitType} value='Save' />
-              <button className='form-control submit' style={{display: buttonDisplay}} onSubmit={null} onClick={this.onEditClick} type='button'>Show/Edit</button>
+              <input className="form-control submit" type={submitType} value="Save" />
+              <button className="form-control submit" style={{display: buttonDisplay}} onSubmit={null} onClick={this.onEditClick} type="button">Show/Edit</button>
             </form>
           </div>
         </div>
        );
   }
-});
+}
 
-module.exports.PoloniexCredentialsForm = PoloniexCredentialsForm;
+export default PoloniexController;
-- 
cgit v1.2.3

