X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=cmd%2Fweb%2Fjs%2Faccount.jsx;h=9a976f4c0729bf104bc82ff3a0bdf80e1358a516;hb=a6820180928670b0642fa6a28ac221ce158230bb;hp=03ca117b756db7a222ddf21b5d1e76d7ecc0ff13;hpb=299b6b6d9fb879c06e675ef240f361348629ff6c;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/cmd/web/js/account.jsx b/cmd/web/js/account.jsx index 03ca117..9a976f4 100644 --- a/cmd/web/js/account.jsx +++ b/cmd/web/js/account.jsx @@ -1,10 +1,43 @@ import Api from './api.js'; import React from 'react'; +import Panel from './panel.js'; + +class AccountInformation extends React.Component { + constructor(props) { + super(props); + this.state = {'email': null}; + } + + loadAccount = () => { + Api.Call('USER_ACCOUNT', {}, function(err, status, data) { + if (err) { + console.error(err, data); + return; + } + + this.setState({'email': data.email}); + }.bind(this)); + } + + componentDidMount = () => { + this.loadAccount(); + } + + render = () => { + var component =
Loading...
; + if (this.state.email !== null) { + component =Email: {this.state.email}
; + } + + return component; + } + +} class PoloniexConfiguration extends React.Component { constructor(props) { super(props); - this.state = {'apiKey': '', 'apiSecret': '', 'apiRequested': false, 'status': 'loading'}; + this.state = {'apiKey': '', 'apiSecret': '', 'status': 'loading', 'editMode': false}; } checkCredentials = () => { @@ -15,6 +48,8 @@ class PoloniexConfiguration extends React.Component { this.setState({'status': 'invalidCredentials'}); } else if (err.code === 'ip_restricted_api_key') { this.setState({'status': 'ipRestricted'}); + } else if (err.code === 'market_credentials_not_configured') { + this.setState({'status': 'emptyCredentials'}); } return; } @@ -28,7 +63,7 @@ class PoloniexConfiguration extends React.Component { } handleCredentialsSubmit = () => { - this.setState({'status': 'loading'}); + this.setState({'status': 'loading', 'editMode': false}); Api.Call('UPDATE_MARKET', {'key': this.state.apiKey, 'secret': this.state.apiSecret, 'name': 'poloniex'}, function(err, status, data) { if (err) { console.error(err, data); @@ -40,14 +75,17 @@ class PoloniexConfiguration extends React.Component { return; } - this.setState({'status': 'loading'}); this.checkCredentials(); }.bind(this)); } componentDidMount = () => { - Api.Call('MARKET', {'name': 'poloniex'}, function(err, status, data) { - this.setState({'apiRequested': true}); + this.checkCredentials(); + } + + onEditClick = () => { + Api.Call('MARKET', {'name': 'poloniex'}, function(err, status, data) { + this.setState({'editMode': true}); if (err) { console.error(err, data); return; @@ -56,8 +94,6 @@ class PoloniexConfiguration extends React.Component { var newStatus = this.state.status; if (!data.key || !data.secret) { newStatus = 'emptyCredentials'; - } else { - this.checkCredentials(); } this.setState({'apiKey': data.key, 'apiSecret': data.secret, 'status': newStatus}); @@ -86,32 +122,24 @@ class PoloniexConfiguration extends React.Component { console.error('unknown status', this.state.status); displayText = null; } - if (this.state.apiRequested === false) { - return ; - } + return ( -