X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=cmd%2Fweb%2Fjs%2Faccount.jsx;h=9a976f4c0729bf104bc82ff3a0bdf80e1358a516;hb=a6820180928670b0642fa6a28ac221ce158230bb;hp=43e7083efdef93d45f14ee0cf4cb0584143b1dd4;hpb=16e43cc77935a979c48e75f1ec8ed792952a4ae8;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FCryptoportfolio%2FFront.git diff --git a/cmd/web/js/account.jsx b/cmd/web/js/account.jsx index 43e7083..9a976f4 100644 --- a/cmd/web/js/account.jsx +++ b/cmd/web/js/account.jsx @@ -1,20 +1,55 @@ 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 = () => { - Api.Call('MARKET_BALANCE', {'name': 'poloniex', 'currency': 'BTC'}, function(err, status, data) { + Api.Call('MARKET_TEST_CREDENTIALS', {'name': 'poloniex'}, function(err, status, data) { if (err) { console.error(err, data); if (err.code === 'invalid_market_credentials') { 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,27 +63,29 @@ class PoloniexConfiguration extends React.Component { } handleCredentialsSubmit = () => { - - /* - *If (!this.state.apiKey || !this.state.apiSecret) { - * return; - *} - */ - + 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); + if (err.code === 'invalid_market_credentials') { + this.setState({'status': 'invalidCredentials'}); + } else if (err.code === 'ip_restricted_api_key') { + this.setState({'status': 'ipRestricted'}); + } 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; @@ -57,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}); @@ -87,32 +122,24 @@ class PoloniexConfiguration extends React.Component { console.error('unknown status', this.state.status); displayText = null; } - if (this.state.apiRequested === false) { - return
; - } + return ( -
-
+ statusMessage={displayText} + editMode={this.state.editMode} + onEditClick={this.onEditClick}/> ); } } class PoloniexCredentialsForm extends React.Component { - constructor(props) { - super(props); - this.state = {'editMode': false}; - } - handleSubmit = (e) => { this.props.onCredentialsSubmit(); - this.setState({'editMode': false}); e.preventDefault(); } @@ -124,15 +151,11 @@ class PoloniexCredentialsForm extends React.Component { this.props.onCredentialsChange(this.props.apiKey, event.target.value); } - onEditClick = () => { - this.setState({'editMode': true}); - } - render = () => { - var submitType = this.state.editMode === true ? 'submit' : 'hidden'; - var buttonDisplay = this.state.editMode === true ? 'none' : 'inline'; - var secretDisplayed = this.state.editMode === true ? this.props.apiSecret : 'XXXXXXX'; - var keyDisplayed = this.state.editMode === true ? this.props.apiKey : 'XXXXXXX'; + var submitType = this.props.editMode === true ? 'submit' : 'hidden'; + var buttonDisplay = this.props.editMode === true ? 'none' : 'inline'; + var secretDisplayed = this.props.editMode === true ? this.props.apiSecret : 'XXXXXXX'; + var keyDisplayed = this.props.editMode === true ? this.props.apiKey : 'XXXXXXX'; var iconName = 'icon-cancel-circled'; switch (this.props.status) { @@ -145,33 +168,38 @@ class PoloniexCredentialsForm extends React.Component { } return ( -
-
- Poloniex credentials -
-
-
- {this.props.statusMessage} -
-
-
-
-
- - - - -
-
-
+ +
+
+ {this.props.statusMessage} +
+
+
+
+
+ + + + + + +
+
); } } -export default PoloniexConfiguration; +class UserAccount extends React.Component { + render = () => { + return ( + + } title="Account" /> + } title="Poloniex credentials" topClassName="api-credentials-form" /> + + ); + } +} + +export default UserAccount;