X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=cmd%2Fweb%2Fjs%2Fpoloniex.jsx;h=76b68d8913312ff7f3640b4f87c98804c3311284;hb=16e43cc77935a979c48e75f1ec8ed792952a4ae8;hp=db6b1c43da71f123ec830dc8d6a8f89bffbe8146;hpb=bf5deb87cef2b6f1370c808821dfb631d00590f6;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/cmd/web/js/poloniex.jsx b/cmd/web/js/poloniex.jsx index db6b1c4..76b68d8 100644 --- a/cmd/web/js/poloniex.jsx +++ b/cmd/web/js/poloniex.jsx @@ -4,26 +4,7 @@ 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 = {'apiRequested': false, 'flag': 'loading', 'valueCurrency': null, 'balanceValue': null, 'balance': null}; } loadBalance = () => { @@ -31,34 +12,19 @@ class PoloniexController extends React.Component { if (err) { console.error(err, data); if (err.code === 'invalid_market_credentials') { - this.setState({'flag': 'invalidCredentials', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); + this.setState({'flag': 'invalidCredentials', 'apiRequested': true, 'valueCurrency': null, 'balanceValue': null, 'balance': null}); } else if (err.code === 'ip_restricted_api_key') { - this.setState({'flag': 'ipRestricted', 'valueCurrency': null, 'balanceValue': null, 'balance': null}); + this.setState({'flag': 'ipRestricted', 'apiRequested': true, 'valueCurrency': null, 'balanceValue': null, 'balance': null}); } return; } - this.setState({'flag': 'ok', 'valueCurrency': data.valueCurrency, 'balanceValue': data.value, 'balance': data.balance}); + this.setState({'flag': 'ok', 'apiRequested': true, 'valueCurrency': data.valueCurrency, 'balanceValue': data.value, 'balance': data.balance}); }.bind(this)); } 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 = () => { @@ -68,13 +34,9 @@ class PoloniexController extends React.Component { displayText = 'Loading data from poloniex...'; break; 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'; + displayText =