]> 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 482dbb6c9b437ca2f0bf2af7e93ed2378810ff55..db6b1c43da71f123ec830dc8d6a8f89bffbe8146 100644 (file)
@@ -32,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;
       }
@@ -68,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;
@@ -108,6 +113,10 @@ class PoloniexBalance extends React.Component {
     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;
 
@@ -115,16 +124,18 @@ class PoloniexBalance extends React.Component {
 
       var balance = Object.keys(this.props.balance).map(function(currency) {
         return <div key={currency}>
-                 <CurrencyLogo currency={currency} /> {this.props.balance[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 balances">
+          <div className="col-6 align-self-center h-100 balances">
               {balance}
           </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}</span><CurrencyLogo currency={this.props.balanceCurrency} />
             </div>