]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blobdiff - cmd/web/js/poloniex.jsx
Use <img> for currency display.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / cmd / web / js / poloniex.jsx
index 96384fd35ac501ee62a918a2620c90d5af9d3564..482dbb6c9b437ca2f0bf2af7e93ed2378810ff55 100644 (file)
@@ -1,11 +1,10 @@
 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};
+    this.state = {'apiKey': '', 'apiSecret': '', 'apiRequested': false, 'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null};
   }
 
   handleCredentialsChange = (key, secret) => {
@@ -43,6 +42,7 @@ class PoloniexController extends React.Component {
 
   componentDidMount = () => {
     Api.Call('MARKET', {'name': 'poloniex'}, function(err, status, data) {
+      this.setState({'apiRequested': true});
       if (err) {
         console.error(err, data);
         return;
@@ -74,6 +74,9 @@ class PoloniexController extends React.Component {
       default:
         displayText = null;
     }
+    if (this.state.apiRequested === false) {
+      return <div></div>;
+    }
     return (
       <div>
         <PoloniexBalance  balanceCurrency={this.state.valueCurrency}
@@ -90,6 +93,15 @@ class PoloniexController extends React.Component {
   }
 }
 
+class CurrencyLogo extends React.Component {
+  render = () => {
+    return <img className="currency-logo"
+                src={'/public/icons/black/' + this.props.currency.toLowerCase() + '.svg' }
+                title={this.props.currency}
+                alt={this.props.currency} />;
+  }
+}
+
 class PoloniexBalance extends React.Component {
   constructor(props) {
     super(props);
@@ -102,19 +114,19 @@ class PoloniexBalance extends React.Component {
     if (this.props.balanceValue !== null) {
 
       var balance = Object.keys(this.props.balance).map(function(currency) {
-        return <div key={currency}><i className={classNames('cc', currency)}></i> {this.props.balance[currency]}</div>;
+        return <div key={currency}>
+                 <CurrencyLogo currency={currency} /> {this.props.balance[currency]}
+               </div>;
       }.bind(this));
 
       dashboard =
         <div className="row">
-          <div className="col-4 align-self-center h-100">
-            <div>
+          <div className="col-4 align-self-center h-100 balances">
               {balance}
-            </div>
           </div>
           <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>
+              Balance ({this.props.balanceCurrency}): <span>{this.props.balanceValue}</span><CurrencyLogo currency={this.props.balanceCurrency} />
             </div>
           </div>
         </div>;
@@ -129,7 +141,7 @@ class PoloniexBalance extends React.Component {
 
     return (
       <div className="row">
-        <div className="box offset-2 col-8">
+        <div className="box offset-2 col-8 portfolio">
           <div className="row">
             <div className="col-4">Portfolio</div>
           </div>
@@ -173,7 +185,7 @@ class PoloniexCredentialsForm extends React.Component {
 
     return (
         <div className="row api-credentials-form">
-          <div className="offset-3 col-6 box">
+          <div className="offset-2 col-8 box">
             <span className="text-center">Poloniex credentials</span>
             <hr/>
             <form role="form" onSubmit={this.handleSubmit}>