]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git/blobdiff - cmd/web/js/poloniex.jsx
Display short positions.
[perso/Immae/Projets/Cryptomonnaies/Cryptoportfolio/Front.git] / cmd / web / js / poloniex.jsx
index c0b68c706671842dcfd0c94a6401d0c8dcb3b104..db6b1c43da71f123ec830dc8d6a8f89bffbe8146 100644 (file)
@@ -1,5 +1,4 @@
 import Api from './api.js';
-import classNames from 'classnames';
 import React from 'react';
 
 class PoloniexController extends React.Component {
@@ -33,6 +32,8 @@ class PoloniexController extends React.Component {
         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;
       }
@@ -69,6 +70,9 @@ class PoloniexController extends React.Component {
       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;
@@ -94,31 +98,46 @@ 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);
     this.state = {'hideMsg': true, 'msg': '', 'msgOk': false};
   }
 
+  computeCurrencyRatio = (currency) => {
+    return (parseFloat(this.props.balance[currency].btcValue) / parseFloat(this.props.balanceValue) * 100.0).toFixed(1);
+  }
+
   render = () => {
     var dashboard = null;
 
     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}>
+                 <div>
+                 <CurrencyLogo currency={currency} /> {this.props.balance[currency].amount} {currency} ({this.computeCurrencyRatio(currency)}%)
+                 </div>
+               </div>;
       }.bind(this));
 
       dashboard =
         <div className="row">
-          <div className="col-4 align-self-center h-100">
-            <div>
+          <div className="col-6 align-self-center h-100 balances">
               {balance}
-            </div>
           </div>
-          <div className="offset-1 col-7 h-100 align-self-center">
+          <div className="offset-1 col-5 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>;
@@ -133,7 +152,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>