From b64be2ad6bab9a9fe5be8c7a3e4add3c5b2853c7 Mon Sep 17 00:00:00 2001 From: Nikhil Saraf <1028334+nikhilsaraf@users.noreply.github.com> Date: Wed, 31 Jul 2019 17:15:54 -0700 Subject: [PATCH 1/4] 1 - add link to show market --- gui/web/src/components/molecules/BotCard/BotCard.js | 10 ++++++++++ gui/web/src/components/molecules/Header/Header.js | 2 -- .../components/molecules/PopoverMenu/PopoverMenu.js | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gui/web/src/components/molecules/BotCard/BotCard.js b/gui/web/src/components/molecules/BotCard/BotCard.js index e170e881e..c6f859050 100644 --- a/gui/web/src/components/molecules/BotCard/BotCard.js +++ b/gui/web/src/components/molecules/BotCard/BotCard.js @@ -67,6 +67,7 @@ class BotCard extends Component { this.tick = this.tick.bind(this); this.toggleOptions = this.toggleOptions.bind(this); this.editBot = this.editBot.bind(this); + this.showMarket = this.showMarket.bind(this); this.callDeleteBot = this.callDeleteBot.bind(this); this._asyncRequests = {}; @@ -272,6 +273,13 @@ class BotCard extends Component { this.props.history.push('/edit?bot_name=' + encodeURIComponent(this.props.name)) } + showMarket() { + let baseCode = this.state.botInfo.asset_base.asset_type === "native" ? "XLM/native" : this.state.botInfo.asset_base.asset_code + "/" + this.state.botInfo.asset_base.asset_issuer; + let quoteCode = this.state.botInfo.asset_quote.asset_type === "native" ? "XLM/native" : this.state.botInfo.asset_quote.asset_code + "/" + this.state.botInfo.asset_quote.asset_issuer; + let link = "https://testnet.interstellar.exchange/app/#/trade/guest/" + baseCode + "/" + quoteCode; + window.open(link); + } + render() { let popover = ""; if (this.state.popoverVisible) { @@ -281,6 +289,8 @@ class BotCard extends Component {
+ {this.props.enableMarket ?
Show Market
:
Show Market
} {this.props.enableEdit ?
Edit
:
Edit
} {this.props.enableCopy ?
Copy
:
Copy
} {this.props.enableDelete ?
Delete
:
Delete
} From 63d669513809e818171e85ae29e6ca3040560f1c Mon Sep 17 00:00:00 2001 From: Nikhil Saraf <1028334+nikhilsaraf@users.noreply.github.com> Date: Thu, 1 Aug 2019 10:51:20 -0700 Subject: [PATCH 2/4] 2 - correct market links for pubnet and testnet bots --- gui/backend/get_bot_info.go | 1 + gui/web/src/components/molecules/BotCard/BotCard.js | 4 ++++ query/botInfo.go | 3 +++ 3 files changed, 8 insertions(+) diff --git a/gui/backend/get_bot_info.go b/gui/backend/get_bot_info.go index 87c3fbb95..91331a5c9 100644 --- a/gui/backend/get_bot_info.go +++ b/gui/backend/get_bot_info.go @@ -175,6 +175,7 @@ func (s *APIServer) runGetBotInfoDirect(w http.ResponseWriter, botName string) { bi := query.BotInfo{ LastUpdated: time.Now().Format("1/_2/2006 15:04:05"), Strategy: buysell, + IsTestnet: strings.Contains(botConfig.HorizonURL, "test"), TradingPair: tradingPair, AssetBase: assetBase, AssetQuote: assetQuote, diff --git a/gui/web/src/components/molecules/BotCard/BotCard.js b/gui/web/src/components/molecules/BotCard/BotCard.js index c6f859050..8bd2b3da9 100644 --- a/gui/web/src/components/molecules/BotCard/BotCard.js +++ b/gui/web/src/components/molecules/BotCard/BotCard.js @@ -22,6 +22,7 @@ import getBotInfo from '../../../kelp-ops-api/getBotInfo'; let defaultBotInfo = { "last_updated": "Never", "strategy": "buysell", + "is_testnet": true, "trading_pair": { "Base": "?", "Quote": "?" @@ -277,6 +278,9 @@ class BotCard extends Component { let baseCode = this.state.botInfo.asset_base.asset_type === "native" ? "XLM/native" : this.state.botInfo.asset_base.asset_code + "/" + this.state.botInfo.asset_base.asset_issuer; let quoteCode = this.state.botInfo.asset_quote.asset_type === "native" ? "XLM/native" : this.state.botInfo.asset_quote.asset_code + "/" + this.state.botInfo.asset_quote.asset_issuer; let link = "https://testnet.interstellar.exchange/app/#/trade/guest/" + baseCode + "/" + quoteCode; + if (!this.state.botInfo.is_testnet) { + link = "https://interstellar.exchange/app/#/trade/guest/" + baseCode + "/" + quoteCode; + } window.open(link); } diff --git a/query/botInfo.go b/query/botInfo.go index 79b90cab6..7f3c57f3c 100644 --- a/query/botInfo.go +++ b/query/botInfo.go @@ -2,6 +2,7 @@ package query import ( "fmt" + "strings" "time" hProtocol "github.com/stellar/go/protocols/horizon" @@ -13,6 +14,7 @@ import ( type BotInfo struct { LastUpdated string `json:"last_updated"` Strategy string `json:"strategy"` + IsTestnet bool `json:"is_testnet"` TradingPair *model.TradingPair `json:"trading_pair"` AssetBase hProtocol.Asset `json:"asset_base"` AssetQuote hProtocol.Asset `json:"asset_quote"` @@ -66,6 +68,7 @@ func (s *Server) getBotInfo() (*BotInfo, error) { return &BotInfo{ LastUpdated: time.Now().Format("1/_2/2006 15:04:05"), Strategy: s.strategyName, + IsTestnet: strings.Contains(s.sdex.API.HorizonURL, "test"), TradingPair: s.tradingPair, AssetBase: assetBase, AssetQuote: assetQuote, From ff59a37d578a759bd45902e009cd0992f51d130c Mon Sep 17 00:00:00 2001 From: Nikhil Saraf <1028334+nikhilsaraf@users.noreply.github.com> Date: Thu, 1 Aug 2019 10:57:18 -0700 Subject: [PATCH 3/4] 3 - faster fetch bots with protection for duplicate requests --- gui/web/src/components/screens/Bots/Bots.js | 9 ++++++--- gui/web/src/components/screens/NewBot/NewBot.js | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gui/web/src/components/screens/Bots/Bots.js b/gui/web/src/components/screens/Bots/Bots.js index 37b35a802..5a0322d4f 100644 --- a/gui/web/src/components/screens/Bots/Bots.js +++ b/gui/web/src/components/screens/Bots/Bots.js @@ -41,6 +41,10 @@ class Bots extends Component { } fetchBots() { + if (this._asyncRequests["listBots"]) { + return + } + var _this = this this._asyncRequests["listBots"] = listBots(this.props.baseUrl).then(bots => { if (!_this._asyncRequests["listBots"]) { @@ -51,8 +55,7 @@ class Bots extends Component { delete _this._asyncRequests["listBots"]; if (bots.hasOwnProperty('error')) { console.log("error in listBots: " + bots.error); - // retry - setTimeout(_this.fetchBots, 5000); + _this.fetchBots(); } else { _this.setState(prevState => ({ bots: bots @@ -118,7 +121,7 @@ class Bots extends Component {
); } else { - setTimeout(this.fetchBots, 5000); + setTimeout(this.fetchBots, 500); } return ( diff --git a/gui/web/src/components/screens/NewBot/NewBot.js b/gui/web/src/components/screens/NewBot/NewBot.js index b5b782f5c..0422d642b 100644 --- a/gui/web/src/components/screens/NewBot/NewBot.js +++ b/gui/web/src/components/screens/NewBot/NewBot.js @@ -38,6 +38,10 @@ class NewBot extends Component { } loadOptionsMetadata() { + if (this._asyncRequests["optionsMetadata"]) { + return + } + var _this = this; this._asyncRequests["optionsMetadata"] = fetchOptionsMetadata(this.props.baseUrl).then(optionsMetadata => { if (!_this._asyncRequests["optionsMetadata"]) { @@ -48,8 +52,7 @@ class NewBot extends Component { delete _this._asyncRequests["optionsMetadata"]; if (optionsMetadata.hasOwnProperty('error')) { console.log("error when loading optionsMetadata: " + optionsMetadata.error); - // retry - setTimeout(_this.loadOptionsMetadata, 5000); + setTimeout(_this.loadOptionsMetadata, 1000); } else { _this.setState(prevState => ({ optionsMetadata: optionsMetadata, From 4d45533bfe486f8878bb4d4271b6452ec0d5fa0e Mon Sep 17 00:00:00 2001 From: Nikhil Saraf <1028334+nikhilsaraf@users.noreply.github.com> Date: Thu, 1 Aug 2019 11:02:33 -0700 Subject: [PATCH 4/4] 4 - badge should reflect testnet/pubnet bots --- gui/web/src/components/atoms/Badge/Badge.js | 8 ++------ .../components/atoms/BotExchangeInfo/BotExchangeInfo.js | 2 +- gui/web/src/components/molecules/BotCard/BotCard.js | 5 ++++- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/gui/web/src/components/atoms/Badge/Badge.js b/gui/web/src/components/atoms/Badge/Badge.js index c3e88ec3c..e3ce744ee 100644 --- a/gui/web/src/components/atoms/Badge/Badge.js +++ b/gui/web/src/components/atoms/Badge/Badge.js @@ -1,15 +1,11 @@ import React, { Component } from 'react'; import styles from './Badge.module.scss'; - - - class Badge extends Component { render() { - return ( - - {this.props.test ? 'Test' : 'Main'} + + {this.props.testnet ? 'Testnet' : 'Pubnet'} ); } diff --git a/gui/web/src/components/atoms/BotExchangeInfo/BotExchangeInfo.js b/gui/web/src/components/atoms/BotExchangeInfo/BotExchangeInfo.js index fba75cb7b..f6baadd35 100644 --- a/gui/web/src/components/atoms/BotExchangeInfo/BotExchangeInfo.js +++ b/gui/web/src/components/atoms/BotExchangeInfo/BotExchangeInfo.js @@ -6,7 +6,7 @@ class BotExchangeInfo extends Component { render() { return (
- + SDEX {this.props.strategy} diff --git a/gui/web/src/components/molecules/BotCard/BotCard.js b/gui/web/src/components/molecules/BotCard/BotCard.js index 8bd2b3da9..a3e7d3e77 100644 --- a/gui/web/src/components/molecules/BotCard/BotCard.js +++ b/gui/web/src/components/molecules/BotCard/BotCard.js @@ -338,7 +338,10 @@ class BotCard extends Component {

{this.props.name}

- +