X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=cmd%2Fweb%2Fjs%2Fpoloniex.jsx;h=db6b1c43da71f123ec830dc8d6a8f89bffbe8146;hb=50c6eea630c5bf6d1513d093125f11ce30deaff5;hp=96384fd35ac501ee62a918a2620c90d5af9d3564;hpb=989fb5c7dbba174f54f3ae69df788d6685fff46b;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/cmd/web/js/poloniex.jsx b/cmd/web/js/poloniex.jsx index 96384fd..db6b1c4 100644 --- a/cmd/web/js/poloniex.jsx +++ b/cmd/web/js/poloniex.jsx @@ -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) => { @@ -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; } @@ -43,6 +44,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; @@ -68,12 +70,18 @@ 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; default: displayText = null; } + if (this.state.apiRequested === false) { + return
; + } return (
{ + return {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
{this.props.balance[currency]}
; + return
+
+ {this.props.balance[currency].amount} {currency} ({this.computeCurrencyRatio(currency)}%) +
+
; }.bind(this)); dashboard =
-
-
+
{balance} -
-
+
- Balance ({this.props.balanceCurrency}): {this.props.balanceValue} + Balance ({this.props.balanceCurrency}): {this.props.balanceValue}
; @@ -129,7 +152,7 @@ class PoloniexBalance extends React.Component { return (
-
+
Portfolio
@@ -173,7 +196,7 @@ class PoloniexCredentialsForm extends React.Component { return (
-
+
Poloniex credentials