Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Some enhancements for Kelp UI, fix bug causing a crash in bots when r…
Browse files Browse the repository at this point in the history
…un from UI (#195)

addresses part of issue #67

* 1 - list onChange function as an input PropType to the <Input> component

* 2 - allow PubNet segment selector selection

* 3 - disable "Helper Fields" switch for now

* 4 - enable editing bot when it is stopping

* 5 - bot randomly crashes on start, try adding a panic handler in the IPC server thread

* 6 - fix bug that is causing bot to crash on start

* 7 - remove chart dummy image in BotCard

* 8 - disable sorting arrows

* 9 - remove onClick for showDetails of bot
  • Loading branch information
nikhilsaraf authored Jul 9, 2019
1 parent 4759428 commit adfcce6
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 27 deletions.
8 changes: 6 additions & 2 deletions cmd/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ func hiddenFlag(flag string) {
}
}

func logPanic(l logger.Logger) {
func logPanic(l logger.Logger, fatalOnError bool) {
if r := recover(); r != nil {
st := debug.Stack()
l.Errorf("PANIC!! recovered to log it in the file\npanic: %v\n\n%s\n", r, string(st))
if fatalOnError {
logger.Fatal(l, fmt.Errorf("PANIC!! recovered to log it in the file\npanic: %v\n\n%s\n", r, string(st)))
}
}
}

Expand Down Expand Up @@ -628,6 +631,7 @@ func startQueryServer(
)

go func() {
defer logPanic(l, true)
e := qs.StartIPC()
if e != nil {
l.Info("")
Expand Down Expand Up @@ -739,5 +743,5 @@ func setLogFile(l logger.Logger, options inputs, botConfig trader.BotConfig) {

l.Infof("logging to file: %s\n", fileName)
// we want to create a deferred recovery function here that will log panics to the log file and then exit
defer logPanic(l)
defer logPanic(l, false)
}
3 changes: 2 additions & 1 deletion gui/web/src/components/atoms/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Input extends Component {
error: PropTypes.string,
size: PropTypes.string,
disabled: PropTypes.bool,
showError: PropTypes.bool
showError: PropTypes.bool,
onChange: PropTypes.func
};

handleChange(event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { Component } from 'react';
import styles from './SegmentedControl.module.scss';

class SegmentedControl extends Component {

render() {
let segments = [];
for (let i in this.props.segments) {
Expand All @@ -13,7 +12,15 @@ class SegmentedControl extends Component {
className = styles.segmentedControlItemSelected
}

segments.push(<li key={s} className={className}>{s}</li>);
segments.push(
<li
key={s}
className={className}
onClick={() => this.props.onSelect(s) }
>
{s}
</li>
);
}

return (
Expand Down
16 changes: 8 additions & 8 deletions gui/web/src/components/molecules/BotCard/BotCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ class BotCard extends Component {
name: PropTypes.string,
test: PropTypes.bool,
warnings: PropTypes.number,
errors: PropTypes.number,
showDetailsFn: PropTypes.func,
errors: PropTypes.number,
baseUrl: PropTypes.string,
};

Expand Down Expand Up @@ -273,12 +272,13 @@ class BotCard extends Component {
render() {
let popover = "";
if (this.state.popoverVisible) {
let enableEdit = this.state.state === Constants.BotState.stopped || this.state.state === Constants.BotState.stopping;
popover = (
<div>
<div className={styles.optionsSpacer}/>
<PopoverMenu
className={styles.optionsMenu}
enableEdit={this.state.state === Constants.BotState.stopped}
enableEdit={enableEdit}
onEdit={this.editBot}
enableCopy={false}
onCopy={this.toggleOptions}
Expand All @@ -305,7 +305,7 @@ class BotCard extends Component {
{popover}
</div>

<div className={styles.sortingArrows}>
{/* <div className={styles.sortingArrows}>
<Button
icon="chevronUp"
variant="transparent"
Expand All @@ -316,10 +316,10 @@ class BotCard extends Component {
variant="transparent"
hsize="round"
/>
</div>
</div> */}

<div className={styles.firstColumn}>
<h2 className={styles.title} onClick={this.props.showDetailsFn}>{this.props.name}</h2>
<h2 className={styles.title}>{this.props.name}</h2>
<div className={styles.botDetailsLine}>
<BotExchangeInfo strategy={this.state.botInfo.strategy}/>
</div>
Expand Down Expand Up @@ -348,9 +348,9 @@ class BotCard extends Component {
/>
</div>

<div className={styles.thirdColumn}>
{/* <div className={styles.thirdColumn}>
<img className={styles.chartThumb} src={chartThumb} alt="chartThumb"/>
</div>
</div> */}

<div className={styles.fourthColumn}>
<RunStatus
Expand Down
8 changes: 4 additions & 4 deletions gui/web/src/components/molecules/BotCard/BotCard.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ $small-spacing: 3px;
font-weight: 400;
margin: 0;
margin-bottom: 0.3rem;
cursor: pointer;
&:hover {
text-decoration: underline;
}
// cursor: pointer;
// &:hover {
// text-decoration: underline;
// }
}

.botDetailsLine {
Expand Down
14 changes: 11 additions & 3 deletions gui/web/src/components/molecules/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class Form extends Component {
<div>
<div className={grid.container}>
<ScreenHeader title={this.props.title} backButtonFn={this.props.router.goBack}>
<Switch/>
<Label>Helper Fields</Label>
{/* <Switch/>
<Label>Helper Fields</Label> */}
</ScreenHeader>

<FormSection>
Expand Down Expand Up @@ -211,6 +211,13 @@ class Form extends Component {
"PubNet",
]}
selected={network}
onSelect={(selected) => {
let newValue = "https://horizon-testnet.stellar.org";
if (selected === "PubNet") {
newValue = "https://horizon.stellar.org";
}
this.props.onChange("trader_config.horizon_url", {target: {value: newValue}});
}}
/>
</FieldItem>
</FormSection>
Expand All @@ -228,7 +235,8 @@ class Form extends Component {
</FieldItem>
</FormSection>

<FormSection tip="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam purus nunc, rhoncus ac lorem eget, eleifend congue nisl.">
{/* <FormSection tip="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam purus nunc, rhoncus ac lorem eget, eleifend congue nisl."> */}
<FormSection>
<div className={grid.row}>
<div className={grid.col4}>
<FieldItem>
Expand Down
6 changes: 3 additions & 3 deletions gui/web/src/components/screens/Bots/Bots.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class Bots extends Component {
this.props.history.push('/new')
}

gotoDetails() {
this.props.history.push('/details')
gotoDetails(botName) {
this.props.history.push('/details?bot_name=' + encodeURIComponent(botName))
}

fetchBots() {
Expand Down Expand Up @@ -137,7 +137,7 @@ class Bots extends Component {
test={bot.test}
warnings={bot.warnings}
errors={bot.errors}
showDetailsFn={this.gotoDetails}
// showDetailsFn={this.gotoDetails}
baseUrl={this.props.baseUrl}
reload={this.fetchBots}
/>
Expand Down
13 changes: 10 additions & 3 deletions query/botInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ func (s *Server) getBotInfo() (*botInfo, error) {
if e != nil {
return nil, fmt.Errorf("error loading orderbook (maxCount=20): %s", e)
}
spreadValue := ob.TopAsk().Price.Subtract(*ob.TopBid().Price)
midPrice := ob.TopAsk().Price.Add(*ob.TopBid().Price).Scale(0.5)
spreadPct := spreadValue.Divide(*midPrice)
topAsk := ob.TopAsk()
topBid := ob.TopBid()
spreadValue := model.NumberFromFloat(-1.0, 16)
midPrice := model.NumberFromFloat(-1.0, 16)
spreadPct := model.NumberFromFloat(-1.0, 16)
if topBid != nil && topAsk != nil {
spreadValue = topAsk.Price.Subtract(*topBid.Price)
midPrice = topAsk.Price.Add(*topBid.Price).Scale(0.5)
spreadPct = spreadValue.Divide(*midPrice)
}

return &botInfo{
Strategy: s.strategyName,
Expand Down
1 change: 0 additions & 1 deletion trader/trader.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func (t *Trader) update() {
// TODO 2 streamline the request data instead of caching
// reset cache of balances for this update cycle to reduce redundant requests to calculate asset balances
t.sdex.IEIF().ResetCachedBalances()
log.Printf("reset cached balances\n")
// reset and recompute cached liabilities for this update cycle
e = t.sdex.IEIF().ResetCachedLiabilities(t.assetBase, t.assetQuote)
log.Printf("liabilities after resetting\n")
Expand Down

0 comments on commit adfcce6

Please sign in to comment.