X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=cmd%2Fweb%2Fjs%2Fpoloniex.jsx;h=edac368e84d07f02d2060d838481d7853cab04a3;hb=78e3e81ddf01f41102f3f4e32c5a3955cf5fb04f;hp=a5fb9a74d49bb3ac45b933c088bb184c18038e75;hpb=adf936f66a5c59e6cc2e7a1c644148e0f119e5c8;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/cmd/web/js/poloniex.jsx b/cmd/web/js/poloniex.jsx index a5fb9a7..edac368 100644 --- a/cmd/web/js/poloniex.jsx +++ b/cmd/web/js/poloniex.jsx @@ -1,30 +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': '', 'apiRequested': false, 'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}; - } - - handleCredentialsChange = (key, secret) => { - this.setState({'apiKey': key, 'apiSecret': secret}); - } - - handleCredentialsSubmit = () => { - if (!this.state.apiKey || !this.state.apiSecret) { - return; - } - Api.Call('UPDATE_MARKET', {'key': this.state.apiKey, 'secret': this.state.apiSecret, 'name': 'poloniex'}, function(err, status, data) { - if (err) { - console.error(err, data); - return; - } - - this.setState({'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); - this.loadBalance(); - }.bind(this)); + this.state = {'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}; } loadBalance = () => { @@ -33,6 +13,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; } @@ -42,22 +24,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; - } - - var flag = this.state.flag; - if (!data.key || !data.secret) { - flag = 'emptyCredentials'; - } else { - this.loadBalance(); - } - - this.setState({'apiKey': data.key, 'apiSecret': data.secret, 'flag': flag}); - }.bind(this)); + this.loadBalance(); } render = () => { @@ -67,73 +34,79 @@ class PoloniexController extends React.Component { displayText = 'Loading data from poloniex...'; break; case 'invalidCredentials': - displayText = 'Invalid poloniex credentials'; - break; + case 'ipRestricted': case 'emptyCredentials': - displayText = 'Please provide poloniex credentials'; + displayText =