From 16e43cc77935a979c48e75f1ec8ed792952a4ae8 Mon Sep 17 00:00:00 2001 From: jloup Date: Mon, 7 May 2018 17:39:58 +0200 Subject: Account page. --- cmd/web/js/account.jsx | 177 +++++++++++++++++++++++++++++++++++++++++++ cmd/web/js/header_footer.jsx | 14 +++- cmd/web/js/main.jsx | 7 ++ cmd/web/js/poloniex.jsx | 110 ++------------------------- 4 files changed, 203 insertions(+), 105 deletions(-) create mode 100644 cmd/web/js/account.jsx (limited to 'cmd/web/js') diff --git a/cmd/web/js/account.jsx b/cmd/web/js/account.jsx new file mode 100644 index 0000000..43e7083 --- /dev/null +++ b/cmd/web/js/account.jsx @@ -0,0 +1,177 @@ +import Api from './api.js'; +import React from 'react'; + +class PoloniexConfiguration extends React.Component { + constructor(props) { + super(props); + this.state = {'apiKey': '', 'apiSecret': '', 'apiRequested': false, 'status': 'loading'}; + } + + checkCredentials = () => { + Api.Call('MARKET_BALANCE', {'name': 'poloniex', 'currency': 'BTC'}, 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': 'ok'}); + }.bind(this)); + } + + 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({'status': 'loading'}); + this.checkCredentials(); + }.bind(this)); + } + + componentDidMount = () => { + Api.Call('MARKET', {'name': 'poloniex'}, function(err, status, data) { + this.setState({'apiRequested': true}); + if (err) { + console.error(err, data); + return; + } + + 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}); + }.bind(this)); + } + + render = () => { + var displayText = null; + switch (this.state.status) { + case 'loading': + displayText = 'Checking Poloniex credentials...'; + break; + case 'invalidCredentials': + displayText = 'Invalid poloniex credentials'; + break; + case 'ipRestricted': + displayText = 'Your API key is IP restricted.'; + break; + case 'emptyCredentials': + displayText = 'Please provide poloniex credentials'; + break; + case 'ok': + displayText = 'You are all set !'; + break; + default: + console.error('unknown status', this.state.status); + displayText = null; + } + if (this.state.apiRequested === false) { + return
; + } + return ( +
+ +
+ ); + } +} + +class PoloniexCredentialsForm extends React.Component { + constructor(props) { + super(props); + this.state = {'editMode': false}; + } + + handleSubmit = (e) => { + this.props.onCredentialsSubmit(); + this.setState({'editMode': false}); + e.preventDefault(); + } + + handleApiKeyChange = (event) => { + this.props.onCredentialsChange(event.target.value, this.props.apiSecret); + } + + handleApiSecretChange = (event) => { + 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 iconName = 'icon-cancel-circled'; + switch (this.props.status) { + case 'loading': + iconName = 'icon-hourglass-2'; + break; + case 'ok': + iconName = 'icon-ok-circled'; + break; + } + + return ( +
+
+ Poloniex credentials +
+
+
+ {this.props.statusMessage} +
+
+
+
+
+ + + + +
+
+
+
+
+ ); + } +} + +export default PoloniexConfiguration; diff --git a/cmd/web/js/header_footer.jsx b/cmd/web/js/header_footer.jsx index 3cb9937..f11ed06 100644 --- a/cmd/web/js/header_footer.jsx +++ b/cmd/web/js/header_footer.jsx @@ -6,6 +6,12 @@ class Signout extends React.Component { } } +class MyAccount extends React.Component { + render = () => { + return Account; + } +} + class Logo extends React.Component { render() { return ; }); return ; -} else { + } else { dashboard =
{this.props.displayText}
; -} + } return (
@@ -164,55 +121,4 @@ class PoloniexBalance extends React.Component { } } -class PoloniexCredentialsForm extends React.Component { - constructor(props) { - super(props); - this.state = {'hideMsg': true, 'msg': '', 'editMode': false, 'msgOk': false}; - } - - handleSubmit = (e) => { - this.props.onCredentialsSubmit(); - this.setState({'editMode': false}); - e.preventDefault(); - } - - handleApiKeyChange = (event) => { - this.props.onCredentialsChange(event.target.value, this.props.apiSecret); - } - - handleApiSecretChange = (event) => { - 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'; - - return ( -
-
- Poloniex credentials -
-
- - - - -
-
-
- ); - } -} - export default PoloniexController; -- cgit v1.2.3